11 releases (breaking)

0.8.0 Nov 18, 2023
0.7.0 Mar 26, 2022
0.6.0 Jan 16, 2022
0.5.0 Jun 5, 2020
0.0.1 Dec 28, 2016

#13 in macOS and iOS APIs

Download history 828/week @ 2023-12-23 504/week @ 2023-12-30 780/week @ 2024-01-06 1595/week @ 2024-01-13 841/week @ 2024-01-20 922/week @ 2024-01-27 682/week @ 2024-02-03 1289/week @ 2024-02-10 1437/week @ 2024-02-17 1249/week @ 2024-02-24 1038/week @ 2024-03-02 889/week @ 2024-03-09 801/week @ 2024-03-16 1414/week @ 2024-03-23 1284/week @ 2024-03-30 678/week @ 2024-04-06

4,212 downloads per month
Used in 49 crates (3 directly)

MIT license

125KB
2.5K SLoC

coremidi

This is a CoreMIDI library for Rust built on top of the low-level bindings coremidi-sys. CoreMIDI is a macOS framework that provides APIs for communicating with MIDI (Musical Instrument Digital Interface) devices, including hardware keyboards and synthesizers.

This library preserves the fundamental concepts behind the CoreMIDI framework, while being Rust idiomatic. This means that if you already know CoreMIDI, you will find very easy to start using it.

The documentation for the master branch can be found here: https://chris-zen.github.io/coremidi/coremidi/

Please see the examples for an idea on how to use it, but if you are eager to see some code, this is how you would send some note:

use coremidi::{Client, Destination, EventBuffer, Protocol};
use std::time::Duration;
use std::thread;

fn main() {
  let client = Client::new("example-client").unwrap();
  let output_port = client.output_port("example-port").unwrap();
  let destination = Destination::from_index(0).unwrap();
  let chord_on = EventBuffer::new(Protocol::Midi10)
    .with_packet(0, &[0x2090407f])
    .with_packet(0, &[0x2090447f]);
  let chord_off = EventBuffer::new(Protocol::Midi10)
    .with_packet(0, &[0x2080407f])
    .with_packet(0, &[0x2080447f]);
  output_port.send(&destination, &chord_on).unwrap();
  thread::sleep(Duration::from_millis(1000));
  output_port.send(&destination, &chord_off).unwrap();
}

If you are looking for a portable MIDI library then you can look into:

For handling low level MIDI data you may look into:

Build Status Crates.io Crates.io Crates.io GitHub tag Minimum rustc version

Installation

The library is published into crates.io, so it can be used by adding the following lines into your Cargo.toml file (but remember to update the version number accordingly):

[dependencies]
coremidi = "^0.8.0"

If you prefer to live in the edge ;-) you can use the master branch by including this instead:

[dependencies]
coremidi = { git = "https://github.com/chris-zen/coremidi", branch="master" }

To play with the source code yourself you can clone the repo and build the code and documentation with the following commands:

git clone https://github.com/chris-zen/coremidi.git
cd coremidi
cargo build
cargo test
cargo doc --open

Examples

The examples can be run with:

cargo run --example send

These are the provided examples:

  • endpoints: how to enumerate sources and destinations.
  • send: how to create an output port and send MIDI messages.
  • receive: how to create an input port and receive MIDI messages.
  • virtual-source: how to create a virtual source and generate MIDI messages.
  • virtual-destination: how to create a virtual destination and receive MIDI messages.
  • properties: how to set and get properties on MIDI objects.
  • notifications: how to receive MIDI client notifications.

Dependencies

~380KB