#midi #heap #bytes #decoding #usage #real-time #execution #allocations

wmidi

Midi parsing library with no heap allocations required

16 releases (stable)

3.1.0 Oct 18, 2019
2.0.4 Aug 31, 2019
1.2.1 Aug 30, 2019
1.2.0 Jul 28, 2019
0.2.0 Jan 22, 2018
Download history 60/week @ 2019-10-30 92/week @ 2019-11-06 30/week @ 2019-11-13 33/week @ 2019-11-20 28/week @ 2019-11-27 49/week @ 2019-12-04 212/week @ 2019-12-11 58/week @ 2019-12-18 94/week @ 2019-12-25 22/week @ 2020-01-01 17/week @ 2020-01-08 18/week @ 2020-01-15 3/week @ 2020-01-22 1/week @ 2020-01-29 49/week @ 2020-02-05

299 downloads per month

MIT license

49KB
1K SLoC

WMIDI

Midi encoding and decoding library suitable for real-time execution.

License: MIT crates.io docs.rs

Usage

use std::convert::TryFrom;

// Decoding messages from bytes.
fn handle_midi_message(bytes: &[u8]) -> Result<(), wmidi::FromBytesError> {
    let message = wmidi::MidiMessage::try_from(bytes)?;
    if let wmidi::MidiMessage::NoteOn(_, note, _) = message {
        println!("Singing {}", note);
    }
    Ok(())
}

// Encoding messages to bytes.
fn midi_to_bytes(message: wmidi::MidiMessage<'_>) -> Vec<u8> {
    let mut bytes = vec![0u8; message.bytes_size()];
    message.copy_to_slice(bytes.as_mut_slice()).unwrap();
    bytes
}

Changelog

3.1

  • Rename MidiMessage::wire_size() to MidiMessage::bytes_size().
  • Introduce MidiMessage::copy_to_slice() method.

3.0

  • Instances of U7 and U14 now have bounds checking.
  • Note is now an enum instead of a u8. Can be converted with Note::try_from and u8::from.

No runtime deps