How to use Tonelib GFX with Midi Controller (Program and controller changes) on Linux

Discussion in 'General discussion' started by Dr.Axelbauer, Aug 15, 2024.

  1. Dr.Axelbauer

    Dr.Axelbauer New Member

    Hi there!
    I am using Tonelib GFX on a daily basis and was a little bit disappointed that "program changes" of my midi controller are not supported.

    Here I describe my workaround on how to get all switches of my foot pedal working on linux machines! – Not just the CC (Controller change) switches but also the PC (Program changes).

    I use the following hardware (but I think the method mentioned below, is not restricted to a specific midi hardware aka foot switch):

    Midi controller: Harely Benton MP100 Midi Foot Controller
    connected to my Laptop via USB.

    System: Ubuntu Studio (but as normally is the case in the linux world: everything i describe should be possible on any distro)

    My workaround is: Bind the Midi events to xdotool events and by this simulate keypresses via your midi controller. Sounds complicated but isn't that hard.

    I made a bash script with the following content:
    Code:
    #!/bin/bash
    aseqdump -p "TSMIDI2.0" | \
    while IFS=" ," read src ev1 ev2 ch label1 data1 label2 data2 rest; do
        case "$ev1 $ev2 $data1" in
            "Program change 0" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+1" ;;
            "Program change 1" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+2" ;;
            "Program change 2" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+3" ;;
            "Program change 3" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+4" ;;
            "Program change 4" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+o" ;;
            "Program change 5" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+shift+o" ;;
            "Control change 26" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+m" ;;
            "Control change 24" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+d" ;;
            "Control change 26" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+m" ;;
            "Control change 25" ) xdotool key --window '$(xdotool getactivewindow)' "shift+Up" ;;
            "Control change 22" ) xdotool key --window '$(xdotool getactivewindow)' "shift+Down" ;;
            "Program change 6" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+a" ;;
            "Program change 7" ) xdotool key --window '$(xdotool getactivewindow)' "ctrl+shift+a" ;;
     esac
    done
    If you run that script in the background and switch back to the Tonelib GFX window currently running, the midi switches should work.

    Here are some further explanations for the script:
    Name of the midi device:
    TSMIDI2.0 = name of my midi device – you can get the names of your midi devices in the terminal via - be sure to start a2jmidid first.
    Code:
    aseqdump -l
    Identify midi switch presses:
    Run:
    Code:
    aseqdump -p "TSMIDI2.0"
    Press a midi switch and you will see in the output of the command, the Event and Data of the pressed switch. There are two different types of events: Program changes and Controller changes; you can assign different switches if you want. In my case program 1A (on my midi device) has the identifier: "Program change 0" due to the output:
    Code:
    aseqdump -p "TSMIDI2.0"
    Waiting for data. Press Ctrl+C to end.
    Source  Event                  Ch  Data
      0:1   Port subscribed            128:0 -> 131:0
     32:0   Program change          0, program 0
    --window '$(xdotool getactivewindow)'
    This just means, that xdotool only uses the keystrokes on the current window in the foreground (which should be Tonelib on our case).

    Generally:
    • Don´t forget to run the script in the background while you are using Tonelib otherwise it won´t work.
    • I am not sure if xdotool is working on linux distros with wayland (newer distros switched from X to Wayland) but I think there is an equivalent (I don´t remember the name or workaround) – look for it...
    • Of course: some knowledge on bash scripting in linux might be helpful ;)
    • Install xdotool first:
      Code:
      sudo apt-get install xdotool a2jmidid
    • Don´t forget to make the script executable:
      Code:
      chmod +x nameofyourscript
    If you have questions just ask – Where there is Linux there is a way! – Happy shredding!
     
    Last edited: Aug 15, 2024
    Hessu Hopo likes this.