Crates.io | midi-stream-parser |
lib.rs | midi-stream-parser |
version | 0.1.0 |
source | src |
created_at | 2022-12-18 12:30:06.550338 |
updated_at | 2022-12-18 12:30:06.550338 |
description | Parser to convert bytes from a MIDI stream into messages. |
homepage | |
repository | https://github.com/sourcebox/midi-stream-parser-rs |
max_upload_size | |
id | 740370 |
size | 11,238 |
This no_std
Rust crate contains a parser that takes a stream of bytes from a MIDI source (typically a serial input on an embedded device) and converts them into well-formed messages for further processing.
Currently, only MIDI 1.0 messages are supported.
Feed the stream into the parser byte-per-byte and process the result. This is required because System Realtime messages can be present in-between other messages and must be processed with priority.
// Maximum length of internal SysEx buffer in bytes
const SYSEX_MAX_LEN: usize = 256;
// Get an instance of the parser
let mut parser = midi_stream_parser::MidiStreamParser::<SYSEX_MAX_LEN>::new();
// Read the bytes from the stream, just some demo data here.
let bytes = [0x90, 60, 127, 61, 40];
// Feed each byte into the parser. For simplicity, errors are discarded here by using `ok()`.
// Whenever a message is ready, it will be returned, otherwise `None`.
for byte in bytes {
if let Ok(Some(message)) = parser.parse(byte) {
println!("Message: {:?}", message);
}
}
Run cargo test
for the unit tests.
Published under the MIT license. Any contribution to this project must be provided under the same license conditions.
Author: Oliver Rockstedt info@sourcebox.de