Note: please use triple backticks ( ``` ) to enclose your code (see my edit to your latest post).
As mentioned above:
giuliomoro stdbuf -i 0 -o 0 -e 0 cat /dev/snd/midiC1D0 > /dev/snd/midiC0D0
and leave it running. This will pipe the inputs from hw:1,0 to hw:0,0. In my case, these correspond to a USB MIDI keyboard and the first virmidi port, you'll have to check for your setup.
if you need to loopback multiple devices, then you need to check what devices you have with amidi -l
and then you would need many of these lines
stdbuf -i 0 -o 0 -e 0 cat `$INPUT > $`OUTPUT
with $INPUT
and $OUTPUT
set to different devices from time to time.
You can trial this by having multiple terminal sessions open and one of these on each. But if you want to set this at startup, it may be worthwhile to create a screen
for each of these, e.g. this line may work (untested):
screen -S "midi-loopback-$INPUT" -d -m bash -c "stdbuf -i 0 -o 0 -e 0 cat $INPUT > $OUTPUT"
the easiest way to put this in a script would then be something along the lines of (untested):
#!/bin/bash
modprobe snd-virmidi
loopback_in_screen()
{
while sleep 1
do
ls $INPUT &>/dev/null && ls $OUTPUT &> /dev/null &&\
screen -S "midi-loopback" -d -m bash -c "stdbuf -i 0 -o 0 -e 0 cat $INPUT > $OUTPUT" && break
done
}
INPUT=/dev/snd/midiC1D0
OUTPUT=/dev/snd/midiC0D0
loopback_in_screen
INPUT=/dev/snd/midiC2D0
OUTPUT=/dev/snd/midiC3D0
loopback_in_screen
INPUT=/dev/snd/midiC4D0
OUTPUT=/dev/snd/midiC5D0
loopback_in_screen