MIDI Communications MacOS Layer

Realtime MIDI IO with Ruby for OSX.

Access the Apple Core MIDI framework API with Ruby.

This library is part of a suite of Ruby libraries for MIDI:

Function Library
MIDI Events representation MIDI Events
MIDI Data parsing MIDI Parser
MIDI communication with Instruments and Control Surfaces MIDI Communications
Low level MIDI interface to MacOS MIDI Communications MacOS Layer
Low level MIDI interface to Linux TO DO (by now MIDI Communications uses alsa-rawmidi)
Low level MIDI interface to JRuby TO DO (by now MIDI Communications uses midi-jruby)
Low level MIDI interface to Windows TO DO (by now MIDI Communications uses midi-winm)

This library is based on Ari Russo's library ffi-coremidi.

Features

  • Simplified API
  • Input and output on multiple devices concurrently
  • Generalized handling of different MIDI Message types (including SysEx)
  • Timestamped input events
  • Patch MIDI via software to other programs using IAC
  • No events history and no buffers optimization

Requirements

Installation

If you're using Bundler, add this line to your application's Gemfile:

gem "midi-communications-macos"

Otherwise

gem install midi-communications-macos

Documentation

(TO DO) rdoc

Differences between MIDI Communications MacOS Layer library and ffi-coremidi library

MIDI Communications MacOS Layer is mostly a clone of ffi-coremidi with some modifications:

  • Added locking behaviour when waiting midi events
  • Removed buffering and process history information logging (to reduce CPU usage in some scenarios)
  • Improved MIDI devices name detection
  • Source updated to Ruby 2.7 code conventions (method keyword parameters instead of options = {}, hash keys as 'key:' instead of ':key =>', etc.)
  • Updated dependencies versions
  • Renamed module to MIDICommunicationsMacOS instead of CoreMIDI
  • Renamed gem to midi-communications-macos instead of ffi-coremidi
  • TODO: update tests to use rspec instead of rake
  • TODO: migrate to (or confirm it's working ok on) Ruby 3.0 and Ruby 3.1

Then, why does exist this library if it is mostly a clone of another library?

The author has been developing since 2016 a Ruby project called Musa DSL that needs a way of representing MIDI Events and a way of communicating with MIDI Instruments and MIDI Control Surfaces.

Ari Russo has done a great job creating several interdependent Ruby libraries that allow MIDI Events representation (MIDI Message and Nibbler) and communication with MIDI Instruments and MIDI Control Surfaces (unimidi, ffi-coremidi and others) that, with some modifications, I've been using in MusaDSL.

After thinking about the best approach to publish MusaDSL I've decided to publish my own renamed version of the modified dependencies because:

  • The original libraries have features (buffering, very detailed logging and processing history information, not locking behaviour when waiting input midi messages) that are not needed in MusaDSL and, in fact, can degrade the performance on some use cases in MusaDSL.
  • The requirements for Musa DSL users probably will evolve in time, so it will be easier to maintain an independent source code base.
  • Some differences on the approach of the modifications vs the original library doesn't allow to merge the modifications on the original libraries.
  • Then the renaming of the libraries is needed to avoid confusing existent users of the original libraries.
  • Due to some of the interdependencies of Ari Russo libraries, the modification and renaming on some of the low level libraries (ffi-coremidi, etc.) forces to modify and rename unimidi library.

All in all I have decided to publish a suite of libraries optimized for MusaDSL use case that also can be used by other people in their projects.

Function Library Based on Ari Russo's Difference
MIDI Events representation MIDI Events MIDI Message removed parsing, small improvements
MIDI Data parsing MIDI Parser Nibbler removed process history information, minor optimizations
MIDI communication with Instruments and Control Surfaces MIDI Communications unimidi use of MIDI Communications MacOS Layer
Low level MIDI interface to MacOS MIDI Communications MacOS Layer ffi-coremidi removed buffering and process history information, locking behaviour when waiting midi events, improved midi devices name detection, minor optimizations
Low level MIDI interface to Linux TO DO
Low level MIDI interface to JRuby TO DO
Low level MIDI interface to Windows TO DO

Author

Acknowledgements

Thanks to Ari Russo for his ruby library ffi-coremidi licensed under Apache License 2.0.

As explained by Ari Russo regarding his library ffi-coremidi:

  • ffi-coremidi began with some coremidi/ffi binding code for MIDI output by Colin Harris contained in his fork of MIDIator and a blog post.
  • MIDIator is (c)2008 by Ben Bleything and Topher Cyll and released under the MIT license (see LICENSE.midiator and LICENSE.prp)
  • Also thank you to Jeremy Voorhis for some useful debugging.

License

MIDI Communicatios MacOS Layer Copyright (c) 2021 Javier Sánchez Yeste, licensed under LGPL 3.0 License

ffi-coremidi Copyright (c) 2011-2017 Ari Russo, licensed under Apache License 2.0 (see the file LICENSE.ffi-coremidi)