-
-
Save chmanie/4f2838f4548d25b9c883f7d6d074f67c to your computer and use it in GitHub Desktop.
#!/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 |
Thankyou for the script - it works perfectly. I'm presuming as it's written will only utilise devices with up to 2 ports. Wondering how I might alter it to use all ports on a 4 port usb midi interface..?
Hey @ElJimBob! I’m using it with a 4 port midi usb device and it works perfectly fine :)
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..?
Maybe they show up differently in the aconnect list that we are parsing here. Would you mind posting the output of aconnect -i -l
?
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
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
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.
See here for the original version: http://m635j520.blogspot.com/2017/01/using-raspberry-pi-as-midi-usb5-pin.html