robert@464
|
1 /*
|
robert@464
|
2 ____ _____ _ _
|
robert@464
|
3 | __ )| ____| | / \
|
robert@464
|
4 | _ \| _| | | / _ \
|
robert@464
|
5 | |_) | |___| |___ / ___ \
|
robert@464
|
6 |____/|_____|_____/_/ \_\
|
robert@464
|
7
|
robert@464
|
8 The platform for ultra-low latency audio and sensor processing
|
robert@464
|
9
|
robert@464
|
10 http://bela.io
|
robert@464
|
11
|
robert@464
|
12 A project of the Augmented Instruments Laboratory within the
|
robert@464
|
13 Centre for Digital Music at Queen Mary University of London.
|
robert@464
|
14 http://www.eecs.qmul.ac.uk/~andrewm
|
robert@464
|
15
|
robert@464
|
16 (c) 2016 Augmented Instruments Laboratory: Andrew McPherson,
|
robert@464
|
17 Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack,
|
robert@464
|
18 Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved.
|
robert@464
|
19
|
robert@464
|
20 The Bela software is distributed under the GNU Lesser General Public License
|
robert@464
|
21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt
|
robert@464
|
22 */
|
robert@464
|
23
|
robert@464
|
24
|
robert@464
|
25 #include <Bela.h>
|
robert@464
|
26 #include <OSCServer.h>
|
robert@464
|
27 #include <OSCClient.h>
|
robert@464
|
28
|
robert@464
|
29 OSCServer oscServer;
|
robert@464
|
30 OSCClient oscClient;
|
robert@464
|
31
|
robert@464
|
32 // this example is designed to be run alongside resources/osc/osc.js
|
robert@464
|
33
|
robert@494
|
34 // parse messages received by OSC Server
|
robert@464
|
35 // msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/
|
robert@464
|
36 void parseMessage(oscpkt::Message msg){
|
robert@464
|
37
|
robert@494
|
38 rt_printf("received message to: %s\n", msg.addressPattern().c_str());
|
robert@464
|
39
|
robert@464
|
40 int intArg;
|
robert@464
|
41 float floatArg;
|
robert@464
|
42 if (msg.match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs()){
|
robert@494
|
43 rt_printf("received int %i and float %f\n", intArg, floatArg);
|
robert@464
|
44 }
|
robert@464
|
45
|
robert@464
|
46 }
|
robert@464
|
47
|
robert@464
|
48 bool setup(BelaContext *context, void *userData)
|
robert@464
|
49 {
|
robert@494
|
50 // setup the OSC server to receive on port 7562
|
robert@464
|
51 oscServer.setup(7562);
|
robert@464
|
52 // setup the OSC client to send on port 7563
|
robert@464
|
53 oscClient.setup(7563);
|
robert@464
|
54
|
robert@464
|
55 // the following code sends an OSC message to address /osc-setup
|
robert@464
|
56 // then waits 1 second for a reply on /osc-setup-reply
|
robert@494
|
57 bool handshakeReceived = false;
|
robert@464
|
58 oscClient.sendMessageNow(oscClient.newMessage.to("/osc-setup").end());
|
robert@494
|
59 oscServer.receiveMessageNow(1000);
|
robert@464
|
60 while (oscServer.messageWaiting()){
|
robert@464
|
61 if (oscServer.popMessage().match("/osc-setup-reply")){
|
robert@494
|
62 handshakeReceived = true;
|
robert@464
|
63 }
|
robert@464
|
64 }
|
robert@464
|
65
|
robert@494
|
66 if (handshakeReceived){
|
robert@494
|
67 rt_printf("handshake received!\n");
|
robert@464
|
68 } else {
|
robert@464
|
69 rt_printf("timeout!\n");
|
robert@464
|
70 }
|
robert@464
|
71
|
robert@464
|
72 return true;
|
robert@464
|
73 }
|
robert@464
|
74
|
robert@464
|
75 void render(BelaContext *context, void *userData)
|
robert@464
|
76 {
|
robert@494
|
77 // receive OSC messages, parse them, and send back an acknowledgment
|
robert@464
|
78 while (oscServer.messageWaiting()){
|
robert@464
|
79 parseMessage(oscServer.popMessage());
|
robert@494
|
80 oscClient.queueMessage(oscClient.newMessage.to("/osc-acknowledge").add(5).add(4.2f).add(std::string("OSC message received")).end());
|
robert@464
|
81 }
|
robert@464
|
82 }
|
robert@464
|
83
|
robert@464
|
84 void cleanup(BelaContext *context, void *userData)
|
robert@464
|
85 {
|
robert@464
|
86
|
robert@464
|
87 }
|
robert@464
|
88
|
robert@464
|
89
|
robert@464
|
90 /**
|
robert@500
|
91 \example OSC/render.cpp
|
robert@464
|
92
|
robert@464
|
93 Open Sound Control
|
robert@464
|
94 ------------------
|
robert@464
|
95
|
robert@464
|
96 This example shows an implementation of OSC (Open Sound Control) which was
|
robert@464
|
97 developed at UC Berkeley Center for New Music and Audio Technology (CNMAT).
|
robert@464
|
98
|
robert@464
|
99 It is designed to be run alongside resources/osc/osc.js
|
robert@464
|
100
|
robert@464
|
101 The OSC server port on which to receive is set in `setup()`
|
robert@464
|
102 via `oscServer.setup()`. Likewise the OSC client port on which to
|
robert@464
|
103 send is set in `oscClient.setup()`.
|
robert@464
|
104
|
robert@464
|
105 In `setup()` an OSC message to address `/osc-setup`, it then waits
|
robert@464
|
106 1 second for a reply on `/osc-setup-reply`.
|
robert@464
|
107
|
robert@464
|
108 in `render()` the code receives OSC messages, parses them, and sends
|
robert@464
|
109 back an acknowledgment.
|
robert@464
|
110 */
|