giuliomoro@301: #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: giuliomoro@301: bool setup(BelaContext *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: giuliomoro@301: void render(BelaContext *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: giuliomoro@301: void cleanup(BelaContext *context, void *userData) l@271: { l@271: l@271: }