17 releases (stable)

Uses old Rust 2015

4.0.0 Sep 13, 2020
3.1.0 Oct 18, 2019
3.0.1 Sep 29, 2019
2.0.4 Aug 31, 2019
0.2.0 Jan 22, 2018

#44 in Audio

Download history 66/week @ 2020-05-31 27/week @ 2020-06-07 61/week @ 2020-06-14 71/week @ 2020-06-21 45/week @ 2020-06-28 69/week @ 2020-07-05 98/week @ 2020-07-12 106/week @ 2020-07-19 97/week @ 2020-07-26 77/week @ 2020-08-02 77/week @ 2020-08-09 42/week @ 2020-08-16 29/week @ 2020-08-23 61/week @ 2020-08-30 74/week @ 2020-09-06 93/week @ 2020-09-13

303 downloads per month
Used in 2 crates (via lv2-midi)

MIT license

76KB
1.5K SLoC

WMIDI

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

crates.io docs.rs

License: MIT travis-ci

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
}

Testing & Benchmarking

  • Build with cargo build.
  • Test with cargo test.
  • Benchmark with cargo bench. The results will be under ./target/criterion/report/index.html.

Changelog

4.0.0

  • New ControlFunction type which pubicly wraps U7.
  • Constants and documentation for all ControlFunction values.
  • Renumber Note enums/consts to be more consistent with midi; for example, C0 is now C1.
  • Merged SysEx and OwnedSysEx variants into a single Cow[u8] type.

3.1.0

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

3.0.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