Using Midi events to run shell commands with mididing

Hi all,

I was quite frustrated because the Zynthian freezes quite often while using it…
So I wanted to be able to restart the Gui and services easily, without the need of an ssh client. Moreover, I intend to use the Zynthian for playing live :slight_smile: so I need a quick way to get the box up and ready quickly !

I have just made an experiment with mididing and I am quite happy so far.
Mididing is available on the repo and based on Python and you can run shell commands upon a midi event.
So I made the following script:

from mididings import *
   CtrlFilter(45) >> System('systemctl restart zynthian')

All it does is ‘systemctl restart zynthian’ when the midi control 45 event is received.
To run the mididing service:

mididings  -f

Next, you have to connect the new mididing midi device to your midi controler:
I did it graphically using qjackctl to be quick but it would be better to use the aconnect command.

I hope this is helpful



Sorry to hear about your freezing problems. Do you see encoder chatter? (An particular encoder changing rapidly between values and the knob becomes unresponsive…?) Perhaps could be cable seating inside the box?

I picture a big red button… :red_circle: :boom:

Not used mididings. Another tool in the box.
-1 for the import * :smiley:

IIRC, @jofemodo decided to not use mididings in his midi filtering system, because it is not dynamic.
If you make changes and you have to reload everythinig.

Hence for a “real” solution, we might think of having system internal commands as destination in the midi filtering system.
Not only midi->midi, but midi->script or something like that.

Guilty for the import * haha

It is actually freezing when I manipulate synths too much (like new layers, remove layers, open snapshots, etc)
One particular issue is that the zynthian got stuck because of a bad index on the GUI.
I faced other supposed bugs but I don’t know how to reproduce them exactly.
So I don’t think it is a wiring issue.

Ok, Sorry then, it sounds like you have code issues not hardware.

Have you tried redirecting the logging in /zynthian/zythian-ui/ ?
replace or comment out :

# Set root logging level
logging.basicConfig(stream=sys.stderr, level=zynthian_gui_config.log_level)


                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',

and then in another terminal

tail -f /tmp/myapp.log

Course I’ve not tried it and there might be a better way but that ~SHOULD~ work …

Apologies if you know all this and you tried it all sometime ago …

Apologies on a grand scale if this is actually rubbish . . …

Better methods appreciated.

Oh and remember to replace the original line once you have some info, logs can tend to clutter things up a bit.

1 Like

easier might be this

systemctl stop zynthian

1 Like

And there’s the better method . . . .


But as developer I like yours better :slight_smile:

1 Like

I understand the point about mididings beeing not dynamic.
Yes, a solution based on the existing midi filtering engine would be better but my point is just that mididings offers an easy way to execute system commands. I use it to restart services but it could also be useful for other things (power off, play file …)
The ssh method is best of course, as long as you have a ssh client available :slight_smile:

In the next “iteration”, i will add “shell” commands to the router :ok_hand:

1 Like

would it be a quick solution to execute the mididings script directly from python?

If you need it quick, mididing is your thing.
But its not part of the final solution.

Hi @claudev

How did you put the mididing script at zynthian startup?

I am trying to connect mididing port and ZynMidiRouter with the following command at startup:

/usr/bin/jack_connect mididings:in_1 ZynMidiRouter:main_out

however I am having the following error at startup:

“ZynMidiRouter ERROR: main_out not a valid port”

Regards, Rod

Hi @rod_amaral

I have never used the ‘main_out’ mini output.
Have you tried to specify the output first, and then the input ?
like this: /usr/bin/jack_connect ZynMidiRouter:main_out mididings:in_1

I normally use the channel outputs:
/usr/bin/jack_connect "ZynMidiRouter:ch5_out" "mididings:in_1"

I use this snippet into a systemd script, for information.

I hop it helped.

Kind regards,