pub struct Command { /* private fields */ }Expand description
Commands to send to the audio device.
Command is used to prepare and send commands to the Presonus STUDIO1824c. A Command can be prepared to set the buttons on the front panel, or to set the faders.
§Examples
use baton_studio::{Button, Channel, Command, Value};
use nusb::MaybeFuture;
// Open the 1824c usb device.
let my_1824c = nusb::list_devices()
.wait()?
.find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
.ok_or(std::io::Error::new(std::io::ErrorKind::NotFound, "device not found"))?
.open()
.wait()?;
let mut command = Command::new();
// Prepare command to set the Mute button to true.
command.set_button(Button::Mute, true);
// Send the command.
command.send(&my_1824c)?;
// Prepare and send command to set fader.
command
.set_input_fader(0, 0, Channel::Left, Value::Unity)
.send(&my_1824c)?;
Implementations§
Source§impl Command
impl Command
Sourcepub fn new() -> Self
pub fn new() -> Self
Initialize the Command struct.
Examples found in repository?
examples/examples.rs (line 16)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17 let mut state = State::new();
18
19 command.set_button(Button::Mute, true);
20 command.send(&device).unwrap();
21
22 command.set_button(Button::Phantom, true).send(&device)?;
23
24 command
25 .set_input_fader(0, 0, Channel::Left, Value::DB(-3.0))
26 .send(&device)?;
27
28 command
29 .set_input_fader(0, 0, Channel::Left, Value::Unity)
30 .send(&device)?;
31
32 command.set_output_fader(0, Value::DB(-2.4)).send(&device)?;
33
34 command
35 .set_output_fader(1, Value::Muted)
36 .send(&device)
37 .unwrap();
38
39 state.poll(&device)?;
40
41 let mic = gain_to_db(state.mic[7]);
42 println!("mic: {} dBFS", mic);
43
44 Ok(())
45}More examples
examples/bypass.rs (line 16)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17
18 // Set all stereo bus faders to unity gain
19 for m in 0..9 {
20 command.set_output_fader(m, Value::Unity).send(&device)?;
21 }
22
23 // Set:
24 // Daw 1 -> Line out 1, Daw 2 -> Line out 2
25 // Daw 3 -> Line out 3, Daw 4 -> Line out 4
26 // Daw 5 -> Line out 5, Daw 6 -> Line out 6
27 // Daw 7 -> Line out 7, Daw 8 -> Line out 8
28 // Daw 9 -> SPDIF out 1, Daw 10 -> SPDIF out 2
29 // Daw 11 -> ADAT out 1, Daw 12 -> ADAT out 2
30 // Daw 13 -> ADAT out 3, Daw 14 -> ADAT out 4
31 // Daw 15 -> ADAT out 5, Daw 16 -> ADAT out 6
32 // Daw 17 -> ADAT out 7, Daw 18 -> ADAT out 8
33 // Everything else muted
34
35 let mut daw_channel_left = 16;
36 let mut daw_channel_right;
37
38 for m in 0..9 {
39 daw_channel_left += 2;
40 daw_channel_right = daw_channel_left + 1;
41 for c in 0..35 {
42 if c == daw_channel_left {
43 command
44 .set_input_fader(c, m, Channel::Left, Value::Unity)
45 .send(&device)?;
46 command
47 .set_input_fader(c, m, Channel::Right, Value::Muted)
48 .send(&device)?;
49 } else if c == daw_channel_right {
50 command
51 .set_input_fader(c, m, Channel::Left, Value::Muted)
52 .send(&device)?;
53 command
54 .set_input_fader(c, m, Channel::Right, Value::Unity)
55 .send(&device)?;
56 } else {
57 command
58 .set_input_fader(c, m, Channel::Left, Value::Muted)
59 .send(&device)?;
60 command
61 .set_input_fader(c, m, Channel::Right, Value::Muted)
62 .send(&device)?;
63 }
64 }
65 }
66
67 Ok(())
68}Prepare a Button command.
Used to turn on or off one of the four buttons on the front panel of the 1824c.
§Examples
// Prepare and send command to turn off phantom power.
command.set_button(Button::Phantom, false).send(&my_1824c)?;Examples found in repository?
examples/examples.rs (line 19)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17 let mut state = State::new();
18
19 command.set_button(Button::Mute, true);
20 command.send(&device).unwrap();
21
22 command.set_button(Button::Phantom, true).send(&device)?;
23
24 command
25 .set_input_fader(0, 0, Channel::Left, Value::DB(-3.0))
26 .send(&device)?;
27
28 command
29 .set_input_fader(0, 0, Channel::Left, Value::Unity)
30 .send(&device)?;
31
32 command.set_output_fader(0, Value::DB(-2.4)).send(&device)?;
33
34 command
35 .set_output_fader(1, Value::Muted)
36 .send(&device)
37 .unwrap();
38
39 state.poll(&device)?;
40
41 let mic = gain_to_db(state.mic[7]);
42 println!("mic: {} dBFS", mic);
43
44 Ok(())
45}Sourcepub fn set_input_fader(
&mut self,
input: u32,
output: u32,
channel: Channel,
value: Value,
) -> &mut Self
pub fn set_input_fader( &mut self, input: u32, output: u32, channel: Channel, value: Value, ) -> &mut Self
Prepare a command to set an input fader.
The input faders are the faders of the 36
§Arguments
inputThe input channel is a number between 0 and 35.outputThe ouput stere bus is a number between 0 and 8.channelThe channel of the output stere bus.LeftorRight.valueThe fader value. SeeValueenum for options.
§Examples
// Prepare and send command to set the fader of the first
// input channel of the left channel of the first stereo
// mix to unity gain.
command.set_input_fader(0, 0, Channel::Left, Value::Unity).send(&my_1824c)?;
// Set value to zero i.e. muted.
command.set_input_fader(0, 0, Channel::Left, Value::Muted).send(&my_1824c)?;
// Use the helper function db_to_gain()
command.set_input_fader(0, 0, Channel::Left, Value::DB(-6.0)).send(&my_1824c)?;Examples found in repository?
examples/examples.rs (line 25)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17 let mut state = State::new();
18
19 command.set_button(Button::Mute, true);
20 command.send(&device).unwrap();
21
22 command.set_button(Button::Phantom, true).send(&device)?;
23
24 command
25 .set_input_fader(0, 0, Channel::Left, Value::DB(-3.0))
26 .send(&device)?;
27
28 command
29 .set_input_fader(0, 0, Channel::Left, Value::Unity)
30 .send(&device)?;
31
32 command.set_output_fader(0, Value::DB(-2.4)).send(&device)?;
33
34 command
35 .set_output_fader(1, Value::Muted)
36 .send(&device)
37 .unwrap();
38
39 state.poll(&device)?;
40
41 let mic = gain_to_db(state.mic[7]);
42 println!("mic: {} dBFS", mic);
43
44 Ok(())
45}More examples
examples/bypass.rs (line 44)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17
18 // Set all stereo bus faders to unity gain
19 for m in 0..9 {
20 command.set_output_fader(m, Value::Unity).send(&device)?;
21 }
22
23 // Set:
24 // Daw 1 -> Line out 1, Daw 2 -> Line out 2
25 // Daw 3 -> Line out 3, Daw 4 -> Line out 4
26 // Daw 5 -> Line out 5, Daw 6 -> Line out 6
27 // Daw 7 -> Line out 7, Daw 8 -> Line out 8
28 // Daw 9 -> SPDIF out 1, Daw 10 -> SPDIF out 2
29 // Daw 11 -> ADAT out 1, Daw 12 -> ADAT out 2
30 // Daw 13 -> ADAT out 3, Daw 14 -> ADAT out 4
31 // Daw 15 -> ADAT out 5, Daw 16 -> ADAT out 6
32 // Daw 17 -> ADAT out 7, Daw 18 -> ADAT out 8
33 // Everything else muted
34
35 let mut daw_channel_left = 16;
36 let mut daw_channel_right;
37
38 for m in 0..9 {
39 daw_channel_left += 2;
40 daw_channel_right = daw_channel_left + 1;
41 for c in 0..35 {
42 if c == daw_channel_left {
43 command
44 .set_input_fader(c, m, Channel::Left, Value::Unity)
45 .send(&device)?;
46 command
47 .set_input_fader(c, m, Channel::Right, Value::Muted)
48 .send(&device)?;
49 } else if c == daw_channel_right {
50 command
51 .set_input_fader(c, m, Channel::Left, Value::Muted)
52 .send(&device)?;
53 command
54 .set_input_fader(c, m, Channel::Right, Value::Unity)
55 .send(&device)?;
56 } else {
57 command
58 .set_input_fader(c, m, Channel::Left, Value::Muted)
59 .send(&device)?;
60 command
61 .set_input_fader(c, m, Channel::Right, Value::Muted)
62 .send(&device)?;
63 }
64 }
65 }
66
67 Ok(())
68}Sourcepub fn set_output_fader(&mut self, output: u32, value: Value) -> &mut Self
pub fn set_output_fader(&mut self, output: u32, value: Value) -> &mut Self
Prepare a command to set an output fader.
Examples found in repository?
examples/examples.rs (line 32)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17 let mut state = State::new();
18
19 command.set_button(Button::Mute, true);
20 command.send(&device).unwrap();
21
22 command.set_button(Button::Phantom, true).send(&device)?;
23
24 command
25 .set_input_fader(0, 0, Channel::Left, Value::DB(-3.0))
26 .send(&device)?;
27
28 command
29 .set_input_fader(0, 0, Channel::Left, Value::Unity)
30 .send(&device)?;
31
32 command.set_output_fader(0, Value::DB(-2.4)).send(&device)?;
33
34 command
35 .set_output_fader(1, Value::Muted)
36 .send(&device)
37 .unwrap();
38
39 state.poll(&device)?;
40
41 let mic = gain_to_db(state.mic[7]);
42 println!("mic: {} dBFS", mic);
43
44 Ok(())
45}More examples
examples/bypass.rs (line 20)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17
18 // Set all stereo bus faders to unity gain
19 for m in 0..9 {
20 command.set_output_fader(m, Value::Unity).send(&device)?;
21 }
22
23 // Set:
24 // Daw 1 -> Line out 1, Daw 2 -> Line out 2
25 // Daw 3 -> Line out 3, Daw 4 -> Line out 4
26 // Daw 5 -> Line out 5, Daw 6 -> Line out 6
27 // Daw 7 -> Line out 7, Daw 8 -> Line out 8
28 // Daw 9 -> SPDIF out 1, Daw 10 -> SPDIF out 2
29 // Daw 11 -> ADAT out 1, Daw 12 -> ADAT out 2
30 // Daw 13 -> ADAT out 3, Daw 14 -> ADAT out 4
31 // Daw 15 -> ADAT out 5, Daw 16 -> ADAT out 6
32 // Daw 17 -> ADAT out 7, Daw 18 -> ADAT out 8
33 // Everything else muted
34
35 let mut daw_channel_left = 16;
36 let mut daw_channel_right;
37
38 for m in 0..9 {
39 daw_channel_left += 2;
40 daw_channel_right = daw_channel_left + 1;
41 for c in 0..35 {
42 if c == daw_channel_left {
43 command
44 .set_input_fader(c, m, Channel::Left, Value::Unity)
45 .send(&device)?;
46 command
47 .set_input_fader(c, m, Channel::Right, Value::Muted)
48 .send(&device)?;
49 } else if c == daw_channel_right {
50 command
51 .set_input_fader(c, m, Channel::Left, Value::Muted)
52 .send(&device)?;
53 command
54 .set_input_fader(c, m, Channel::Right, Value::Unity)
55 .send(&device)?;
56 } else {
57 command
58 .set_input_fader(c, m, Channel::Left, Value::Muted)
59 .send(&device)?;
60 command
61 .set_input_fader(c, m, Channel::Right, Value::Muted)
62 .send(&device)?;
63 }
64 }
65 }
66
67 Ok(())
68}Sourcepub fn send(&self, device: &Device) -> Result<(), TransferError>
pub fn send(&self, device: &Device) -> Result<(), TransferError>
Send the prepared command to the device.
Examples found in repository?
examples/examples.rs (line 20)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17 let mut state = State::new();
18
19 command.set_button(Button::Mute, true);
20 command.send(&device).unwrap();
21
22 command.set_button(Button::Phantom, true).send(&device)?;
23
24 command
25 .set_input_fader(0, 0, Channel::Left, Value::DB(-3.0))
26 .send(&device)?;
27
28 command
29 .set_input_fader(0, 0, Channel::Left, Value::Unity)
30 .send(&device)?;
31
32 command.set_output_fader(0, Value::DB(-2.4)).send(&device)?;
33
34 command
35 .set_output_fader(1, Value::Muted)
36 .send(&device)
37 .unwrap();
38
39 state.poll(&device)?;
40
41 let mic = gain_to_db(state.mic[7]);
42 println!("mic: {} dBFS", mic);
43
44 Ok(())
45}More examples
examples/bypass.rs (line 20)
5fn main() -> Result<(), Box<dyn Error>> {
6 let device = nusb::list_devices()
7 .wait()?
8 .find(|dev| dev.vendor_id() == 0x194f && dev.product_id() == 0x010d)
9 .ok_or(std::io::Error::new(
10 std::io::ErrorKind::NotFound,
11 "device not found",
12 ))?
13 .open()
14 .wait()?;
15
16 let mut command = Command::new();
17
18 // Set all stereo bus faders to unity gain
19 for m in 0..9 {
20 command.set_output_fader(m, Value::Unity).send(&device)?;
21 }
22
23 // Set:
24 // Daw 1 -> Line out 1, Daw 2 -> Line out 2
25 // Daw 3 -> Line out 3, Daw 4 -> Line out 4
26 // Daw 5 -> Line out 5, Daw 6 -> Line out 6
27 // Daw 7 -> Line out 7, Daw 8 -> Line out 8
28 // Daw 9 -> SPDIF out 1, Daw 10 -> SPDIF out 2
29 // Daw 11 -> ADAT out 1, Daw 12 -> ADAT out 2
30 // Daw 13 -> ADAT out 3, Daw 14 -> ADAT out 4
31 // Daw 15 -> ADAT out 5, Daw 16 -> ADAT out 6
32 // Daw 17 -> ADAT out 7, Daw 18 -> ADAT out 8
33 // Everything else muted
34
35 let mut daw_channel_left = 16;
36 let mut daw_channel_right;
37
38 for m in 0..9 {
39 daw_channel_left += 2;
40 daw_channel_right = daw_channel_left + 1;
41 for c in 0..35 {
42 if c == daw_channel_left {
43 command
44 .set_input_fader(c, m, Channel::Left, Value::Unity)
45 .send(&device)?;
46 command
47 .set_input_fader(c, m, Channel::Right, Value::Muted)
48 .send(&device)?;
49 } else if c == daw_channel_right {
50 command
51 .set_input_fader(c, m, Channel::Left, Value::Muted)
52 .send(&device)?;
53 command
54 .set_input_fader(c, m, Channel::Right, Value::Unity)
55 .send(&device)?;
56 } else {
57 command
58 .set_input_fader(c, m, Channel::Left, Value::Muted)
59 .send(&device)?;
60 command
61 .set_input_fader(c, m, Channel::Right, Value::Muted)
62 .send(&device)?;
63 }
64 }
65 }
66
67 Ok(())
68}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Command
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnwindSafe for Command
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more