Previously, in order to be able to shut down my Pi from the MODEP UI, I wrote a script to listen for a particular MIDI CC and value, then shut the host system down.
I then thought of a number of different uses for this same MIDI-triggering-commands approach, and re-implemented it in a more generalized fashion as MidiCmdServer:
In the script, you can easily set any number of new command for it to listen for like this:
#midi_cmd(cc_num, cc_val, "command to run", optional_uptime_second_restriction) midi_cmd(64, 127, "init 0", 120) # ^ same as the original shutdown server functionality midi_cmd(127, 30, "echo 'test' > /tmp/test") midi_cmd(64, 0, "uptime > /tmp/uptime")
Commands are executed via os.system.
This approach allows for also assigning whatever commands you might want on a host system, to any MIDI CC number and value.
To have the server start on boot, I usually add it to crontab (set your path properly):
@reboot /usr/bin/sudo /path/to/midi_cmd_server.py &
In the MODEP UI, simply select the MidiCmdServer as an output (capture) MIDI port and connect your expected MIDI source to it.
Hopefully this proves to be useful to other folks who are messing around with MIDI stuff on their Pis and other hardware!