comparison examples/05-Communication/OSC/render.cpp @ 494:5779ed0562ac prerelease

Typo, OSC example.
author Robert Jack <robert.h.jack@gmail.com>
date Tue, 21 Jun 2016 19:33:17 +0100
parents 8fcfbfb32aa0
children b935f890e512
comparison
equal deleted inserted replaced
493:a23d74e2f6cb 494:5779ed0562ac
29 OSCServer oscServer; 29 OSCServer oscServer;
30 OSCClient oscClient; 30 OSCClient oscClient;
31 31
32 // this example is designed to be run alongside resources/osc/osc.js 32 // this example is designed to be run alongside resources/osc/osc.js
33 33
34 // parse messages recieved by OSC Server 34 // parse messages received by OSC Server
35 // msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/ 35 // msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/
36 void parseMessage(oscpkt::Message msg){ 36 void parseMessage(oscpkt::Message msg){
37 37
38 rt_printf("recieved message to: %s\n", msg.addressPattern().c_str()); 38 rt_printf("received message to: %s\n", msg.addressPattern().c_str());
39 39
40 int intArg; 40 int intArg;
41 float floatArg; 41 float floatArg;
42 if (msg.match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs()){ 42 if (msg.match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs()){
43 rt_printf("recieved int %i and float %f\n", intArg, floatArg); 43 rt_printf("received int %i and float %f\n", intArg, floatArg);
44 } 44 }
45 45
46 } 46 }
47 47
48 bool setup(BelaContext *context, void *userData) 48 bool setup(BelaContext *context, void *userData)
49 { 49 {
50 // setup the OSC server to recieve on port 7562 50 // setup the OSC server to receive on port 7562
51 oscServer.setup(7562); 51 oscServer.setup(7562);
52 // setup the OSC client to send on port 7563 52 // setup the OSC client to send on port 7563
53 oscClient.setup(7563); 53 oscClient.setup(7563);
54 54
55 // the following code sends an OSC message to address /osc-setup 55 // the following code sends an OSC message to address /osc-setup
56 // then waits 1 second for a reply on /osc-setup-reply 56 // then waits 1 second for a reply on /osc-setup-reply
57 bool handshakeRecieved = false; 57 bool handshakeReceived = false;
58 oscClient.sendMessageNow(oscClient.newMessage.to("/osc-setup").end()); 58 oscClient.sendMessageNow(oscClient.newMessage.to("/osc-setup").end());
59 oscServer.recieveMessageNow(1000); 59 oscServer.receiveMessageNow(1000);
60 while (oscServer.messageWaiting()){ 60 while (oscServer.messageWaiting()){
61 if (oscServer.popMessage().match("/osc-setup-reply")){ 61 if (oscServer.popMessage().match("/osc-setup-reply")){
62 handshakeRecieved = true; 62 handshakeReceived = true;
63 } 63 }
64 } 64 }
65 65
66 if (handshakeRecieved){ 66 if (handshakeReceived){
67 rt_printf("handshake recieved!\n"); 67 rt_printf("handshake received!\n");
68 } else { 68 } else {
69 rt_printf("timeout!\n"); 69 rt_printf("timeout!\n");
70 } 70 }
71 71
72 return true; 72 return true;
73 } 73 }
74 74
75 void render(BelaContext *context, void *userData) 75 void render(BelaContext *context, void *userData)
76 { 76 {
77 // recieve OSC messages, parse them, and send back an acknowledgment 77 // receive OSC messages, parse them, and send back an acknowledgment
78 while (oscServer.messageWaiting()){ 78 while (oscServer.messageWaiting()){
79 parseMessage(oscServer.popMessage()); 79 parseMessage(oscServer.popMessage());
80 oscClient.queueMessage(oscClient.newMessage.to("/osc-acknowledge").add(5).add(4.2f).add(std::string("OSC message recieved")).end()); 80 oscClient.queueMessage(oscClient.newMessage.to("/osc-acknowledge").add(5).add(4.2f).add(std::string("OSC message received")).end());
81 } 81 }
82 } 82 }
83 83
84 void cleanup(BelaContext *context, void *userData) 84 void cleanup(BelaContext *context, void *userData)
85 { 85 {