Scripting Linux ALSA-MIDI connections - how to ensure Rack ports exist?

I would like to use VCV Rack in my next set.

I’m using SuperCollider for live coding, and recently added a MIDI output option. This is working nicely with Rack. (This is in Linux, so inter-app audio and MIDI are easy – no problems there. The audio connections are straightforward – I issue jack_connect shell commands from within SC.)

My question is about automating the MIDI connections when opening the session.

I have two choices:

  1. Launch Rack first, then SC. Problem: At the moment of launching Rack, the SC MIDI ports don’t exist. So the MIDI-CV and MIDI-CC modules can’t find the source device – meaning that they open with ALSA MIDI backend (OK) but “No device.” If it’s not connected to a device, then it doesn’t create the ALSA MIDI port at all :confused: – so, when I initialize the MIDI client in SC, VCV Rack isn’t there. SC does have the capability to make the MIDI connection, but only if it can find the target port.

  2. Launch SC first, then Rack. This can be made to work, but it’s not quite smooth. I have to MIDIClient.init in SC to create the source MIDI port – then open Rack and let the MIDI modules find the source (there’s a possible point of failure here) – then close SC’s MIDIClient and reopen it so that it sees Rack. It functions OK, but if I do something in the wrong order (which is easy to do when you’re on stage with a lot of setup steps to handle), then it gets a little dicey.

This would be much easier if MIDI-CV and MIDI-CC would open their MIDI ports at the moment of selecting ALSA, instead of waiting to connect to a specific device.

The point of failure, by the way, is: If I forget to open SC MIDIClient before launching Rack, then the MIDI modules’ device selection is cleared – and there is no way to get it back except to click by hand on the modules. The only solution is manual intervention, effectively making it impossible to script the connections. (It seems to me that allowing clever users to script the connections would be good for usability.)


1 Like

what if use jack midi bridge and connect everything to jack midi?

what about using jack with

a2jmidid -e -u

before starting SC and VCV?

1 Like

@David @Nils Thank you both. I just tried it and it will work nicely. I can even run the daemon as a unixCmd in the SuperCollider script :sunglasses:

Thanks! hjh