5 releases
0.2.0 | May 17, 2023 |
---|---|
0.1.3 | Apr 9, 2023 |
0.1.2 | Feb 26, 2023 |
0.1.1 | Oct 16, 2022 |
0.1.0 | Jun 9, 2022 |
#306 in Audio
Used in 3 crates
(2 directly)
48KB
1K
SLoC
midi-convert
Utilities for converting to/from midi_types::MidiMessage
Links
lib.rs
:
midi_convert
Utilities for converting to/from midi_types::MidiMessage
Examples
Render a MidiMessage
into a byte slice.
use midi_convert::render_slice::MidiRenderSlice;
use midi_types::MidiMessage;
let mut s = [0u8; 3];
let m = MidiMessage::NoteOn(2.into(), 0x76.into(), 0x34.into());
assert_eq!(m.render_slice(&mut s), 3);
assert_eq!(s, [0x92, 0x76, 0x34]);
Try to extract a MidiMessage
from a byte slice.
use midi_convert::parse::{MidiTryParseSlice, MidiParseError};
use midi_types::MidiMessage;
assert_eq!(MidiMessage::try_parse_slice(&[0x92, 0x76, 0x34]), Ok(MidiMessage::NoteOn(2.into(), 0x76.into(), 0x34.into())));
assert_eq!(MidiMessage::try_parse_slice(&[0x92]), Err(MidiParseError::BufferTooShort));
Parse a byte stream, returning MidiMessage
found along the way.
use midi_convert::parse::{MidiParser};
use midi_types::MidiMessage;
let mut parser = MidiParser::new();
assert_eq!(parser.parse(0x92), None);
assert_eq!(parser.parse(0x76), None);
assert_eq!(parser.parse(0x34), Some(MidiMessage::NoteOn(2.into(), 0x76.into(), 0x34.into())));
Dependencies
~190KB