Blog
RWMidi Processing MIDI Library25.09.2008 03:37:07
I do some quite extensive MIDI development using the awesome processing environment (check it out at http://processing.org/ ), but one thing that always left me unsatisfied was MIDI support. Also, the different MIDI implementations on Linux, Windows, OSX would lead to weird behaviour inside javax.sound.midi as well, which was most easily noticed when handling SYSEX messages. I finally resorted to write my own simple and clean MIDI wrapper for processing, which I am proud to announce to you now. You can download it at http://ruinwesen.com/support-files/rwmidi.zip . Simply unzip the file, and move the rwmidi folder to your processing libraries folder. The javadoc and a sketch example can be found at http://ruinwesen.com/support-files/rwmidi/documentation/RWMidi.html .
The library provides access to existing MIDI devices through static methods in the RWMidi class. It differentiates between input and output device, because some OS provide devices that can do both input and output, while others don't. Also, we don't provide access to devices through IDs, because these could change dynamically. The best way is to get an array with MidiInputDevices or MidiOutputDevices and access MIDI endpoints through these objects. For example:
input = RWMidi.getInputDevices()[0].createInput(this); output = RWMidi.getOutputDevices()[0].createOutput();
You can also get a list of device names and access a device through its name (beware of device having similar names). After you get the MidiInputDevice and MidiOutputDevice, you have to open a MidiInput, which is used to receive data, and a MidiOutput, which is used to send data. You can either subclass MidiInput and override the send() method, or you can register callbacks with the MidiInput. The easiest way to do this is to provide an Object to the createInput() method. This will register common methods as callbacks: noteOnReceived(Note) is called when a Note ON is received, and is given a Note object as argument. Similarly, noteOffReceived(Note) for Note OFF, controllerChangeReceived(Controller) for CC messages, programChangeReceived(ProgramChange) for program change messages, and sysexReceived(SysexMessage) for sysex messages. Sysex Messages are always transmitted in full, you won't get half of a sysex message, but always a nice complete one.
Similarly, the MidiOutput object provides a number of methods to facilitate sending MIDI Messages: sendNoteOn, sendNoteOff, sendControllerChange, sendSysex, etc...
The library was tested under Linux, Windows XP and MacOSX, and seems to work fine. However, this is an early version, so any bugs you find, let me know!




