Skip to content

Instantly share code, notes, and snippets.

@chmanie
Created January 26, 2021 18:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmanie/4f2838f4548d25b9c883f7d6d074f67c to your computer and use it in GitHub Desktop.
Save chmanie/4f2838f4548d25b9c883f7d6d074f67c to your computer and use it in GitHub Desktop.
Connect all MIDI inputs to all MIDI outputs (except themselves). Supports multi-port devices
#!/usr/bin/ruby
t = `aconnect -i -l`
$devices = {}
$device = 0
t.lines.each do |l|
match = /client (\d*)\:((?:(?!client).)*)?/.match(l)
# we skip empty lines and the "Through" port
unless match.nil? || match[1] == '0' || /Through/=~l
$device = match[1]
$devices[$device] = []
end
match = /^\s+(\d+)\s/.match(l)
if !match.nil? && !$devices[$device].nil?
$devices[$device] << match[1]
end
end
$devices.each do |device1, ports1|
ports1.each do |port1|
$devices.each do |device2, ports2|
ports2.each do |port2|
# probably not a good idea to connect a port to itself
unless device1 == device2 && port1 == port2
system "aconnect #{device1}:#{port1} #{device2}:#{port2}"
end
end
end
end
end
@ElJimBob
Copy link

Interesting. The 3rd and 4th ports of my interface seem to be ignored by the script. Its a Nektar Midiflex. I can still manually connect them to devices via qjackctl though. Perhaps it's a hardware issue..?

@chmanie
Copy link
Author

chmanie commented Oct 20, 2021

Maybe they show up differently in the aconnect list that we are parsing here. Would you mind posting the output of aconnect -i -l?

@ElJimBob
Copy link

Sure, here -
aconnect -i -l
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 16: 'MIDIFlex4' [type=kernel,card=0]
0 'MIDIFlex4 MIDI 1'
Connecting To: 16:1, 20:0, 32:0, 32:1
Connected From: 16:1, 20:0, 32:0, 32:1
1 'MIDIFlex4 MIDI 2'
Connecting To: 16:0, 20:0, 32:0, 32:1
Connected From: 16:0, 20:0, 32:0, 32:1
client 20: 'Craft Synth 2.0' [type=kernel,card=1]
0 'Craft Synth 2.0 MIDI 1'
Connecting To: 16:0, 16:1, 32:0, 32:1
Connected From: 16:0, 16:1, 32:0, 32:1
client 32: 'Launchpad X' [type=kernel,card=4]
0 'Launchpad X MIDI 1'
Connecting To: 16:0, 16:1, 20:0, 32:1
Connected From: 16:0, 16:1, 20:0, 32:1
1 'Launchpad X MIDI 2'
Connecting To: 16:0, 16:1, 20:0, 32:0
Connected From: 16:0, 16:1, 20:0, 32:0

@ElJimBob
Copy link

Screenshot_20211020-202353__01

@chmanie
Copy link
Author

chmanie commented Nov 12, 2021

I think the problem might be that the input ports on the device do not match the number of output ports but I might be mistaken. I'd have to debug that again and try to replicate the issue. Sorry if this is taking a long time

@drhitchcockco
Copy link

Has anyone had a Roland TB-03 working with their hub? When I run aconnect -l it can see the device and it's connected but I can't seem to access it from any of my other devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment