Skip to content

Instantly share code, notes, and snippets.

@lukaszkorecki
Last active February 1, 2025 19:51
Use Raspberry PI as a MIDI Host, connecting Arturia MiniLab to Korg Minilogue XD (module, regular version has a keyboard so this would be useless to do)
# assuming you sudo su'd yourself
# confirmed working with Raspberry Pi 3B+
# Minilogue XD & MiniLab are both connected via USB, and USB+MIDI is enabled in Minilogue's settings
# save the midi-usb-setup.sh script in /usr/bin/midi-usb-setup
# save midi-usb.service in /etc/systemd/system/midi-usb.service
# now do the setup the service:
chmod +x /usr/bin/midi-usb-setup
systemctl daemon-reload
systemctl enable midi-usb.service
systemctl start midi-usb.service
systemctl status midi-usb.service
aconnect -l
# that takes care of automatic setup on start
# let's configure udev so that the service runs on USB device changes
# Save the following in
echo 'ACTION=="add|remove", SUBSYSTEM=="usb", RUN+="/bin/systemctl restart midi-usb.service"' > /etc/udev/rules.d/99-midi-usb.rules
# and activate with:
udevadm control --reload-rules
udevadm trigger
# At any point run the following to see the logs:
journalctl -u midi-usb.service -f
systemctl status midi-usb.service
#!/usr/bin/env bash
# save this under /usr/bin/midi-usb-setup
# we need to wait for two sets of MIDI devices:
miniLabConnected() {
if [[ -n $(aconnect -o | grep -E 'Arturia MiniLab') ]]; then
echo "true"
else
echo "false"
fi
}
minilogueConnected() {
if [[ -n $(aconnect -i | grep -E 'minilogue xd') ]]; then
echo "true"
else
echo "false"
fi
}
# Wait for minilogueto be connected, it's the slowest
tryCount=0
maxTries=8
minilogueFailed=false
while [[ $(minilogueConnected) == "false" ]]; do
echo "Waiting for minilogue to be connected..."
tryCount=$((tryCount + 1))
if [[ $tryCount -ge $maxTries ]]; then
tryCount=0
echo "Could not connect to minilogue, stopping..."
exit 0
fi
sleep 1
done
# Wait for minilab to be connected
while [[ $(miniLabConnected) == "false" ]]; do
echo "Waiting for Minilab to be connected..."
tryCount=$((tryCount + 1))
if [[ $tryCount -ge $maxTries ]]; then
tryCount=0
echo "Could not connect to minilab, exiting..."
exit 0
fi
sleep 1
done
## now we can connect MiniLab to minilogue
# first, clear all routes
aconnect -x
# get client ID for Minilab:
# output is: client 20: 'Arturia MiniLab mkII' [type=kernel,card=1], we need the '20:'
miniLabClientID=$(aconnect -l | awk '/client.+Arturia.+MiniLab/ { print $2 }')
minilogueClientID=$(aconnect -l | awk '/client.+minilogue xd/ { print $2 }')
# now connect all inputs to outputs, minilogue has two input ports!
aconnect ${miniLabClientID}0 ${minilogueClientID}0
aconnect ${miniLabClientID}0 ${minilogueClientID}1
[Unit]
Description=MIDI USB Auto-Setup
After=network.target
Wants=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/midi-usb-setup
User=root
StandardOutput=journal
StandardError=journal
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment