Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

83 Commits

Repository files navigation

WMIDI

Midi encoding and decoding library.

crates.iodocs.rs

License: MITBuild Status

Usage

use std::convert::TryFrom;// Decoding messages from bytes.fnhandle_midi_message(bytes:&[u8]) -> Result<(), wmidi::FromBytesError>{let message = wmidi::MidiMessage::try_from(bytes)?;iflet wmidi::MidiMessage::NoteOn(_, note, val) = message {let volume = u8::from(val)asu8 / 127.0;println!("Singing {} at volume {}", note, volume);}Ok(())}// Encoding messages to bytes.fnmidi_to_bytes(message: wmidi::MidiMessage<'_>) -> Vec<u8>{letmut 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

4.0.11

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

About

Rust midi encoding and decoding library.

Topics

Resources

Stars

100 stars

Watchers

6 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages