Skip to main content

USysExDecoder

Struct USysExDecoder 

Source
pub struct USysExDecoder<'a>(/* private fields */);
Expand description

Universal SysEx decoder.

Implementations§

Source§

impl USysExDecoder<'_>

Source

pub fn decode(msg: &MidiMessage) -> Option<USysExDecoder<'_>>

Creates a new decoder for the message.

§Error

Returns None if the message isn’t a Universal System Exclusive

Examples found in repository?
examples/arturia-blink.rs (line 103)
60fn main() {
61    let midi_input = midir::MidiInput::new("MIDITest").unwrap();
62
63    let device_port = find_port(&midi_input);
64    if device_port.is_none() {
65        println!("Input device not found!");
66        return;
67    }
68
69    let (sender, receiver) = channel::<MidiMessage>();
70
71    let device_port = device_port.unwrap();
72    let _connect_in = midi_input.connect(
73        &device_port,
74        ARTURIA_DEVICE,
75        move |_timestamp, data, sender| {
76            let msg = MidiMessage::from(data);
77            // println!("{}: received {:?} => {:?}", timestamp, data, msg);
78            print_on_err!(sender.send(msg));
79        },
80        sender,
81    );
82
83    let midi_output = midir::MidiOutput::new("MIDITest").unwrap();
84    let device_port = find_port(&midi_output);
85    if device_port.is_none() {
86        println!("Output device not found!");
87        return;
88    }
89
90    let device_port = device_port.unwrap();
91    if let Ok(mut connect_out) = midi_output.connect(&device_port, ARTURIA_DEVICE) {
92        let msg = MidiMessage::SysEx(SysExEvent::new_non_realtime(
93            consts::usysex::ALL_CALL,
94            [0x06, 0x01],
95            &[0xf7],
96        ));
97        print_on_err!(connect_out.send_message(msg));
98        println!("Press Control-C at anytime to stop the demo");
99
100        let hundred_millis = time::Duration::from_millis(100);
101        loop {
102            if let Ok(msg) = receiver.recv() {
103                if let Some(decoder) = USysExDecoder::decode(&msg) {
104                    if decoder.is_non_realtime()
105                        && decoder.target_device() == 0
106                        && decoder.general_info_reply_manufacturer_id()
107                            == Some(arturia::EXTENDED_ID_VALUE)
108                    {
109                        if decoder.general_info_reply_family() != Some(([2, 0], [4, 2])) {
110                            println!("Your device isn't supported by this demo");
111                            println!("Only the Arturia minilab MkII is supported");
112                        } else {
113                            run_demo(&mut connect_out);
114                        }
115                    }
116                }
117            }
118            thread::sleep(hundred_millis);
119        }
120    }
121}
Source

pub fn is_non_realtime(&self) -> bool

Tell if message is non realtime

Examples found in repository?
examples/arturia-blink.rs (line 104)
60fn main() {
61    let midi_input = midir::MidiInput::new("MIDITest").unwrap();
62
63    let device_port = find_port(&midi_input);
64    if device_port.is_none() {
65        println!("Input device not found!");
66        return;
67    }
68
69    let (sender, receiver) = channel::<MidiMessage>();
70
71    let device_port = device_port.unwrap();
72    let _connect_in = midi_input.connect(
73        &device_port,
74        ARTURIA_DEVICE,
75        move |_timestamp, data, sender| {
76            let msg = MidiMessage::from(data);
77            // println!("{}: received {:?} => {:?}", timestamp, data, msg);
78            print_on_err!(sender.send(msg));
79        },
80        sender,
81    );
82
83    let midi_output = midir::MidiOutput::new("MIDITest").unwrap();
84    let device_port = find_port(&midi_output);
85    if device_port.is_none() {
86        println!("Output device not found!");
87        return;
88    }
89
90    let device_port = device_port.unwrap();
91    if let Ok(mut connect_out) = midi_output.connect(&device_port, ARTURIA_DEVICE) {
92        let msg = MidiMessage::SysEx(SysExEvent::new_non_realtime(
93            consts::usysex::ALL_CALL,
94            [0x06, 0x01],
95            &[0xf7],
96        ));
97        print_on_err!(connect_out.send_message(msg));
98        println!("Press Control-C at anytime to stop the demo");
99
100        let hundred_millis = time::Duration::from_millis(100);
101        loop {
102            if let Ok(msg) = receiver.recv() {
103                if let Some(decoder) = USysExDecoder::decode(&msg) {
104                    if decoder.is_non_realtime()
105                        && decoder.target_device() == 0
106                        && decoder.general_info_reply_manufacturer_id()
107                            == Some(arturia::EXTENDED_ID_VALUE)
108                    {
109                        if decoder.general_info_reply_family() != Some(([2, 0], [4, 2])) {
110                            println!("Your device isn't supported by this demo");
111                            println!("Only the Arturia minilab MkII is supported");
112                        } else {
113                            run_demo(&mut connect_out);
114                        }
115                    }
116                }
117            }
118            thread::sleep(hundred_millis);
119        }
120    }
121}
Source

pub fn target_device(&self) -> u8

Returns the target device

§Panic

If the message isn’t a Universal System Exclusive it will panic. The decode() function is supposed to check for it.

Examples found in repository?
examples/arturia-blink.rs (line 105)
60fn main() {
61    let midi_input = midir::MidiInput::new("MIDITest").unwrap();
62
63    let device_port = find_port(&midi_input);
64    if device_port.is_none() {
65        println!("Input device not found!");
66        return;
67    }
68
69    let (sender, receiver) = channel::<MidiMessage>();
70
71    let device_port = device_port.unwrap();
72    let _connect_in = midi_input.connect(
73        &device_port,
74        ARTURIA_DEVICE,
75        move |_timestamp, data, sender| {
76            let msg = MidiMessage::from(data);
77            // println!("{}: received {:?} => {:?}", timestamp, data, msg);
78            print_on_err!(sender.send(msg));
79        },
80        sender,
81    );
82
83    let midi_output = midir::MidiOutput::new("MIDITest").unwrap();
84    let device_port = find_port(&midi_output);
85    if device_port.is_none() {
86        println!("Output device not found!");
87        return;
88    }
89
90    let device_port = device_port.unwrap();
91    if let Ok(mut connect_out) = midi_output.connect(&device_port, ARTURIA_DEVICE) {
92        let msg = MidiMessage::SysEx(SysExEvent::new_non_realtime(
93            consts::usysex::ALL_CALL,
94            [0x06, 0x01],
95            &[0xf7],
96        ));
97        print_on_err!(connect_out.send_message(msg));
98        println!("Press Control-C at anytime to stop the demo");
99
100        let hundred_millis = time::Duration::from_millis(100);
101        loop {
102            if let Ok(msg) = receiver.recv() {
103                if let Some(decoder) = USysExDecoder::decode(&msg) {
104                    if decoder.is_non_realtime()
105                        && decoder.target_device() == 0
106                        && decoder.general_info_reply_manufacturer_id()
107                            == Some(arturia::EXTENDED_ID_VALUE)
108                    {
109                        if decoder.general_info_reply_family() != Some(([2, 0], [4, 2])) {
110                            println!("Your device isn't supported by this demo");
111                            println!("Only the Arturia minilab MkII is supported");
112                        } else {
113                            run_demo(&mut connect_out);
114                        }
115                    }
116                }
117            }
118            thread::sleep(hundred_millis);
119        }
120    }
121}
Source

pub fn subid(&self) -> [u8; 2]

Returns the subid for the Universel System Exclusive message.

§Panic

If the message isn’t a Universal System Exclusive it will panic. The decode() function is supposed to check for it.

Source

pub fn general_info_reply_manufacturer_id(&self) -> Option<ManufacturerId>

Return the manufacturer ID from the General Info reply Check that the SysEx message is the right one.

§Error

Returns None if the message isn’t the right one.

Examples found in repository?
examples/arturia-blink.rs (line 106)
60fn main() {
61    let midi_input = midir::MidiInput::new("MIDITest").unwrap();
62
63    let device_port = find_port(&midi_input);
64    if device_port.is_none() {
65        println!("Input device not found!");
66        return;
67    }
68
69    let (sender, receiver) = channel::<MidiMessage>();
70
71    let device_port = device_port.unwrap();
72    let _connect_in = midi_input.connect(
73        &device_port,
74        ARTURIA_DEVICE,
75        move |_timestamp, data, sender| {
76            let msg = MidiMessage::from(data);
77            // println!("{}: received {:?} => {:?}", timestamp, data, msg);
78            print_on_err!(sender.send(msg));
79        },
80        sender,
81    );
82
83    let midi_output = midir::MidiOutput::new("MIDITest").unwrap();
84    let device_port = find_port(&midi_output);
85    if device_port.is_none() {
86        println!("Output device not found!");
87        return;
88    }
89
90    let device_port = device_port.unwrap();
91    if let Ok(mut connect_out) = midi_output.connect(&device_port, ARTURIA_DEVICE) {
92        let msg = MidiMessage::SysEx(SysExEvent::new_non_realtime(
93            consts::usysex::ALL_CALL,
94            [0x06, 0x01],
95            &[0xf7],
96        ));
97        print_on_err!(connect_out.send_message(msg));
98        println!("Press Control-C at anytime to stop the demo");
99
100        let hundred_millis = time::Duration::from_millis(100);
101        loop {
102            if let Ok(msg) = receiver.recv() {
103                if let Some(decoder) = USysExDecoder::decode(&msg) {
104                    if decoder.is_non_realtime()
105                        && decoder.target_device() == 0
106                        && decoder.general_info_reply_manufacturer_id()
107                            == Some(arturia::EXTENDED_ID_VALUE)
108                    {
109                        if decoder.general_info_reply_family() != Some(([2, 0], [4, 2])) {
110                            println!("Your device isn't supported by this demo");
111                            println!("Only the Arturia minilab MkII is supported");
112                        } else {
113                            run_demo(&mut connect_out);
114                        }
115                    }
116                }
117            }
118            thread::sleep(hundred_millis);
119        }
120    }
121}
Source

pub fn general_info_reply_family(&self) -> Option<([u8; 2], [u8; 2])>

Return the device family from the General Info reply Check that the SysEx message is the right one.

§Error

Returns None if the message isn’t the right one.

Examples found in repository?
examples/arturia-blink.rs (line 109)
60fn main() {
61    let midi_input = midir::MidiInput::new("MIDITest").unwrap();
62
63    let device_port = find_port(&midi_input);
64    if device_port.is_none() {
65        println!("Input device not found!");
66        return;
67    }
68
69    let (sender, receiver) = channel::<MidiMessage>();
70
71    let device_port = device_port.unwrap();
72    let _connect_in = midi_input.connect(
73        &device_port,
74        ARTURIA_DEVICE,
75        move |_timestamp, data, sender| {
76            let msg = MidiMessage::from(data);
77            // println!("{}: received {:?} => {:?}", timestamp, data, msg);
78            print_on_err!(sender.send(msg));
79        },
80        sender,
81    );
82
83    let midi_output = midir::MidiOutput::new("MIDITest").unwrap();
84    let device_port = find_port(&midi_output);
85    if device_port.is_none() {
86        println!("Output device not found!");
87        return;
88    }
89
90    let device_port = device_port.unwrap();
91    if let Ok(mut connect_out) = midi_output.connect(&device_port, ARTURIA_DEVICE) {
92        let msg = MidiMessage::SysEx(SysExEvent::new_non_realtime(
93            consts::usysex::ALL_CALL,
94            [0x06, 0x01],
95            &[0xf7],
96        ));
97        print_on_err!(connect_out.send_message(msg));
98        println!("Press Control-C at anytime to stop the demo");
99
100        let hundred_millis = time::Duration::from_millis(100);
101        loop {
102            if let Ok(msg) = receiver.recv() {
103                if let Some(decoder) = USysExDecoder::decode(&msg) {
104                    if decoder.is_non_realtime()
105                        && decoder.target_device() == 0
106                        && decoder.general_info_reply_manufacturer_id()
107                            == Some(arturia::EXTENDED_ID_VALUE)
108                    {
109                        if decoder.general_info_reply_family() != Some(([2, 0], [4, 2])) {
110                            println!("Your device isn't supported by this demo");
111                            println!("Only the Arturia minilab MkII is supported");
112                        } else {
113                            run_demo(&mut connect_out);
114                        }
115                    }
116                }
117            }
118            thread::sleep(hundred_millis);
119        }
120    }
121}

Auto Trait Implementations§

§

impl<'a> Freeze for USysExDecoder<'a>

§

impl<'a> RefUnwindSafe for USysExDecoder<'a>

§

impl<'a> Send for USysExDecoder<'a>

§

impl<'a> Sync for USysExDecoder<'a>

§

impl<'a> Unpin for USysExDecoder<'a>

§

impl<'a> UnsafeUnpin for USysExDecoder<'a>

§

impl<'a> UnwindSafe for USysExDecoder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.