MCPcopy Index your code
hub / github.com/RustAudio/wmidi

github.com/RustAudio/wmidi @v4.0.10

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.0.10 ↗ · + Follow
78 symbols 126 edges 7 files 11 documented · 14% updated 2mo agov4.0.10 · 2024-09-10★ 1003 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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

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.

Core symbols most depended-on inside this repo

index
called by 8
src/midi_message.rs
copy_to_slice
called by 7
src/midi_message.rs
bytes_size
called by 6
src/midi_message.rs
to_freq_f32
called by 4
src/note.rs
to_freq_f64
called by 3
src/note.rs
combine_data
called by 2
src/midi_message.rs
split_data
called by 2
src/midi_message.rs
valid_data_byte
called by 2
src/midi_message.rs

Shape

Method 36
Function 34
Enum 5
Class 3

Languages

Rust100%

Modules by API surface

src/midi_message.rs27 symbols
src/byte.rs26 symbols
src/note.rs13 symbols
benches/bench.rs4 symbols
src/error.rs3 symbols
src/cc.rs3 symbols
src/lib.rs2 symbols

For agents

$ claude mcp add wmidi \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact