{"id":77,"date":"2021-04-16T11:39:25","date_gmt":"2021-04-16T09:39:25","guid":{"rendered":"https:\/\/radix-studio.fr\/blog\/?p=77"},"modified":"2023-04-05T13:10:44","modified_gmt":"2023-04-05T11:10:44","slug":"midirouter-by-example","status":"publish","type":"post","link":"https:\/\/radix-studio.fr\/blog\/2021\/04\/16\/midirouter-by-example\/","title":{"rendered":"MIDIRouter by example"},"content":{"rendered":"\n<p>This article provides some detailed example and associated configuration file for MIDIRouter (<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/NothNoth\/MIDIRouter\" target=\"_blank\">https:\/\/github.com\/NothNoth\/MIDIRouter<\/a>).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Simple forward<\/h2>\n\n\n\n<p>Let&rsquo;s start with a very simple use case: \u00ab\u00a0I want to forward all messages received on my input MIDI interface to my output MIDI interface\u00a0\u00bb.<\/p>\n\n\n\n<p>This may typically happen when you have a MIDI Usb keyboard connected to your audio interface and you want to send everything to you freshly acquired analog synthesizer connected to your MIDI output.<\/p>\n\n\n\n<p>Our configuration file will first specify your MIDI input and output devices.<\/p>\n\n\n\n<p>Simply run MIDIRouter with no arguments to list available devices:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage: .\/midirouter &lt;config file&gt;\nMIDI inputs:\n   P\u00e9riph\u00e9rique MIDI USB\n   Korg\n   MOOG\n   Faderfox EC4\n   Port 1\n   Port 2\n   Port 3\n   Port 4\n   Port 5\n   Port 6\n   Port 7\n   Port 8\nMIDI outputs:\n   P\u00e9riph\u00e9rique MIDI USB\n   Korg\n   MOOG\n   Faderfox EC4\n   Port 1\n   Port 2\n   Port 3\n   Port 4\n   Port 5\n   Port 6\n   Port 7\n   Port 8\n<\/code><\/pre>\n\n\n\n<p>Let&rsquo;s say I want to route everything from \u00ab\u00a0Korg\u00a0\u00bb to \u00ab\u00a0MOOG\u00a0\u00bb.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"SourceDevice\": \"Korg\",\n    \"DestinationDevice\": \"MOOG\",\n    \"DefaultPassthrough\": true,\n    \"Verbose\": true\n}<\/code><\/pre>\n\n\n\n<p>The \u00ab\u00a0DefaultPassthrough\u00a0\u00bb simply tells the MIDIRouter to forward all messages not matching any other rule. Since we don&rsquo;t have any other rule set, this default behaviour will match all captured messages on the input interface.<\/p>\n\n\n\n<p>The \u00ab\u00a0Verbose\u00a0\u00bb option is useful when setting everything up: it will show a message everytime a MIDI event is received (you can switch it to &lsquo;false&rsquo; once everything works fine).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Note On\/off forward only<\/h2>\n\n\n\n<p>On our previous example we&rsquo;ve used the DefaultPassthrough feature to allow a complete forward of all messages from the input MIDI device to the output MIDI device.<\/p>\n\n\n\n<p>Now we may not want to send everything to our vintage Analog Synth since it only supports NoteOn and NoteOff MIDI mesages. In order to do that, we will use what is the main feature of MIDIRouter: \u00ab\u00a0rules\u00a0\u00bb.<\/p>\n\n\n\n<p>A \u00ab\u00a0Rule\u00a0\u00bb is built using three main sections:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A filter which describes what kind of MIDI message to look for on the input MIDI interface<\/li><li>A transformation which optionally defines how you want to change the extracted value<\/li><li>A generator which describes what kind of MIDI message to replay on the output MIDI interface<\/li><\/ul>\n\n\n\n<p>Our complete forward scenario is quite simple:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Filter: we want to match any Note On or Note Off message whatever the MIDI channel, value or velocity<\/li><li>Transform: we don&rsquo;t want to transform anything<\/li><li>Generator: we want to replay using the same type of MIDI message (Note on, note Off), same MIDI channel, same note, same Velocity<\/li><\/ul>\n\n\n\n<p>We will here need two rules, one for the Note On events and one for the Note Off events.<\/p>\n\n\n\n<p>Let&rsquo;s start with Note On forward.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"SourceDevice\": \"Korg\",\n    \"DestinationDevice\": \"MOOG\",\n    \"DefaultPassthrough\": false,\n    \"Verbose\": true,\n    \"Rules\": &#91;\n        {\n            \"Name\": \"Raw forward of any Note On\",\n            \"Filter\": {\n                \"Name\": \"Note On in (I can write anything here)\",\n                \"MsgType\": \"Note On\",\n                \"Channel\": \"*\",\n                \"Settings\": {\n                    \"Note\": \"*\",\n                    \"Velocity\": \"*\"\n                }\n            },\n            \"Transform\": {\n                \"Mode\": \"None\"\n            },\n            \"Generator\": {\n                \"Name\": \"Note On out\",\n                \"MsgType\":\"Note On\",\n                \"Channel\": \"*\",\n                \"Settings\": {\n                    \"Note\": \"*\",\n                    \"Velocity\": \"*\"\n                }\n            }\n        }\n    ]\n}<\/code><\/pre>\n\n\n\n<p>In the first part of this configuration file, we have the same section defining the input and output. Note that we&rsquo;ve disabled the Defaultpassthrough option. <\/p>\n\n\n\n<p>Then we have the <strong>\u00ab\u00a0Rules\u00a0\u00bb<\/strong> array which &#8211; for now &#8211; only contains one rule for our \u00ab\u00a0Note On\u00a0\u00bb events. The \u00ab\u00a0Name\u00a0\u00bb fields can be used to put any comments to be used for display only.<\/p>\n\n\n\n<p>The <strong>\u00ab\u00a0Filter\u00a0\u00bb<\/strong> is built using:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>MsgType: the type of midi message to look for (among \u00ab\u00a0Note On\u00a0\u00bb, \u00ab\u00a0Note Off\u00a0\u00bb, \u00ab\u00a0Aftertouch\u00a0\u00bb, \u00ab\u00a0Control Change\u00a0\u00bb, \u00ab\u00a0Program Change\u00a0\u00bb, \u00ab\u00a0Channel Pressure\u00a0\u00bb, \u00ab\u00a0Pitch Wheel\u00a0\u00bb). Here we set it to \u00ab\u00a0Note On\u00a0\u00bb<\/li><li>Channel: the MIDI channel to look for (1 to 16). Here we want to match any channel and use &lsquo;*&rsquo;.<\/li><li>Now comes the \u00ab\u00a0Note On\u00a0\u00bb specific settings which are \u00ab\u00a0Note\u00a0\u00bb (the note value) and \u00ab\u00a0Velocity\u00a0\u00bb. Since we want to match any note or velocity, we use &lsquo;*&rsquo; again.<\/li><\/ul>\n\n\n\n<p>Then comes the <strong>\u00ab\u00a0Transform\u00a0\u00bb<\/strong> entry which would technically allow us to transform a note to another one. Here we just want to replay the MIDI message as it, so we use \u00ab\u00a0None\u00a0\u00bb.<\/p>\n\n\n\n<p>The <strong>\u00ab\u00a0Generator\u00a0\u00bb<\/strong> section describes what kind of MIDI message we want to generate when a MIDI message matching our filter is captured. These settings are quite similar to the filter settings.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>MsgType: the type of midi message to generate (among \u00ab\u00a0Note On\u00a0\u00bb, \u00ab\u00a0Note Off\u00a0\u00bb, \u00ab\u00a0Aftertouch\u00a0\u00bb, \u00ab\u00a0Control Change\u00a0\u00bb, \u00ab\u00a0Program Change\u00a0\u00bb, \u00ab\u00a0Channel Pressure\u00a0\u00bb, \u00ab\u00a0Pitch Wheel\u00a0\u00bb). So here we set it to \u00ab\u00a0Note On\u00a0\u00bb<\/li><li>Channel: the MIDI channel to set (1 to 16). Here we want reuse the same MIDI channel found on the captured Note on, we set it to \u00ab\u00a0*\u00a0\u00bb.<\/li><li>Now comes the \u00ab\u00a0Note On\u00a0\u00bb specific settings which are \u00ab\u00a0Note\u00a0\u00bb (the note value) and \u00ab\u00a0Velocity\u00a0\u00bb. Since we want to replay the same note and velocity, we use &lsquo;*&rsquo; again.<\/li><\/ul>\n\n\n\n<p>And that&rsquo;s it: the rule will match all Note on events and replay them to the output interface using the exact same settings (MIDI channel, note, velocity).<\/p>\n\n\n\n<p>Because we want to send also Note Off messages, we add another rule with very similar settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"SourceDevice\": \"Faderfox EC4\",\n    \"DestinationDevice\": \"P\u00e9riph\u00e9rique MIDI USB\",\n    \"DefaultPassthrough\": false,\n    \"Verbose\": false,\n    \"Rules\": &#91;\n        {\n            \"Name\": \"Match any NoteOn\",\n            \"Filter\": {\n                \"Name\": \"Note On in\",\n                \"MsgType\": \"Note On\",\n                \"Channel\": \"*\",\n                \"Settings\": {\n                    \"Note\": \"*\",\n                    \"Velocity\": \"*\"\n                }\n            },\n            \"Transform\": {\n                \"Mode\": \"None\"\n            },\n            \"Generator\": {\n                \"Name\": \"Note On out\",\n                \"MsgType\":\"Note On\",\n                \"Channel\": \"*\",\n                \"Settings\": {\n                    \"Note\": \"*\",\n                    \"Velocity\": \"*\"\n                }\n            }\n        },\n        {\n            \"Name\": \"Match any NoteOff\",\n            \"Filter\": {\n                \"Name\": \"Note Off in\",\n                \"MsgType\": \"Note Off\",\n                \"Channel\": \"*\",\n                \"Settings\": {\n                    \"Note\": \"*\",\n                    \"Velocity\": \"*\"\n                }\n            },\n            \"Transform\": {\n                \"Mode\": \"None\"\n            },\n            \"Generator\": {\n                \"Name\": \"Note Off out\",\n                \"MsgType\":\"Note Off\",\n                \"Channel\": \"*\",\n                \"Settings\": {\n                    \"Note\": \"*\",\n                    \"Velocity\": \"*\"\n                }\n            }\n        }\n    ]\n}<\/code><\/pre>\n\n\n\n<p>On the next article, we will see how we can send Pitch Wheel events captured on a given MIDI channel to another MIDI channel and transform them to Aftertouch events:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-radix-studio-blog wp-block-embed-radix-studio-blog\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"EwCNKLtdTp\"><a href=\"https:\/\/radix-studio.fr\/blog\/2021\/04\/16\/midirouter-by-example-part2\/\">MIDIRouter by example &#8211; part2<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"\u00ab\u00a0MIDIRouter by example &#8211; part2\u00a0\u00bb &#8212; Radix Studio - Blog\" src=\"https:\/\/radix-studio.fr\/blog\/2021\/04\/16\/midirouter-by-example-part2\/embed\/#?secret=bXH4NY19AY#?secret=EwCNKLtdTp\" data-secret=\"EwCNKLtdTp\" width=\"525\" height=\"296\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This article provides some detailed example and associated configuration file for MIDIRouter (https:\/\/github.com\/NothNoth\/MIDIRouter). Simple forward Let&rsquo;s start with a very simple use case: \u00ab\u00a0I want to forward all messages received on my input MIDI interface to my output MIDI interface\u00a0\u00bb. This may typically happen when you have a MIDI Usb keyboard connected to your audio &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/radix-studio.fr\/blog\/2021\/04\/16\/midirouter-by-example\/\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;MIDIRouter by example&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[5],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-electronics","tag-midirouter"],"_links":{"self":[{"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":5,"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":88,"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions\/88"}],"wp:attachment":[{"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/radix-studio.fr\/blog\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}