JACK MIDI and supercollider on Linux

I think you’ve two midi ‘systems’ on Linux. Alsa midi and JACK midi. a2jmidid tool converts Alsa midi to JACK midi.

But why doesn’t MIDIClient.init; give me the JACK MIDI options?

I’ve Zynaddsubfx synth running, which has a JACK midi input. I’m using a2jmidid, but supercollider doesn’t list the midi input port of Zynaddsubfx.

MIDI Sources:
	MIDIEndPoint("System", "Timer")
	MIDIEndPoint("System", "Announce")
	MIDIEndPoint("Midi Through", "Midi Through Port-0")
	MIDIEndPoint("M Audio Audiophile 24/96", "M Audio Audiophile 24/96 MIDI")
	MIDIEndPoint("SuperCollider", "out0")
	MIDIEndPoint("SuperCollider", "out1")
MIDI Destinations:
	MIDIEndPoint("Midi Through", "Midi Through Port-0")
	MIDIEndPoint("M Audio Audiophile 24/96", "M Audio Audiophile 24/96 MIDI")
	MIDIEndPoint("SuperCollider", "in0")
	MIDIEndPoint("SuperCollider", "in1")
	MIDIEndPoint("SuperCollider", "in2")
	MIDIEndPoint("SuperCollider", "in3")
-> MIDIClient

From a2jmidid man page:

a2jmidid is a daemon that implements automatic bridging. For every ALSA sequencer port you
get one jack midi port.

So a2jmidid makes ALSA midi ports available to JACK midi. It looks like you want the reverse: JACK midi ports available to ALSA (since SuperCollider works with ALSA midi). I don’t know about good options out there for this, there is j2amidi_bridge but I read that it crashes randomly (I don’t use it though, so I don’t really know).

However, exposing SuperCollider midi ports to JACK already allows you to connect SC to ZynAddSubFx, for example from QJackCtl: open the Connections window, then the MIDI tab, and you’ll find SuperCollider’s out0 port nested under a2j, in the Output Ports sections. Then you can just connect it to zynaddsubfx input.
This could be automated by creating a QJackCtl “patchbay”, or with a command like:

jack_connect "a2j:SuperCollider [129] (capture): out0" zynaddsubfx:midi_input

which could be also executed as unixCmd from within SuperCollider.

I’ll add a little script to clarify and test this configuration on SC’s side:

MIDIClient.init
// create a MIDIOut object
// sending through SuperCollider's out0 midi port
m = MIDIOut(0);

// play some bad freejazz
(
Pbind(
  \type,\midi,
  \midiout,m,
  \degree, Prand((-14..14),inf),
  \amp, 1,
  \dur, 0.1
).play
)

m.allNotesOff(0)