midi-stream-parser

Crates.iomidi-stream-parser
lib.rsmidi-stream-parser
version0.1.0
sourcesrc
created_at2022-12-18 12:30:06.550338
updated_at2022-12-18 12:30:06.550338
descriptionParser to convert bytes from a MIDI stream into messages.
homepage
repositoryhttps://github.com/sourcebox/midi-stream-parser-rs
max_upload_size
id740370
size11,238
Oliver Rockstedt (sourcebox)

documentation

README

midi-stream-parser

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.

Usage Example

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);
    }
}

Tests

Run cargo test for the unit tests.

License

Published under the MIT license. Any contribution to this project must be provided under the same license conditions.

Author: Oliver Rockstedt info@sourcebox.de

Commit count: 8

cargo fmt