{"id":1717,"date":"2021-02-05T09:13:13","date_gmt":"2021-02-05T09:13:13","guid":{"rendered":"https:\/\/ofalcao.pt\/blog\/?p=1717"},"modified":"2021-10-09T16:34:24","modified_gmt":"2021-10-09T15:34:24","slug":"mido-on-ev3dev","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2021\/mido-on-ev3dev","title":{"rendered":"mido on ev3dev"},"content":{"rendered":"\n<p>Just a quick note: got &#8216;<a href=\"https:\/\/mido.readthedocs.io\/en\/latest\/index.html#\" data-type=\"URL\" data-id=\"https:\/\/mido.readthedocs.io\/en\/latest\/index.html#\">mido<\/a>&#8216; and &#8216;<a href=\"https:\/\/github.com\/SpotlightKid\/python-rtmidi\" data-type=\"URL\" data-id=\"https:\/\/github.com\/SpotlightKid\/python-rtmidi\">python-rtmidi<\/a>&#8216; working together on ev3dev<\/p>\n\n\n\n<p>So now I can use python to access MIDI ports, send and receive MIDI messages in a cleaner way, with no need for &#8216;amidicat&#8217; and pipes. Not sure yet if EV3 has enough resources for my &#8220;clean&#8221; python3 scripts to work as fast as my &#8220;dirt&#8221; pybricks scripts but it&#8217;s worth a try.<\/p>\n\n\n\n<p>It also works with &#8216;multimidicast&#8217; so ipMIDI:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">$ .\/multimidicast &amp;\n$ python3\n\u00bb\u00bb\u00bb import mido\n\u00bb\u00bb\u00bb mido.get_input_name()\n\u00bb\u00bb\u00bb port = mido.open_input('.\/multimidicast:225.0.0.37:21928 128:0')\n\u00bb\u00bb\u00bb for msg in port:\n\u00bb\u00bb\u00bb     print(msg)<\/pre>\n<\/div><\/div>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<p>pressing a few keys on a virtual piano on my laptop routed to a &#8216;qmidinet&#8217; port and this shows up on EV3&#8217;s python shell:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">...\nnote_on channel=0 note=81 velocity=77 time=0\nnote_off channel=0 note=81 velocity=0 time=0\n...<\/pre>\n\n\n\n<p>so a dancing robot (or a music guided robot) is now closer to happen.<\/p>\n\n\n\n<p>&#8216;mido&#8217; also have it&#8217;s own client\/server solution for networking MIDI messages but I still prefer ipMIDI since I  intend to keep all coding on EV3 side.<\/p>\n\n\n\n<p>Details on installation <s>will<\/s> follow <s>soon<\/s>.:<\/p>\n\n\n\n<p>To install &#8216;python-rtmidi&#8217; there are a few dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install pkgconf libasound2-dev<\/pre>\n\n\n\n<p>Then it should be enough (assuming we already have pip3 &#8211; if not, then &#8220;<code>sudo apt install python3-pip<\/code>&#8220;) to<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo pip3 install python-rtmidi --install-option=\"--no-jack\"<\/pre>\n\n\n\n<p>but it isn&#8217;t. After ~20 minutes the EV3 crashes. I resolved the problem by adding a huge swapfile and also stopping &#8216;avahi-daemon&#8217; and &#8216;brickman&#8217; to free up some resources, not sure what are exactly the needed resouces but this works:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo ev3dev-config<\/pre>\n\n\n\n<p>use this tool to disable &#8216;avahi-daemon&#8217; e &#8216;brickman&#8217;<\/p>\n\n\n\n<p>Then create a 128 MB file for swapfile and use it instead of the memory-based swapfile:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo fallocate -l 128M \/swapfile\nsudo chmod 600 \/swapfile\nsudo mkswap \/swapfile\nsudo swapoff -v \/dev\/zram0\nsudo swapon \/swapfile<\/pre>\n\n\n\n<p>Then the installation of &#8216;python-rtmidi&#8217; should work it tooks ~25 minutes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Successfully installed python-rtmidi-1.4.9<\/pre>\n\n\n\n<p>NOTE: I am not sure if a swapfile of 128 MB is necessary (the default swapfile on &#8216;\/dev\/zram0&#8217; has already 96 MB) but I did test doing this with only an huge swapfile (1 GB, without disabling &#8216;avahi-daemon&#8217; nor &#8216;brickman&#8217;)  and also just disabling those 2 services and keeping the default swapfile on &#8216;\/dev\/zram0&#8217; and neither worked.<\/p>\n\n\n\n<p>Then &#8216;mido&#8217; should be easy:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo pip3 install mido<\/pre>\n\n\n\n<p>After 3 or 4 minutes we get:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Successfully installed mido-1.2.10<\/pre>\n\n\n\n<p>Then we should reactive the services (&#8216;sudo ev3dev-config&#8217;) and undo the swapfile modification:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo swapoff -v \/swapfile<br>sudo rm \/swapfile<br>sudo swapon \/dev\/zram0<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just a quick note: got &#8216;mido&#8216; and &#8216;python-rtmidi&#8216; 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 &#8216;amidicat&#8217; and pipes. Not sure yet if EV3 has enough resources for my &#8220;clean&#8221; python3 scripts to work as fast &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2021\/mido-on-ev3dev\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;mido on ev3dev&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[],"series":[],"class_list":["post-1717","post","type-post","status-publish","format-standard","hentry","category-sem-categoria"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-rH","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/comments?post=1717"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1717\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1717"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}