annotate examples/osc/render.cpp @ 304:d2b7df6b355b prerelease

Added Makefile support for runscreen, runscreenfg, run, runfg
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 27 May 2016 17:49:05 +0100
parents e4392164b458
children db2fe4e1b88e
rev   line source
giuliomoro@301 1 #include <Bela.h>
l@271 2 #include <OSCServer.h>
l@271 3 #include <OSCClient.h>
l@271 4
l@271 5 OSCServer oscServer;
l@271 6 OSCClient oscClient;
l@271 7
l@271 8 // this example is designed to be run alongside resources/osc/osc.js
l@271 9
l@271 10 // parse messages recieved by OSC Server
l@271 11 // msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/
l@271 12 void parseMessage(oscpkt::Message msg){
l@271 13
l@271 14 rt_printf("recieved message to: %s\n", msg.addressPattern().c_str());
l@271 15
l@271 16 int intArg;
l@271 17 float floatArg;
l@271 18 if (msg.match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs()){
l@271 19 rt_printf("recieved int %i and float %f\n", intArg, floatArg);
l@271 20 }
l@271 21
l@271 22 }
l@271 23
giuliomoro@301 24 bool setup(BelaContext *context, void *userData)
l@271 25 {
l@271 26 // setup the OSC server to recieve on port 7562
l@271 27 oscServer.setup(7562);
l@271 28 // setup the OSC client to send on port 7563
l@271 29 oscClient.setup(7563);
l@271 30
l@271 31 // the following code sends an OSC message to address /osc-setup
l@271 32 // then waits 1 second for a reply on /osc-setup-reply
l@271 33 bool handshakeRecieved = false;
l@271 34 oscClient.sendMessageNow(oscClient.newMessage.to("/osc-setup").end());
l@271 35 oscServer.recieveMessageNow(1000);
l@271 36 while (oscServer.messageWaiting()){
l@271 37 if (oscServer.popMessage().match("/osc-setup-reply")){
l@271 38 handshakeRecieved = true;
l@271 39 }
l@271 40 }
l@271 41
l@271 42 if (handshakeRecieved){
l@271 43 rt_printf("handshake recieved!\n");
l@271 44 } else {
l@271 45 rt_printf("timeout!\n");
l@271 46 }
l@271 47
l@271 48 return true;
l@271 49 }
l@271 50
giuliomoro@301 51 void render(BelaContext *context, void *userData)
l@271 52 {
l@271 53 // recieve OSC messages, parse them, and send back an acknowledgment
l@271 54 while (oscServer.messageWaiting()){
l@271 55 parseMessage(oscServer.popMessage());
l@271 56 oscClient.queueMessage(oscClient.newMessage.to("/osc-acknowledge").add(5).add(4.2f).add(std::string("OSC message recieved")).end());
l@271 57 }
l@271 58 }
l@271 59
giuliomoro@301 60 void cleanup(BelaContext *context, void *userData)
l@271 61 {
l@271 62
l@271 63 }