Midi connection manager

My situation is a little different, but this might help: Live I have a big Pd patch that is both audio effects controlled by MIDI controllers, and a MIDI router between keyboard (-ish) controllers and synths. Depending on my mood and what I pack to a gig, which controllers and synths I have varies… but I want to run the Pi headless… so I needed a way to have the whole thing automatically patch as needed…

I use this script:

#!/bin/sh

aconnect -x

try_aconnect() {
	aconnect "$1" "$2" 2>/dev/null && echo connected $1 '-->' $2 || true
}

# in Pd, four midi devices appear as 0~3 in, and 4~7 out
try_aconnect 'Faderfox UC44':0 'Pure Data':0
try_aconnect 'Elektron Digitakt':0 'Pure Data':1
try_aconnect 'Circuit':0 'Pure Data':2
try_aconnect 'PreenFM mk2':0 'Pure Data':2
try_aconnect 'pisound':0 'Pure Data':2
try_aconnect 'nanoKEY2':0 'Pure Data':3
try_aconnect 'DU-TOUCH S':0 'Pure Data':3
try_aconnect 'Launchpad Pro':1 'Pure Data':3

try_aconnect 'Pure Data':4 'Faderfox UC44':0
try_aconnect 'Pure Data':5 'Elektron Digitakt':0
try_aconnect 'Pure Data':6 'Circuit':0
try_aconnect 'Pure Data':6 'PreenFM mk2':0
try_aconnect 'Pure Data':6 'pisound':0

Essentially, I define four ports, for four different functions in my Pd patch:

  • port 0: main knob/fader controller
  • port 1: drum machine
  • port 2: synth
  • port 3: note controller

Then this script just attempts to hook up everything… and is tolerant of missing devices.

I’ve arranged for this script to run after both as the CLICK_3 script, and at the end of the CLICK_1 script.
I can thus re-connect devices on the fly.

1 Like