Configuring Mac OS X MIDI Programmatically

I am writing a program that converts OSC to MIDI, allowing OSC-enabled applications (like touchOSC on my iPhone) to control MIDI-enabled applications (Sibelius, Ableton Live, etc.).

I use Python to create an OSC server and convert from OSC to MIDI. To get the MIDI for the application in question, I output the MIDI to the Apple IAC driver, which is then included as an input in the program in question.

Does anyone know a means to programmatically configure Mac MIDI devices programmatically? In particular, I need to enable the IAC driver, which is disabled by default.

Using FileMon, I noticed that Audio Midi Setup.app modifies this file when IAC driver is enabled / disabled:

~ / Preferences / ByHost / com.apple.MIDI.0017f2cxxxxx.plist

The number 0017f2cxxxxx is my system IOPlatformUUID. This is a simple list of XML properties, but I am afraid to write directly to it. Even if I did, apparently, would I have to persuade the midi server process to re-read it somehow?

Finally, I am becoming more and more aware that using the IAC driver is generally a fairly primitive solution - for starters, it only works on a Mac! Ideally, I would write a feedback MIDI driver, and all my problems would be solved ...

+4
source share
3 answers

Your hunch about writing directly on plist is correct - you probably shouldn't. I'm not 100% sure about this, but I have the feeling that the plist reflects the state of the MIDI device, but changing it will not open or close this MIDI device as necessary.

To really open a MIDI device, you can use something like pygame . I used it for some projects related to audio, and the SDK is very simple and easy to use. Since python doesn't have much support for MIDI directly, this is probably the best choice (if you didn't write the python C module itself, which would be pretty painful).

As for the IAC, it’s a shame that another OS doesn’t have virtual MIDI devices like this. IAC is very useful and good at what it does. Therefore, relying on the IAC for something like this, it will not be cross-platform, you can write an abstraction layer to control the loopback device. For Windows users, you can recommend the free MIDI loopback device that will be used with your software.

+3
source

If you want to send the OSC to MIDI, you'd better create a virtual Midi port in the software, and try to remotely configure IAC. This virtual port will appear in Ableton, etc., so that you can then manage it programmatically.

You can do this using the rtmidi-python library (or an older and slightly different pyrtmidi ) - both are based on the cross-platform rtmidi lib, which provides direct MIDI Control sending and Notes:

import rtmidi_python as rtmidi vmidi_out = rtmidi.MidiOut() vmidi_out.open_virtual_port('My Virtual MIDI Output Port') vmidi_out.send_message([0x90, 48, 100]) # Note on vmidi_out.send_message([176, 7, 100]) # Control Change - Volume 
+1
source

PyGame itself uses PortMidi under the hood. If you do not need the entire PyGame library, this may be useful for you.

0
source

All Articles