This is as close to usptream as currently possibly. Only a few changes were done to the dependencies: the wasm target was removed and the coremidi dependency was updated to pick up a more recent version so that we don't need to vendor separate versions of the core-foundation and core-foundation-sys crates. This vendors the following crates: * alsa-sys * alsa * coremidi * coremidi-sys * memalloc * midir Overall this adds ~30K lines of code, over half of which is in the alsa bindings alone. Differential Revision: https://phabricator.services.mozilla.com/D124640
		
			
				
	
	
	
	
		
			4.7 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	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 it looks like, but if you are eager to see some code, this is how you would send some note:
extern crate coremidi;
use coremidi::{Client, Destinations, PacketBuffer};
use std::time::Duration;
use std::thread;
let client = Client::new("example-client").unwrap();
let output_port = client.output_port("example-port").unwrap();
let destination = Destinations::from_index(0).unwrap();
let note_on = PacketBuffer::new(0, &[0x90, 0x40, 0x7f]);
let note_off = PacketBuffer::new(0, &[0x80, 0x40, 0x7f]);
output_port.send(&destination, ¬e_on).unwrap();
thread::sleep(Duration::from_millis(1000));
output_port.send(&destination, ¬e_off).unwrap();
If you are looking for a portable MIDI library then you can look into:
- midir (which is using this lib)
 - portmidi-rs
 
For handling low level MIDI data you may look into:
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.6.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 target/doc/coremidi/index.html
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.
 
Roadmap
- Enumerate destinations
 - Create output ports
 - Create a PacketList from MIDI bytes
 - Send a PacketList into an output port
 - Create virtual sources
 - Support a virtual source receiving a PacketList
 - Flush output
 - Enumerate sources
 - Create input ports
 - Support callbacks from input messages
 - Connect and disconnect sources
 - Add support to build PacketList (PacketBuffer)
 - Create virtual destinations with callback
 - Stop and restart MIDI I/O
 - MIDI Objects and properties
 - Client notifications
 - Support Sysex
 - Support devices
 - Support entities
 - MIDIThru connections