16

I have a MIDI controller (Launchkey Mini) that I don't really use for music production anymore, but I would like to use the drum pad buttons or piano keys on it to perform computer keyboard combinations, such as Ctrl + Alt + Delete, with a single press.

Whenever I try to research this question, I either get pointed to Bome's MIDI Translator, which costs money and isn't on Linux, a horribly outdated plug-in/application, or some random library for coding it myself, which I have no clue how to do since I have virtually no skill in programming things related to audio.

I caught wind of something called VMPK, but after reading its documentation, it looks like that only converts computer keystrokes to MIDI signals, not the other way around.

Is there some way I can do this? I am on Xubuntu 16.04.

2
  • I wonder whether this might be a step in the right direction. I've only ever used it to actually drive MIDI devices from e.g. my iPhone via a regular sequencer, but maybe it's extensible to your needs - en.wikipedia.org/wiki/Open_Sound_Control
    – Tetsujin
    Jan 22, 2017 at 6:54
  • I don't know about any ready-made software, but it sounds like a fun project. With example programs how to get MIDI events and how to synthesize input keystroke events, would your programming skills be enough to make it yourself? And are you using Alsa or Jack for your MIDI controller?
    – dirkt
    Jan 22, 2017 at 7:14

2 Answers 2

23

This cannot be done without some programming.

First, test how to detect MIDI events. Go to a terminal, and run aseqdump -l to list the MIDI ports; this outputs something like this:

$ aseqdump -l
 Port    Client name                      Port name
  0:0    System                           Timer
  0:1    System                           Announce
 14:0    Midi Through                     Midi Through Port-0
 24:0    Xonar D2                         Xonar D2 MIDI
 32:0    Yamaha DS-1E (YMF754)            Yamaha DS-1E (YMF754) MIDI

Then run it with the client name to check whether events arrive:

$ aseqdump -p "Xonar D2"
Waiting for data. Press Ctrl+C to end.
Source  Event                  Ch  Data
 24:0   Note on                 0, note 64, velocity 86
 24:0   Note on                 0, note 48, velocity 80
 24:0   Note off                0, note 48
 24:0   Note on                 0, note 68, velocity 84
 24:0   Note on                 0, note 52, velocity 88
 24:0   Note off                0, note 64
 24:0   Note off                0, note 52
 24:0   Note off                0, note 68
...

Second, to simulate key strokes, you need xdotool. If you do not yet have it installed, run sudo apt-get install xdotool. You can use type to type text, or key to simulate special keys:

xdotool type Hello, World!
xdotool key ctrl+p

Please note that not all special keys are handled correctly by xdotool. And Ctrl+Alt+Del is handled very specially by the kernel and probably does not work when simulated; try running sudo reset instead of xdotool.

Finally, tie everything together with a script. Put this into a text file, for example, ~/bin/midi-to-keys:

#!/bin/bash
aseqdump -p "Xonar D2" | \
while IFS=" ," read src ev1 ev2 ch label1 data1 label2 data2 rest; do
    case "$ev1 $ev2 $data1" in
        "Note on 64" ) xdotool type hello ;;
        "Note on 48" ) xdotool key ctrl+j ;;
    esac
done

Make it executable (chmod +x ~/bin/midi-to-keys), and run it (~/bin/midi-to-keys). Now, pressing E-5 or C-4 should have some effect.

Change or add lines of the form "Note on x" ) command ;; to do whatever you want.

4
  • Oh, that's not too bad! I was worried there would be way more to it. Thank you! Jan 22, 2017 at 18:08
  • 2
    Great answer! It's amazing what you can do very easily on Linux/Unix systems by just combining a few "do one thing and do it well" command line tools together like this. I'm going to keep this example in mind when people ask me why I use Linux. I'm finally going to get some practical use out of my midi controllers now!
    – LaVache
    Apr 21, 2018 at 10:39
  • This is fantastic! I'm able to control OBS and switch scenes with my Novation Nocturn MIDI controller now! So much better, thanks!
    – Delorean
    Jun 12, 2019 at 2:52
  • Great, man! Works fine! To test without use xdotool, you can use "Note on 40" ) notify-send "summary" "body";; Dec 2, 2020 at 0:15
14

I had a similar problem so I programmed up something that suits my requirements.

https://gitlab.com/enetheru/midi2input

Runs in linux and uses the x windows system for keyboard and mouse input events.

It uses lua for configuration and mapping, can perform any action as your user. has detection on what window is active using the X_CLASS attribute so you can make different mappings for whatever application is currently running.

Automatically reloads the configuration so you don't have to close and re-open it all the time.

i've written a simple udev rule to create the midi connections when i plug in my controller.

There is even an archlinux PKGBUILD for archlinux, i just havent added it to the aur.

The idea was to remove all of the pain points in making mappings from the mid controller to anything I want.

It's been a few years since I built it out, and I use it every day, I pay attention to the repo, but there has only been one or two people ever email me about it.

2
  • Link only answers are not so usefull.
    – Toto
    Sep 15, 2017 at 7:38
  • 5
    @Toto, This one is as it addresses OP's problem directly and the link is valid Sep 15, 2017 at 8:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .