pub struct Decoder<const N: usize = MAX_SYSEX_LEN> { /* private fields */ }Expand description
Reassembles MIDI messages from bytes arriving in any chunking.
The decoder handles the three things that make a MIDI stream awkward:
- Running status. A status byte stays in force until another one arrives, so a stream of note-ons may carry one status byte and nothing but data afterwards. System common messages clear it; real-time messages do not.
- Real-time interleaving.
F8throughFFmay appear between any two bytes, including between theF0andF7of aSysExframe. They are reported where they arrive and disturb nothing. - Chunking. A USB packet or a serial read boundary can fall anywhere. Feeding one byte at a time and feeding a whole dump at once produce the same events.
N is the SysEx buffer size and defaults to MAX_SYSEX_LEN. A frame
longer than the buffer is dropped, with Error::SysExTooLong reported once.
use deepmind_midi::wire::{Decoder, Event};
// A firmware-sized buffer is wasted on a host that only sends NRPN edits.
let mut decoder: Decoder<64> = Decoder::new();
let mut frames = 0;
decoder.feed(&[0xF0, 0x00, 0x20, 0x32, 0x20, 0x00, 0x03, 0xF7], |event| {
if matches!(event, Ok(Event::SysEx(_))) {
frames += 1;
}
});
assert_eq!(frames, 1);Implementations§
Source§impl<const N: usize> Decoder<N>
impl<const N: usize> Decoder<N>
Trait Implementations§
Auto Trait Implementations§
impl<const N: usize> Forget for Decoder<N>
impl<const N: usize> Freeze for Decoder<N>
impl<const N: usize> Move for Decoder<N>
impl<const N: usize> RefUnwindSafe for Decoder<N>
impl<const N: usize> Send for Decoder<N>
impl<const N: usize> Sync for Decoder<N>
impl<const N: usize> Unpin for Decoder<N>
impl<const N: usize> UnsafeUnpin for Decoder<N>
impl<const N: usize> UnwindSafe for Decoder<N>
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