Using Midi events to run shell commands with mididing

#1

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 *
config(
    backend='jack-rt',
)
run(
   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  my_midi_bash_script.py

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

Regards,
Claude

3 Likes

#2

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:

0 Likes

#3

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.

0 Likes

#4

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.

0 Likes

#5

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

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

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

with

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='/tmp/myapp.log',
                    filemode='w')

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

#6

easier might be this

http://wiki.zynthian.org/index.php/Command_Line_User_Guide

systemctl stop zynthian
/zynthian/zynthian-sys/sbin/zynthian.sh

1 Like

#7

And there’s the better method . . . .

:smiley:

0 Likes

#8

But as developer I like yours better :slight_smile:

1 Like

#9

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:

0 Likes

#10

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

1 Like

#11
2 Likes

#12

would it be a quick solution to execute the mididings script directly from python?
http://dsacre.github.io/mididings/doc/tools.html#mididings
python my_midi_bash_script.py

0 Likes

#13

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

0 Likes

#14

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

0 Likes

#15

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,
Claude

0 Likes