Crates.io | wmidi |
lib.rs | wmidi |
version | 4.0.10 |
source | src |
created_at | 2018-01-15 06:12:14.208152 |
updated_at | 2023-12-20 01:48:29.181926 |
description | Midi parsing library. |
homepage | |
repository | https://github.com/RustAudio/wmidi |
max_upload_size | |
id | 46870 |
size | 89,520 |
Midi encoding and decoding library.
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
}
no_std
environments.MidiMessage
, except for MidiMessage::OwnedSysEx
.cargo build
.cargo test
.cargo bench
. The results will be under ./target/criterion/report/index.html
.MidiMessage::wire_size()
to MidiMessage::bytes_size()
.MidiMessage::copy_to_slice()
method.Note::try_from
and u8::from
.