Just thought I would share a quick custom panel that shows how to send OSC from Ross Dashboard to other devices.
If you’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 be used by a wide variety of software for remote control purposes.
To send a message, first a byte array must be constructed. In Dashboard, the easiest way to do this is to use a messageBuilder object and then convert it to a byte array at the end.
function createOSCMessage(cmd, val, varType) { var messageBuilder = ogscript.createMessageBuilder(); var len = cmd.length+1; var pad = (4 - len%4)%4; messageBuilder.writeString(cmd); // put null terminator at end of command string messageBuilder.writeChar(0); // null terminator // pad end of command string with nulls for (var i=0; i<pad; ++i) { messageBuilder.writeChar(0); }
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.
Next, the type (float, int, or string) is determined and the value applied:
// set the 4 bytes that identify the format messageBuilder.writeChar(','); if (varType == 'float') { messageBuilder.writeChar('f'); messageBuilder.writeChar(0); messageBuilder.writeChar(0); messageBuilder.writeFloat(val); } else if (varType == 'int') { messageBuilder.writeChar('i'); messageBuilder.writeChar(0); messageBuilder.writeChar(0); messageBuilder.writeInt(val); } else { messageBuilder.writeChar('s'); messageBuilder.writeChar(0); messageBuilder.writeChar(0); messageBuilder.writeString(val); } return messageBuilder.toByteArray(); }
The resulting byte array is returned to the function that called it.
To send a float:
function sendOSCMessageFloat(ip, port, cmd, val) { ogscript.sendUDPBytes(ip, port, createOSCMessage(cmd, val, 'float')); ogscript.debug('OSC Float Sent'); } var host = '127.0.0.1'; var port = '12321'; var oscCommand = '/command/float'; var oscFloat = 1.1; sendOSCMessageFloat(host, port, oscCommand, oscFloat);
To send an int:
function sendOSCMessageInt(ip, port, cmd, val) { ogscript.sendUDPBytes(ip, port, createOSCMessage(cmd, val, 'int')); ogscript.debug('OSC Int Sent'); } var host = '127.0.0.1'; var port = '12321'; var oscCommand = '/command/int'; var oscInt = 1; sendOSCMessageInt(host, port, oscCommand, oscInt);
To send a string:
function sendOSCMessageString(ip, port, cmd, val) { ogscript.sendUDPBytes(ip, port, createOSCMessage(cmd, val, 'string')); ogscript.debug('OSC String Sent'); } var host = '127.0.0.1'; var port = '12321'; var oscCommand = '/command/string'; var oscString = 'TEST'; sendOSCMessageString(host, port, oscCommand, oscString);
That’s it! Pretty simple using the message builder and byte array.
I’ve made the custom panel available on Github.