How to connect automatically to controllers


The time I need to connect my controllers to supercollider is always a struggle for me. Once they are setup, everything works fine.

I am wondering how do you manage them ?

I’m trying to write code to automate it but it’s not working like I expect:

When I connect my controller and try MIDIdef, it does not work. Jack doesn’t even show the MIDI in/out of supercollider

I figured I need to call MIDIClient.init for SC to add a jack in/out

But now I need to connect manually the controller to sc in jack
So I figured I can use

port = MIDIIn.findPort ("SE25", "SE25 MIDI 1");

to find the port then connect it to SC

MIDIIn.connect(0, port.uid)

The problem is if I connect my controller after calling MIDIClient.init, MIDIIn.findPort doesn’t find it. MIDIClient.destinations doesn’t includes it.

I tried both

But it does nothing

If I call MIDIClient.init a second time. The device now appears. But there is also a random number of additional output and inputs of SC inserted into the list (and jack). If I don’t take care, the s.meter become very big quick!


  1. Connect your controller first.

  2. MIDIClient.init

  3. MIDIIn.connect something (or just MIDIIn.connectAll).

  4. MIDIdef should then work transparently.

It is a weakness of SC’s MIDI client that it doesn’t recognize devices connected after initialization. Other audio software might but ours doesn’t. The solution is to connect the hardware first.


For everyone interested, I once sketched a feature to get connect/disconnect events from ALSA midi. You can see it here:

I eventually abandoned that, I could pick it up again if there’s interest!

While rewriting my MIDI/jack code, I found that this method MIDIClient.list actually refresh the list of MIDIEndPoint and then findPort works without restarting SC or running MIDIClient.init a second time !

Since you say it is impossible, I’m a bit puzzled. If this is actually a feature and not a bug, I suggest to rename it to MIDIClient.refresh to be more clear

Maybe you can use

You can specify port numbers

MIDIClient.init(6, 9);

On Linux there are also other tools to manage JACK connections, like Non/New-Session-Manager (client jackpatch), aj-snapshot or via a bash script using jack_connect for instance all though I’m not 100% sure atm if and how MIDI connections are handled by them).

Oh, OK, I didn’t realize it would do that.

So it’s easier, then!

In a related scenario: In my last show, I wanted to play notes in VCV Rack using MIDI from SC. That was a bit of a chicken-egg scenario: If I initialized SC’s MIDIClient before launching Rack, then SC couldn’t find Rack’s MIDI port. If I launched Rack first, then it wouldn’t find SC’s MIDI port (and this would require manual intervention, which I didn’t want).

The solution turned out to be a2j-midid – create a virtual thru port first, and connect both SC and Rack to that.