So I thought it might be worth documenting how to get MIDI working with SP on Linux (Ubuntu 16.04) as, despite being relatively experienced, I struggled; and is a worthwhile goal because MIDI connectivity opens up a world of different sound possibilities for SP outside of the native SuperCollider engine.
This is written with the Sunvox softsynth in mind as a target (Sunvox is MIDI enabled) but what goes here almost certainly goes for other MIDI targets, whether software or hardware.
Linux Sound Background
I am absolutely not an expert here and encourage you to go read Ted Felix’s excellent guide -
http://tedfelix.com/linux/linux-midi.html
but in summary -
- ALSA (Advanced Linux Sound Architecture) is the part of the Linux kernel that talks to your sound-related hardware (sound cards and MIDI interfaces)
- JACK is an extra layer over ALSA offering low latency and the ability to synchronize multiple audio sources
We need to use JACK rather than ALSA here because SuperCollider only works with JACK.
qjackctl
qjackctl is the best way to configure and manage JACK connections.
- Setup -> Interface -> [ensure your native soundcard is picked; may require some experimentation]
- Setup -> Midi Driver -> seq [this should be enabled by default]
- Start [hit the start button]
a2jmidid
Now if you happened to connect a Korg NanoKey keyboard to your Linux machine and launch Sunvox in its standard ALSA mode, everything “just works”. But if you configure/launch qjackctl and configure Sunvox for JACK, stuff no longer “just works”
This is because ALSA MIDI and JACK MIDI are apparently different things.
Specifically, Sunvox can work with either, but the NanoKey seems to want to work in ALSA MIDI mode; so you force Sunvox to work in JACK MIDI mode, the two can no longer speak.
[why do all MIDI Readable Clients, whether NanoKey, SP or other, seem to want to work in ALSA MIDI mode only ?]
Fortunately this can be resolved by using a2jmidid, which bridges ALSA MIDI connections to JACK MIDI connections, so that our MIDI Readable Client can now talk to our MIDI Writeable Client.
a2jmidid --export-hw
Sunvox
Sunvox (http://www.warmplace.ru/soft/sunvox/) is an absolutely terrific sounding softsynth written by Russia’s equivalent of @samaaron, a guy called Alexander Zolotov. It is available for pretty much every platform you can name (Windows/Mac/Linux/ioS/Android). It is MIDI enabled. It can work with all the different Linux sound systems including ALSA and JACK. I am not paid to promote it
Because SuperCollider only works with JACK we need to configure Sunvox to also use JACK; if you have JACK running and try to launch Sunvox in its default (ALSA) configuration, it will likely hang. So -
Preferences -> Audio -> Driver = JACK
Preferences -> MIDI -> MIDI Controller 1 = JACK
[you’ll probably need to do this in separate stages; configure Audio first without JACK running; then shutdown Sunvox, launch qjackctl (see above), re- launch Sunvox and configure MIDI, now JACK is shown as an available MIDI option]
Sonic Pi
Launch SP as normal
Connecting SP and Sunvox via qjackctl
Ready to go. So, assuming -
- qjackctl is running
- a2jmidid is running
- Sunvox is running and has been configured to use JACK as per above
- SP is running
then your qjackctl Connect -> MIDI tab should look as follows
[I have added the connection manually, by selecting a source/target from each window and clicking ‘Connect’]
Then assuming you have a Sunvox module selected in the Sunvox UI, a quick SP script should allow you to hear a sound played in Sunvox.
midi_note_on 50
sleep 1
midi_note_off 50
All done. Phew! A world of possibilities opens up. I’m off to but a MIDI-to-CV controller for my Erica Pico
Thanks to @Martin for some very helpful pointers.