annotate projects/osc/render.cpp @ 285:5433c83ce04e Doxy prerelease

Doxygen content added to more project render.cpp files and amended in others.
author Robert Jack <robert.h.jack@gmail.com>
date Tue, 17 May 2016 18:46:55 +0100
parents fb9c28a4676b
children
rev   line source
robert@285 1 /*
robert@285 2 ____ _____ _ _
robert@285 3 | __ )| ____| | / \
robert@285 4 | _ \| _| | | / _ \
robert@285 5 | |_) | |___| |___ / ___ \
robert@285 6 |____/|_____|_____/_/ \_\.io
robert@285 7
robert@285 8 */
robert@285 9
robert@285 10 /**
robert@285 11 \example 5_osc
robert@285 12
robert@285 13 Open Sound Control
robert@285 14 ------------------
robert@285 15
robert@285 16 This example shows an implementation of OSC (Open Sound Control) which was
robert@285 17 developed at UC Berkeley Center for New Music and Audio Technology (CNMAT).
robert@285 18
robert@285 19 It is designed to be run alongside resources/osc/osc.js
robert@285 20
robert@285 21 The OSC server port on which to receive is set in `setup()`
robert@285 22 via `oscServer.setup()`. Likewise the OSC client port on which to
robert@285 23 send is set in `oscClient.setup()`.
robert@285 24
robert@285 25 In `setup()` an OSC message to address `/osc-setup`, it then waits
robert@285 26 1 second for a reply on `/osc-setup-reply`.
robert@285 27
robert@285 28 in `render()` the code receives OSC messages, parses them, and sends
robert@285 29 back an acknowledgment.
robert@285 30
robert@285 31
robert@285 32 */
robert@285 33
robert@285 34
l@271 35 #include <BeagleRT.h>
l@271 36 #include <OSCServer.h>
l@271 37 #include <OSCClient.h>
l@271 38
l@271 39 OSCServer oscServer;
l@271 40 OSCClient oscClient;
l@271 41
l@271 42 // this example is designed to be run alongside resources/osc/osc.js
l@271 43
l@271 44 // parse messages recieved by OSC Server
l@271 45 // msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/
l@271 46 void parseMessage(oscpkt::Message msg){
l@271 47
l@271 48 rt_printf("recieved message to: %s\n", msg.addressPattern().c_str());
l@271 49
l@271 50 int intArg;
l@271 51 float floatArg;
l@271 52 if (msg.match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs()){
l@271 53 rt_printf("recieved int %i and float %f\n", intArg, floatArg);
l@271 54 }
l@271 55
l@271 56 }
l@271 57
l@271 58 bool setup(BeagleRTContext *context, void *userData)
l@271 59 {
l@271 60 // setup the OSC server to recieve on port 7562
l@271 61 oscServer.setup(7562);
l@271 62 // setup the OSC client to send on port 7563
l@271 63 oscClient.setup(7563);
l@271 64
l@271 65 // the following code sends an OSC message to address /osc-setup
l@271 66 // then waits 1 second for a reply on /osc-setup-reply
l@271 67 bool handshakeRecieved = false;
l@271 68 oscClient.sendMessageNow(oscClient.newMessage.to("/osc-setup").end());
l@271 69 oscServer.recieveMessageNow(1000);
l@271 70 while (oscServer.messageWaiting()){
l@271 71 if (oscServer.popMessage().match("/osc-setup-reply")){
l@271 72 handshakeRecieved = true;
l@271 73 }
l@271 74 }
l@271 75
l@271 76 if (handshakeRecieved){
l@271 77 rt_printf("handshake recieved!\n");
l@271 78 } else {
l@271 79 rt_printf("timeout!\n");
l@271 80 }
l@271 81
l@271 82 return true;
l@271 83 }
l@271 84
l@271 85 void render(BeagleRTContext *context, void *userData)
l@271 86 {
l@271 87 // recieve OSC messages, parse them, and send back an acknowledgment
l@271 88 while (oscServer.messageWaiting()){
l@271 89 parseMessage(oscServer.popMessage());
l@271 90 oscClient.queueMessage(oscClient.newMessage.to("/osc-acknowledge").add(5).add(4.2f).add(std::string("OSC message recieved")).end());
l@271 91 }
l@271 92 }
l@271 93
l@271 94 void cleanup(BeagleRTContext *context, void *userData)
l@271 95 {
l@271 96
l@271 97 }