mido on ev3dev

Just a quick note: got ‘mido‘ and ‘python-rtmidi‘ working together on ev3dev

So now I can use python to access MIDI ports, send and receive MIDI messages in a cleaner way, with no need for ‘amidicat’ and pipes. Not sure yet if EV3 has enough resources for my “clean” python3 scripts to work as fast as my “dirt” pybricks scripts but it’s worth a try.

It also works with ‘multimidicast’ so ipMIDI:

$ ./multimidicast &
$ python3
»»» import mido
»»» mido.get_input_name()
»»» port = mido.open_input('./multimidicast:225.0.0.37:21928 128:0')
»»» for msg in port:
»»»     print(msg)

pressing a few keys on a virtual piano on my laptop routed to a ‘qmidinet’ port and this shows up on EV3’s python shell:

...
note_on channel=0 note=81 velocity=77 time=0
note_off channel=0 note=81 velocity=0 time=0
...

so a dancing robot (or a music guided robot) is now closer to happen.

‘mido’ also have it’s own client/server solution for networking MIDI messages but I still prefer ipMIDI since I intend to keep all coding on EV3 side.

Details on installation will follow soon.:

To install ‘python-rtmidi’ there are a few dependencies:

sudo apt install pkgconf libasound2-dev

Then it should be enough (assuming we already have pip3 – if not, then “sudo apt install python3-pip“) to

sudo pip3 install python-rtmidi --install-option="--no-jack"

but it isn’t. After ~20 minutes the EV3 crashes. I resolved the problem by adding a huge swapfile and also stopping ‘avahi-daemon’ and ‘brickman’ to free up some resources, not sure what are exactly the needed resouces but this works:

sudo ev3dev-config

use this tool to disable ‘avahi-daemon’ e ‘brickman’

Then create a 128 MB file for swapfile and use it instead of the memory-based swapfile:

sudo fallocate -l 128M /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapoff -v /dev/zram0
sudo swapon /swapfile

Then the installation of ‘python-rtmidi’ should work it tooks ~25 minutes:

Successfully installed python-rtmidi-1.4.9

NOTE: I am not sure if a swapfile of 128 MB is necessary (the default swapfile on ‘/dev/zram0’ has already 96 MB) but I did test doing this with only an huge swapfile (1 GB, without disabling ‘avahi-daemon’ nor ‘brickman’) and also just disabling those 2 services and keeping the default swapfile on ‘/dev/zram0’ and neither worked.

Then ‘mido’ should be easy:

sudo pip3 install mido

After 3 or 4 minutes we get:

Successfully installed mido-1.2.10

Then we should reactive the services (‘sudo ev3dev-config’) and undo the swapfile modification:

sudo swapoff -v /swapfile
sudo rm /swapfile
sudo swapon /dev/zram0

Deixe uma resposta

O seu endereço de email não será publicado. Campos obrigatórios marcados com *