Skip to content

Instantly share code, notes, and snippets.

@shikaan
Created June 9, 2020 19:47
Show Gist options
  • Select an option

  • Save shikaan/1a3e7d42e25247d0c9cf5f18c0ea4ffb to your computer and use it in GitHub Desktop.

Select an option

Save shikaan/1a3e7d42e25247d0c9cf5f18c0ea4ffb to your computer and use it in GitHub Desktop.

Revisions

  1. shikaan created this gist Jun 9, 2020.
    52 changes: 52 additions & 0 deletions midi-to-qsynth
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/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