robert@464: /* robert@464: ____ _____ _ _ robert@464: | __ )| ____| | / \ robert@464: | _ \| _| | | / _ \ robert@464: | |_) | |___| |___ / ___ \ robert@464: |____/|_____|_____/_/ \_\ robert@464: robert@464: The platform for ultra-low latency audio and sensor processing robert@464: robert@464: http://bela.io robert@464: robert@464: A project of the Augmented Instruments Laboratory within the robert@464: Centre for Digital Music at Queen Mary University of London. robert@464: http://www.eecs.qmul.ac.uk/~andrewm robert@464: robert@464: (c) 2016 Augmented Instruments Laboratory: Andrew McPherson, robert@464: Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack, robert@464: Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved. robert@464: robert@464: The Bela software is distributed under the GNU Lesser General Public License robert@464: (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt robert@464: */ robert@464: robert@464: robert@464: #include robert@464: #include robert@464: #include robert@464: robert@464: OSCServer oscServer; robert@464: OSCClient oscClient; robert@464: robert@464: // this example is designed to be run alongside resources/osc/osc.js robert@464: robert@494: // parse messages received by OSC Server robert@464: // msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/ robert@464: void parseMessage(oscpkt::Message msg){ robert@464: robert@494: rt_printf("received message to: %s\n", msg.addressPattern().c_str()); robert@464: robert@464: int intArg; robert@464: float floatArg; robert@464: if (msg.match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs()){ robert@494: rt_printf("received int %i and float %f\n", intArg, floatArg); robert@464: } robert@464: robert@464: } robert@464: robert@464: bool setup(BelaContext *context, void *userData) robert@464: { robert@494: // setup the OSC server to receive on port 7562 robert@464: oscServer.setup(7562); robert@464: // setup the OSC client to send on port 7563 robert@464: oscClient.setup(7563); robert@464: robert@464: // the following code sends an OSC message to address /osc-setup robert@464: // then waits 1 second for a reply on /osc-setup-reply robert@494: bool handshakeReceived = false; robert@464: oscClient.sendMessageNow(oscClient.newMessage.to("/osc-setup").end()); robert@494: oscServer.receiveMessageNow(1000); robert@464: while (oscServer.messageWaiting()){ robert@464: if (oscServer.popMessage().match("/osc-setup-reply")){ robert@494: handshakeReceived = true; robert@464: } robert@464: } robert@464: robert@494: if (handshakeReceived){ robert@494: rt_printf("handshake received!\n"); robert@464: } else { robert@464: rt_printf("timeout!\n"); robert@464: } robert@464: robert@464: return true; robert@464: } robert@464: robert@464: void render(BelaContext *context, void *userData) robert@464: { robert@494: // receive OSC messages, parse them, and send back an acknowledgment robert@464: while (oscServer.messageWaiting()){ robert@464: parseMessage(oscServer.popMessage()); robert@494: oscClient.queueMessage(oscClient.newMessage.to("/osc-acknowledge").add(5).add(4.2f).add(std::string("OSC message received")).end()); robert@464: } robert@464: } robert@464: robert@464: void cleanup(BelaContext *context, void *userData) robert@464: { robert@464: robert@464: } robert@464: robert@464: robert@464: /** robert@500: \example OSC/render.cpp robert@464: robert@464: Open Sound Control robert@464: ------------------ robert@464: robert@464: This example shows an implementation of OSC (Open Sound Control) which was robert@464: developed at UC Berkeley Center for New Music and Audio Technology (CNMAT). robert@464: robert@464: It is designed to be run alongside resources/osc/osc.js robert@464: robert@464: The OSC server port on which to receive is set in `setup()` robert@464: via `oscServer.setup()`. Likewise the OSC client port on which to robert@464: send is set in `oscClient.setup()`. robert@464: robert@464: In `setup()` an OSC message to address `/osc-setup`, it then waits robert@464: 1 second for a reply on `/osc-setup-reply`. robert@464: robert@464: in `render()` the code receives OSC messages, parses them, and sends robert@464: back an acknowledgment. robert@464: */