Open Sound Control
This example shows an implementation of OSC (Open Sound Control) which was developed at UC Berkeley Center for New Music and Audio Technology (CNMAT).
It is designed to be run alongside resources/osc/osc.js. For the example to work, run in a terminal on the board ``` node /root/Bela/resources/osc/osc.js ```
In setup()
an OSC message to address /osc-setup
, it then waits 1 second for a reply on /osc-setup-reply
.
After that, OSC communication takes place in the on_receive() callback, which is called every time a new message comes in.
#include <libraries/OscSender/OscSender.h>
#include <libraries/OscReceiver/OscReceiver.h>
int localPort = 7562;
int remotePort = 7563;
const char* remoteIp = "127.0.0.1";
bool handshakeReceived;
void on_receive(oscpkt::Message* msg, const char* addr, void* arg)
{
printf("From %s\n", addr);
if(msg->match("/osc-setup-reply"))
handshakeReceived = true;
else if(msg->match("/osc-test")){
int intArg;
float floatArg;
msg->match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs();
printf("received a message with int %i and float %f\n", intArg, floatArg);
}
}
{
oscReceiver.
setup(localPort, on_receive);
oscSender.
setup(remotePort, remoteIp);
int count = 0;
int timeoutCount = 10;
printf("Waiting for handshake ....\n");
while(!handshakeReceived && ++count != timeoutCount)
{
usleep(100000);
}
if (handshakeReceived) {
printf("handshake received!\n");
} else {
printf("timeout! : did you start the node server? `node /root/Bela/resources/osc/osc.js\n");
return false;
}
return true;
}
{
}
{
}