{"id":4269,"date":"2021-12-25T05:53:53","date_gmt":"2021-12-25T04:53:53","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=4269"},"modified":"2024-08-18T05:16:54","modified_gmt":"2024-08-18T03:16:54","slug":"microcontrollers-and-midi","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/","title":{"rendered":"Microcontrollers and Apple MIDI"},"content":{"rendered":"<p>My <a href=\"https:\/\/github.com\/pschatzmann\/arduino-midi\">Arduino MIDI Library<\/a> is using Arduino Streams as a basic design feature and therefore it supports Bluetooth, TCP\/IP and UDP.<\/p>\n<p>I am usually programming on an <strong>old Macbook<\/strong>, so I was wondering if I can extend my library to support <a href=\"https:\/\/en.wikipedia.org\/wiki\/RTP-MIDI\">Apple MIDI<\/a> as well.<\/p>\n<p>After some research I found that Apple MIDI communicates on 2 UDP ports: one for the session management and the other for the midi data. I wanted to avoid me having to implement the protocol myself and found the <strong>C implementation from Thorsten Klose<\/strong> which provides a quite nice abstraction layer: All I needed to do was to implemeent my C++ class which provides the necessary callback methods and integrates into my MIDI parser.<\/p>\n<h3>Arduino Sketch<\/h3>\n<p>Here is the example sketch which uses the new functionality:<\/p>\n<pre><code>#include &lt;WiFi.h&gt;\n#include \"Midi.h\"\n\nMidiCallbackAction action;\nAppleMidiServer apple(&amp;action);\n\nconst char *SSID = \"your ssid\";\nconst char *PWD = \"your password\";\n\nvoid onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) {\n  Serial.print(\"onNoteOn: \");\n  Serial.println(note);\n}\n\nvoid onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity) {\n  Serial.print(\"onNoteOff: \");\n  Serial.println(note);\n}\n\nvoid setupWIFI() {\n  Serial.begin(119200);\n  MidiLogLevel = MidiInfo;\n\n  WiFi.begin(SSID, PWD);\n  while (WiFi.status() != WL_CONNECTED) {\n    Serial.print('.');\n    delay(1000);\n  }\n\n  Serial.print(\"Connected to IP address: \");\n  Serial.println(WiFi.localIP());\n}\n\nvoid setup() {\n  action.setCallbacks(onNoteOn, onNoteOff);\n  setupWIFI();\n  apple.begin(5004);\n}\n\nvoid loop() {\n  if (!apple.loop()){\n    delay(10);\n  }\n}\n\n<\/code><\/pre>\n<p>As you can see, by using the <a href=\"https:\/\/pschatzmann.github.io\/arduino-midi\/html\/classmidi_1_1_apple_midi_server.html\">AppleMidiServer class<\/a> we use the same concepts that we already know from in all other examples and because this is a server class, we can not only receive MIDI messages, but also produce them.<\/p>\n<h3>Dependencies<\/h3>\n<ul>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-midi\">arduino-midi<\/a><\/li>\n<\/ul>\n<h3>OS\/X MIDI Setup<\/h3>\n<ul>\n<li>Connect your MIDI keyboard to the computer. <\/li>\n<li>Open the Audio Midi Setup tool. <\/li>\n<li>Goto Window Show MIDI Studio.<\/li>\n<li>Double click on Network<\/li>\n<li>The entry &#8216;AppleMidi&#8217; should be available in the Directory<\/li>\n<li>Select it and click on the <Connect> button<\/li>\n<li>In the Live Routings select your Keyboard on the line with -><\/li>\n<\/ul>\n<p>If you hit the keys, you should see the corresponding entries in the Arduino Serial Monitor<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My Arduino MIDI Library is using Arduino Streams as a basic design feature and therefore it supports Bluetooth, TCP\/IP and UDP. I am usually programming on an old Macbook, so I was wondering if I can extend my library to support Apple MIDI as well. After some research I found [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2000,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20,22],"tags":[33],"class_list":["post-4269","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound","tag-midi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Microcontrollers and Apple MIDI - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Microcontrollers and Apple MIDI - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"My Arduino MIDI Library is using Arduino Streams as a basic design feature and therefore it supports Bluetooth, TCP\/IP and UDP. I am usually programming on an old Macbook, so I was wondering if I can extend my library to support Apple MIDI as well. After some research I found [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-25T04:53:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-18T03:16:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2020\/09\/midi.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"582\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Microcontrollers and Apple MIDI\",\"datePublished\":\"2021-12-25T04:53:53+00:00\",\"dateModified\":\"2024-08-18T03:16:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/\"},\"wordCount\":248,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/midi.png\",\"keywords\":[\"MIDI\"],\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/\",\"name\":\"Microcontrollers and Apple MIDI - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/midi.png\",\"datePublished\":\"2021-12-25T04:53:53+00:00\",\"dateModified\":\"2024-08-18T03:16:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/midi.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/midi.png\",\"width\":1280,\"height\":582},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/12\\\/25\\\/microcontrollers-and-midi\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontrollers and Apple MIDI\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Microcontrollers and Apple MIDI - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/","og_locale":"en_US","og_type":"article","og_title":"Microcontrollers and Apple MIDI - Phil Schatzmann","og_description":"My Arduino MIDI Library is using Arduino Streams as a basic design feature and therefore it supports Bluetooth, TCP\/IP and UDP. I am usually programming on an old Macbook, so I was wondering if I can extend my library to support Apple MIDI as well. After some research I found [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/","og_site_name":"Phil Schatzmann","article_published_time":"2021-12-25T04:53:53+00:00","article_modified_time":"2024-08-18T03:16:54+00:00","og_image":[{"width":1280,"height":582,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2020\/09\/midi.png","type":"image\/png"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Microcontrollers and Apple MIDI","datePublished":"2021-12-25T04:53:53+00:00","dateModified":"2024-08-18T03:16:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/"},"wordCount":248,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2020\/09\/midi.png","keywords":["MIDI"],"articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/","url":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/","name":"Microcontrollers and Apple MIDI - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2020\/09\/midi.png","datePublished":"2021-12-25T04:53:53+00:00","dateModified":"2024-08-18T03:16:54+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2020\/09\/midi.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2020\/09\/midi.png","width":1280,"height":582},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/12\/25\/microcontrollers-and-midi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Microcontrollers and Apple MIDI"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=4269"}],"version-history":[{"count":13,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4269\/revisions"}],"predecessor-version":[{"id":6331,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4269\/revisions\/6331"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/2000"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=4269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=4269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=4269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}