{"id":861,"date":"2021-10-27T09:02:48","date_gmt":"2021-10-27T09:02:48","guid":{"rendered":"https:\/\/es-andreabianchini.it\/andrewsblog\/?p=861"},"modified":"2021-10-27T09:02:49","modified_gmt":"2021-10-27T09:02:49","slug":"lettura-del-flusso-midi-di-uno-strumento","status":"publish","type":"post","link":"https:\/\/es-andreabianchini.it\/andrewsblog\/?p=861","title":{"rendered":"Lettura del flusso MIDI di uno strumento"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code># mido_test.py\n#\n# Questo programma dimostra l'utilizzo della libreria MIDO \n# per la gestione dei dispositivi MIDI.\n# In particolare, questo programma cattura e stampa il flusso midi\n# prodotto da una tastiera elettronica.\n# Dopo aver selezionato il dispositivo tra quelli disponibili,\n# viene effettuato un ciclo di lettura continua sino all'interruzione\n# tramite tasto CTRL-C.\n#\n# by Andrea Bianchini (2021)\n#\n\n\nimport mido\n\no=mido.get_output_names()\n\nfor i in range(len(o)):\n    print(str(i)+\"-\"+o&#91;i])\n\nprint()\nk=int(input(\"Seleziona il numero corrispondente al dispositivo di interesse:\"))\nprint()\n\nport = mido.open_input(o&#91;k])\n\ntry:\n    while True:\n        for msg in port.iter_pending():\n            if  msg.type!=\"clock\":\n                print(msg)\nexcept KeyboardInterrupt:\n    print(\"Interrupted by user\")\n\nport.close()\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Esempio:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0-Midi Through:Midi Through Port-0 14:0\n1-Digital Keyboard:Digital Keyboard MIDI 1 20:0\n2-Midi Through:Midi Through Port-0 14:0\n3-Digital Keyboard:Digital Keyboard MIDI 1 20:0\n\nSeleziona il numero corrispondente al dispositivo di interesse:1\n\nstart time=0\ncontrol_change channel=3 control=120 value=0 time=0\ncontrol_change channel=7 control=120 value=0 time=0\ncontrol_change channel=5 control=120 value=0 time=0\ncontrol_change channel=3 control=7 value=122 time=0\nnote_on channel=3 note=67 velocity=40 time=0\nnote_on channel=3 note=48 velocity=39 time=0\nnote_on channel=3 note=69 velocity=48 time=0\nnote_off channel=3 note=67 velocity=0 time=0\nnote_on channel=3 note=59 velocity=45 time=0\nnote_off channel=3 note=59 velocity=0 time=0\nnote_on channel=3 note=55 velocity=42 time=0\nnote_off channel=3 note=69 velocity=0 time=0\nnote_off channel=3 note=48 velocity=0 time=0\nnote_on channel=3 note=67 velocity=33 time=0\nnote_off channel=3 note=67 velocity=0 time=0\nnote_off channel=3 note=55 velocity=0 time=0\nnote_on channel=3 note=65 velocity=34 time=0\nnote_on channel=3 note=53 velocity=39 time=0\nnote_on channel=3 note=63 velocity=35 time=0\nnote_off channel=3 note=65 velocity=0 time=0\nnote_on channel=3 note=52 velocity=50 time=0\nnote_off channel=3 note=53 velocity=0 time=0\nnote_off channel=3 note=63 velocity=0 time=0\nnote_on channel=3 note=62 velocity=42 time=0\nnote_off channel=3 note=52 velocity=0 time=0\nnote_off channel=3 note=62 velocity=0 time=0\nnote_on channel=3 note=53 velocity=41 time=0\nnote_on channel=3 note=64 velocity=49 time=0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Esempio:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,7],"tags":[],"class_list":["post-861","post","type-post","status-publish","format-standard","hentry","category-python","category-stem"],"_links":{"self":[{"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=\/wp\/v2\/posts\/861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=861"}],"version-history":[{"count":1,"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=\/wp\/v2\/posts\/861\/revisions"}],"predecessor-version":[{"id":862,"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=\/wp\/v2\/posts\/861\/revisions\/862"}],"wp:attachment":[{"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/es-andreabianchini.it\/andrewsblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}