Loading qmidiroute (and map file) on login, auto-restarting on crash (using qmidiroute to convert MIDI footswitch program change messages to control change messages)

Hello there blokas community! I have been on a thrilling (mostly frustrating) ride this past week, trying to get my DXFC midi foot controller to work with MODEP. It only sends program change messages and cannot be reprogrammed, so I had to figure out how to convert MIDI program change to control change messages (which are recognized by MODEP)… Then, once I figured that out, how to make the program converting those messages load automatically when I plug in the pi. Then, once I figured that out, how to prevent the program from crashing OR make it automatically reboot after crashing. This is where I am currently stuck and need support.

I tried out a long list of programs and different possible methods, including midifilter, drumstick midi monitor, puredata, reaper, qtractor, and finally qmidiroute. Trying out these different programs often required me to learn how to install programs and dependencies using cmake or cpan, and was a very steep learning curve for me. After reaching a ton of dead-ends, finally I got it to work perfectly using qmidiroute… The next issue, though, was running qmidiroute automatically on startup/login.

Again I tried a wide variety of methods, including rc.local, init.d, systemd, crontab, and finally .bashrc. For most of these methods I was able to get the script to run on startup/login, but there were various issues with calling the route map file, so I ended up with an empty qmidiroute running on startup (without any of the rules for routing MIDI messages running, so effectively useless). Finally, I was able to get it to work using a ridiculous and haphazard method: editing the .bashrc file to run the command “qmidiroute home/patch/DXFC.qmr” every time I open a new terminal window. Then, I made the file /home/pi/.config/lxsession/LXDE-pi/autostart with the command “x-terminal-emulator” to open a new terminal window at startup. This works (miraculously), but for some reason breaks the desktop environment, so that it’s just a black screen with terminal windows and the qmidiroute gui. This is fine for me, as long as I can reverse it when I need to access the desktop environment again. But now I am having another issue…

For some reason I can’t figure out, qmidiroute crashes occasionally and I lose all of my MIDI message reroutes (thus the foot controller suddenly stops working). I am thinking that there are two ways to resolve this… 1) I could modify the command or script somehow to continuously check if qmidiroute home/patch/DXFC.qmr is running - and if not, to run it again; and 2) I could modify the command/script somehow to have the “qmidiroute home/patch/DXFC.qmr” run repeatedly every x minutes. Method 2) seems like something I could actually figure out, but doesn’t seem ideal because I could end up with qmidiroute crashing and having to wait for it to reboot, or I could end up with a bunch of simultaneous qmidiroutes eating up cpu power. So I am wondering if anyone knows how I could configure option 1), based on the programs and method I described above, that would be amazing. If you have a better method of doing this, that would also be amazing.

Any support would be immensely appreciated, as I have been struggling with this for some time now. I imagine that it would be relevant to many users who have a similar foot controller (that only sends program change messages and cannot be reprogrammed) who need to convert the midi messages. Many thanks in advance!

This sounds like a good job for systemd - it can restart processes upon them crashing.

One unobvious thing to understand when writing the .service files is that by default, it’s in a completely empty environment, so you can’t rely on ‘current directory’, or ‘PATH’ being there, so the execution line must use absolute paths to the executable files. Then the process you start may be expecting some variables set up like HOME. You can also make it start as some regular user rather than root.

Do you still have some systemd service draft available? We could help you push it through to a state where it does what you expect it to do. :slight_smile:

Thanks so much for your quick response, Giedrius! I tweaked around with systemd a little bit, with no luck. However, I followed the instructions here and just added @ symbols to the beginning of the commands in /home/pi/.config/lxsession/LXDE-pi/autostart …

@x-terminal-emulator
@qmidiroute /home/patch/DXFC.qmr

…and it seems to be stable, I haven’t noticed losing the footswitch control again yet! So I guess I am all set on this for now. Thanks again for your help.

1 Like