{"id":555,"date":"2020-04-03T12:42:36","date_gmt":"2020-04-03T12:42:36","guid":{"rendered":"http:\/\/techministry.blog\/?p=555"},"modified":"2020-04-03T12:42:36","modified_gmt":"2020-04-03T12:42:36","slug":"sending-osc-messages-from-ross-dashboard","status":"publish","type":"post","link":"https:\/\/techministry.blog\/?p=555","title":{"rendered":"Sending OSC messages from Ross Dashboard"},"content":{"rendered":"<p>Just thought I would share a quick custom panel that shows how to send OSC from Ross Dashboard to other devices.<\/p>\n<p>If you&#8217;re not familiar with OSC (Open Sound Control), you can read about it <a href=\"http:\/\/opensoundcontrol.org\/introduction-osc\" target=\"_blank\" rel=\"noopener\">here<\/a>. Essentially, it is a protocol used for real-time communication between (typically) media devices, synthesizers, etc. It has grown to be used by a wide variety of software for remote control purposes.<\/p>\n<p>To send a message, first a byte array must be constructed. In Dashboard, the easiest way to do this is to use a <em>messageBuilder<\/em> object and then convert it to a byte array at the end.<\/p>\n<pre>function createOSCMessage(cmd, val, varType)\n   {\n      var messageBuilder = ogscript.createMessageBuilder();\n      var len = cmd.length+1;\n      var pad = (4 - len%4)%4;\n      messageBuilder.writeString(cmd);      \n      \n      \/\/ put null terminator at end of command string\n      messageBuilder.writeChar(0); \/\/ null terminator\n      \n      \/\/ pad end of command string with nulls\n      for (var i=0; i&amp;lt;pad; ++i) \n      {\n         messageBuilder.writeChar(0);\n      }<\/pre>\n<p>This creates the message builder object, inserts the OSC command, and then pads the rest of the bytes with nulls. The command byte must be a multiple of 4, so the pad is calculated.<\/p>\n<p>Next, the type (float, int, or string) is determined and the value applied:<\/p>\n<pre>     \/\/ set the 4 bytes that identify the format\n     messageBuilder.writeChar(',');\n\n     if (varType == 'float')\n     {\n          messageBuilder.writeChar('f');\n          messageBuilder.writeChar(0);\n          messageBuilder.writeChar(0);\n          messageBuilder.writeFloat(val);\n     }\n     else if (varType == 'int')\n     {\n          messageBuilder.writeChar('i');\n          messageBuilder.writeChar(0);\n          messageBuilder.writeChar(0);\n          messageBuilder.writeInt(val);\n     }\n     else\n     {\n          messageBuilder.writeChar('s');\n          messageBuilder.writeChar(0);\n          messageBuilder.writeChar(0);\n          messageBuilder.writeString(val);\n     }\n\n     return messageBuilder.toByteArray();\n}<\/pre>\n<p>The resulting byte array is returned to the function that called it.<\/p>\n<p>To send a float:<\/p>\n<pre>function sendOSCMessageFloat(ip, port, cmd, val)\n{\n     ogscript.sendUDPBytes(ip, port, createOSCMessage(cmd, val, 'float'));\n     ogscript.debug('OSC Float Sent');\n}\n\nvar host = '127.0.0.1';\nvar port = '12321';\nvar oscCommand = '\/command\/float';\nvar oscFloat = 1.1;\nsendOSCMessageFloat(host, port, oscCommand, oscFloat);<\/pre>\n<p>To send an int:<\/p>\n<pre>function sendOSCMessageInt(ip, port, cmd, val)\n{\n     ogscript.sendUDPBytes(ip, port, createOSCMessage(cmd, val, 'int'));\n     ogscript.debug('OSC Int Sent');\n}\n\nvar host = '127.0.0.1';\nvar port = '12321';\nvar oscCommand = '\/command\/int';\nvar oscInt = 1;\nsendOSCMessageInt(host, port, oscCommand, oscInt);<\/pre>\n<p>To send a string:<\/p>\n<pre>function sendOSCMessageString(ip, port, cmd, val)\n{\n     ogscript.sendUDPBytes(ip, port, createOSCMessage(cmd, val, 'string'));\n     ogscript.debug('OSC String Sent');\n}\n\nvar host = '127.0.0.1';\nvar port = '12321';\nvar oscCommand = '\/command\/string';\nvar oscString = 'TEST';\nsendOSCMessageString(host, port, oscCommand, oscString);<\/pre>\n<p>That&#8217;s it! Pretty simple using the message builder and byte array.<\/p>\n<p>I&#8217;ve made the custom panel available on <a href=\"https:\/\/github.com\/josephdadams\/RossDashboardPanels\" target=\"_blank\" rel=\"noopener\">Github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just thought I would share a quick custom panel that shows how to send OSC from Ross Dashboard to other devices. If you&#8217;re not familiar with OSC (Open Sound Control), you can read about it here. Essentially, it is a protocol used for real-time communication between (typically) media devices, synthesizers, etc. It has grown to &hellip; <a href=\"https:\/\/techministry.blog\/?p=555\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Sending OSC messages from Ross Dashboard&#8221;<\/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":[1],"tags":[22,43,51,68],"class_list":["post-555","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-dashboard","tag-osc","tag-programming","tag-technology"],"_links":{"self":[{"href":"https:\/\/techministry.blog\/index.php?rest_route=\/wp\/v2\/posts\/555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techministry.blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techministry.blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techministry.blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techministry.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=555"}],"version-history":[{"count":0,"href":"https:\/\/techministry.blog\/index.php?rest_route=\/wp\/v2\/posts\/555\/revisions"}],"wp:attachment":[{"href":"https:\/\/techministry.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techministry.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techministry.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}