In the comments, dirkt suggested to write a custom program. So, I wrote a short working proof of concept script in Python that reads inputs from a MIDI controller and then simulates the required key press. I tested it on Ubuntu 20.04. Unfortunately, it requires superuser privileges to run, otherwise /dev/uinput cannot be opened for writing.
import mido
from evdev import uinput, ecodes as e
def press_playpause():
"""Simulate pressing the "play" key"""
with uinput.UInput() as ui:
ui.write(e.EV_KEY, e.KEY_PLAY, 1)
ui.syn()
def clear_event_queue(inport):
"""Recent events are stacked up in the event queue
and read when opening the port. Avoid processing these
by clearing the queue.
"""
while inport.receive(block=False) is not None:
pass
device_name = mido.get_input_names()[0] # you may change this line
print("Device name:", device_name)
MIDI_CODE_PLAY = 115
MIDI_VALUE_ON = 127
with mido.open_input(name=device_name) as inport:
clear_event_queue(inport)
print("Waiting for MIDI events...")
for msg in inport:
print(msg)
if (hasattr(msg, "value")
and msg.value == MIDI_VALUE_ON
and hasattr(msg, "control")
and msg.control == MIDI_CODE_PLAY):
press_playpause()
Requirements:
uinput, and read up on the ALSA MIDI interface. You don't have to do this in C, e.g. Python has libraries for both.