23 stable releases (4 major)

Uses old Rust 2015

4.0.11 Apr 19, 2026
4.0.10 Dec 20, 2023
4.0.8 Aug 30, 2023
4.0.6 May 14, 2021
0.2.0 Jan 22, 2018

#103 in Audio

Download history 825/week @ 2026-04-15 1315/week @ 2026-04-22 931/week @ 2026-04-29 758/week @ 2026-05-06 727/week @ 2026-05-13 724/week @ 2026-05-20 1343/week @ 2026-05-27 1394/week @ 2026-06-03 1415/week @ 2026-06-10 1402/week @ 2026-06-17 1222/week @ 2026-06-24 1287/week @ 2026-07-01 1135/week @ 2026-07-08 1039/week @ 2026-07-15 1090/week @ 2026-07-22 1595/week @ 2026-07-29

5,046 downloads per month
Used in 30 crates (5 directly)

MIT license

91KB
1.5K SLoC

WMIDI

Midi encoding and decoding library.

crates.io docs.rs

License: MIT Build Status

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, val) = message {
        let volume = u8::from(val) as u8 / 127.0;
        println!("Singing {} at volume {}", note, volume);
    }
    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
}

Features

  • Supports no_std environments.
  • No memory allocations (therefore realtime safe) for parsing and encoding.
  • No memory allocations for creating MidiMessage, except for MidiMessage::OwnedSysEx.

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

Unreleased

  • Use error from core.
  • Added MidiMessage::set_channel() method.

4.0.0

  • New ControlFunction type which simply wraps a U7.
  • Constants and documentation for all ControlFunction values.
  • Renumber Note enums/consts to be more consistent with midi; for example, C0 is now C1.

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