Giter VIP home page Giter VIP logo

wmidi's Introduction

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.

wmidi's People

Contributors

chmanie avatar davide125 avatar jswrenn avatar musitdev avatar rex4539 avatar sm-fifteen avatar wmedrano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

wmidi's Issues

What does "real-time execution" mean?

I suppose that this crate is usable for embedded targets like STM32, so it is [no_std]. If so, it would be nice to have a hint on that in the README.

MIDI 2.0 implementation

Over the past year, the MMA has been detailling the various components of the MIDI 2.0 specification and working to define things such as an official MIDI 2.0 USB profile. The MIDI 2.0 protocol itself aims to extend the MIDI 1.0 protocol in a back-compatible way (such as by introducing higher resolution note-on and data/control change messages), as well as formalize the use of profiles (which is what GM2 essentially was, but also things like MIDI Show Control and the like), feature negotiation and making controllers into more of a configurable set of features than a list of spec-reccomanded/profile-mandated CC numbers.

It could be interesting to look into adding support for this new extended protocol here.

Note ON with velocity 0 should be parsed as NoteOff

Calling wmidi::MidiMessage::try_from() on a raw Note ON message with velocity 0 currently returns a Note ON message.

According to the MIDI spec, a Note ON message with velocity 0 should be treated as a Note OFF message:
https://www.midi.org/forum/228-writing-midi-software-send-note-off

Do you consider this as a responsibility of the wmidi library, or a responsibility of the application?

I would suggest it is responsibility of the library, with two primary reasons:

  • NoteOn message with velocity 0 is not really a valid logical message from a high-level perspective.
  • Users who are unaware of this requirement may observe compatibility issues with MIDI hardware that only sends NoteOn with vel=0 instead of actual NoteOff message. Change in library would fix this everywhere.

Example sequence, expected result:
[144, 60, 127] => Ok(NoteOn(Ch1, C4(60), U7(127)))
[144, 60, 0] => Ok(NoteOff(Ch1, C4(60), U7(0)))

Example sequence, actual result:
[144, 60, 127] => Ok(NoteOn(Ch1, C4(60), U7(127)))
[144, 60, 0] => Ok(NoteOn(Ch1, C4(60), U7(0)))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.