{"id":1629,"date":"2020-04-16T10:25:04","date_gmt":"2020-04-16T09:25:04","guid":{"rendered":"https:\/\/ofalcao.pt\/blog\/?p=1629"},"modified":"2020-04-16T10:25:05","modified_gmt":"2020-04-16T09:25:05","slug":"amidicat","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2020\/amidicat","title":{"rendered":"aMIDIcat"},"content":{"rendered":"<div class=\"seriesmeta\">This post is part 2 of 6 of \u00a0<a href=\"https:\/\/ofalcao.pt\/blog\/series\/lego-ipmidi\" class=\"series-359\" title=\"LEGO ipMIDI\">LEGO ipMIDI<\/a><\/div>\n<p>Using a system call to &#8216;amidi&#8217; seemed a bit slow. While searching the Net I found that &#8216;mido&#8217; also supports &#8216;amidi&#8217; as a backend but the documentation clearly states that it is very heavy to make system calls each time.<\/p>\n\n\n\n<p>So I kept searching. Maybe opening &#8216;amidi&#8217; just once and redirecting commands through a pipe? No, it doesn&#8217;t like allow.<\/p>\n\n\n\n<p>But&#8230; found <a href=\"http:\/\/krellan.com\/amidicat\/\">aMIDIcat<\/a>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>It hooks up standard input, and standard output, to the ALSA sequencer.<br>This makes it easy to pipe data around.<\/p><\/blockquote>\n\n\n\n<p>Yes, yes! Ubuntu says &#8216;amidicat&#8217; is included in &#8216;sndio-tools&#8217; but after installing this package in ev3dev the command was not found so I download the source code and compiled it (very short, very fast, just use &#8216;make&#8217;).<\/p>\n\n\n\n<p>And it works!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"903C7F\" | .\/amidicat --port 128:0 --hex<\/pre>\n\n\n\n<p>Even better: it works directly to &#8216;multimidicast&#8217; so no need to load the &#8216;snd-virmidi&#8217; kernel module and connect it to &#8216;multimidicast&#8217;.<\/p>\n\n\n\n<p>So I create a pipe:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkfifo midipipe<\/pre>\n\n\n\n<p>and in my python\/micropython script I just open the pipe and write to it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pipe = open(\".\/midipipe\", \"w\")<br>pipe.write(\"903C7F\")<\/pre>\n\n\n\n<p>so no need to use &#8216;os.system&#8217; at all!<\/p>\n\n\n\n<p>The gain was huge: I can now send several notes in a row and they sound like they were played at the same time (a chord); with system calls to &#8216;amidi&#8217; the delay between each system call was clearly noticeable.<\/p>\n\n\n\n<p>I still have the problem that sooner or later a note stucks and I need to send a &#8216;all notes off&#8217; (&#8220;B0 7B 00&#8221;) MIDI command. But for now I can live with it (of course, my wife -the musician that will use the LEGO ipMIDI instrument &#8211; will not).<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"seriesmeta\">This post is part 2  of 6 of \u00a0<a href=\"https:\/\/ofalcao.pt\/blog\/series\/lego-ipmidi\" class=\"series-359\" title=\"LEGO ipMIDI\">LEGO ipMIDI<\/a><\/div><p>Using a system call to &#8216;amidi&#8217; seemed a bit slow. While searching the Net I found that &#8216;mido&#8217; also supports &#8216;amidi&#8217; as a backend but the documentation clearly states that it is very heavy to make system calls each time. So I kept searching. Maybe opening &#8216;amidi&#8217; just once and redirecting commands through a pipe? &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2020\/amidicat\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;aMIDIcat&#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":[359],"class_list":["post-1629","post","type-post","status-publish","format-standard","hentry","category-sem-categoria","series-lego-ipmidi"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s2Mhyv-amidicat","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1629","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=1629"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1629\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1629"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}