robert@285: /* robert@285: ____ _____ _ _ robert@285: | __ )| ____| | / \ robert@285: | _ \| _| | | / _ \ robert@285: | |_) | |___| |___ / ___ \ robert@285: |____/|_____|_____/_/ \_\.io robert@285: robert@285: */ robert@285: robert@285: /** robert@285: \example 5_osc robert@285: robert@285: Open Sound Control robert@285: ------------------ robert@285: robert@285: This example shows an implementation of OSC (Open Sound Control) which was robert@285: developed at UC Berkeley Center for New Music and Audio Technology (CNMAT). robert@285: robert@285: It is designed to be run alongside resources/osc/osc.js robert@285: robert@285: The OSC server port on which to receive is set in `setup()` robert@285: via `oscServer.setup()`. Likewise the OSC client port on which to robert@285: send is set in `oscClient.setup()`. robert@285: robert@285: In `setup()` an OSC message to address `/osc-setup`, it then waits robert@285: 1 second for a reply on `/osc-setup-reply`. robert@285: robert@285: in `render()` the code receives OSC messages, parses them, and sends robert@285: back an acknowledgment. robert@285: robert@285: robert@285: */ robert@285: robert@285: l@271: #include l@271: #include l@271: #include l@271: l@271: OSCServer oscServer; l@271: OSCClient oscClient; l@271: l@271: // this example is designed to be run alongside resources/osc/osc.js l@271: l@271: // parse messages recieved by OSC Server l@271: // msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/ l@271: void parseMessage(oscpkt::Message msg){ l@271: l@271: rt_printf("recieved message to: %s\n", msg.addressPattern().c_str()); l@271: l@271: int intArg; l@271: float floatArg; l@271: if (msg.match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs()){ l@271: rt_printf("recieved int %i and float %f\n", intArg, floatArg); l@271: } l@271: l@271: } l@271: l@271: bool setup(BeagleRTContext *context, void *userData) l@271: { l@271: // setup the OSC server to recieve on port 7562 l@271: oscServer.setup(7562); l@271: // setup the OSC client to send on port 7563 l@271: oscClient.setup(7563); l@271: l@271: // the following code sends an OSC message to address /osc-setup l@271: // then waits 1 second for a reply on /osc-setup-reply l@271: bool handshakeRecieved = false; l@271: oscClient.sendMessageNow(oscClient.newMessage.to("/osc-setup").end()); l@271: oscServer.recieveMessageNow(1000); l@271: while (oscServer.messageWaiting()){ l@271: if (oscServer.popMessage().match("/osc-setup-reply")){ l@271: handshakeRecieved = true; l@271: } l@271: } l@271: l@271: if (handshakeRecieved){ l@271: rt_printf("handshake recieved!\n"); l@271: } else { l@271: rt_printf("timeout!\n"); l@271: } l@271: l@271: return true; l@271: } l@271: l@271: void render(BeagleRTContext *context, void *userData) l@271: { l@271: // recieve OSC messages, parse them, and send back an acknowledgment l@271: while (oscServer.messageWaiting()){ l@271: parseMessage(oscServer.popMessage()); l@271: oscClient.queueMessage(oscClient.newMessage.to("/osc-acknowledge").add(5).add(4.2f).add(std::string("OSC message recieved")).end()); l@271: } l@271: } l@271: l@271: void cleanup(BeagleRTContext *context, void *userData) l@271: { l@271: l@271: }