Skip to content

Instantly share code, notes, and snippets.

@shikaan
Created June 9, 2020 19:47
Show Gist options
  • Save shikaan/1a3e7d42e25247d0c9cf5f18c0ea4ffb to your computer and use it in GitHub Desktop.
Save shikaan/1a3e7d42e25247d0c9cf5f18c0ea4ffb to your computer and use it in GitHub Desktop.
Attaches a midi device to Qsynth through ALSA
#!/usr/bin/env bash
# CONSTANTS
readonly MIDI_DEVICE_NAME=GarageKey
# VARIABLES
midi_device_port=
qsynth_port=
# FUNCTIONS
function get_qsynth_alsa_port() {
if [[ -z "${qsynth_port}" ]]; then
sleep 1
qsynth_port=$(aconnect -l | grep -E "client.*Qsynth" | sed -E "s/client ([0-9]+).*/\1/g" -)
else
get_qsynth_alsa_port
fi
}
echo "Fetching alsa port for ${MIDI_DEVICE_NAME}..."
midi_device_port=$(aconnect -l | grep -E "client.*${MIDI_DEVICE_NAME}" | sed -E "s/client ([0-9]+).*/\1/g" -)
echo "> Got port ${midi_device_port}. Using it as input"
echo "Launching Qsynth..."
qsynth -a alsa & &> /dev/null
echo "Fetching alsa port for Qsynth..."
get_qsynth_alsa_port
echo "> Got port ${qsynth_port}. Using it as output"
echo "Connecting device to Qsynth..."
aconnect ${midi_device_port} ${qsynth_port}
PS3="Play a note. Do you hear anything? How do you want to proceed?"
select answer in "Close" "Launch diagnosis tool" "Try again"; do
case $REPLY in
1)
break
;;
2)
aseqdump -p ${midi_device_port}
;;
3)
$(basename $0) && exit
;;
*)
echo "Invalid option $REPLY"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment