OSCClient.h
1 /***** OSCClient.h *****/
2 #ifndef __OSCClient_H_INCLUDED__
3 #define __OSCClient_H_INCLUDED__
4 
5 #include <UdpClient.h>
6 #include <Bela.h>
7 #include <oscpkt.hh>
8 #include <queue>
9 
11  public:
12  OSCMessageFactory& to(std::string);
13  OSCMessageFactory& add(std::string);
14  OSCMessageFactory& add(int);
15  OSCMessageFactory& add(float);
16  OSCMessageFactory& add(bool);
17  OSCMessageFactory& add(void *ptr, int size);
18  oscpkt::Message end();
19  private:
20  oscpkt::Message msg;
21 };
22 
23 class OSCClient{
24  public:
25  OSCClient();
26 
27  // must be called once during setup
28  void setup(int port, const char* address="127.0.0.1", bool scheduleTask = true);
29 
30  // queue a message to be sent during the next aux task OSCSendTask
31  // audio-thread safe
32  void queueMessage(oscpkt::Message);
33 
34  // send a mesage immediately
35  // *** do not use on audio thread! ***
36  // to be used during setup
37  void sendMessageNow(oscpkt::Message);
38 
39  // allows new OSC messages to be created
40  // audio-thread safe
41  // usage: oscClient.queueMessage(oscClient.newMessage.to("/address").add(param).end());
42  OSCMessageFactory newMessage;
43 
44  private:
45  const char* address;
46  int port;
47 
48  UdpClient socket;
49  AuxiliaryTask OSCSendTask;
50  std::queue<oscpkt::Message> outQueue;
51  oscpkt::PacketWriter pw;
52  char* outBuffer;
53 
54  static void sendQueue(void*);
55 
56  void createAuxTasks();
57  void queueSend();
58 
59 };
60 
61 #endif
Definition: OSCClient.h:10
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition: 01-Basics/minimal/render.cpp:35
Definition: OSCClient.h:23
Main Bela public API.
Definition: UdpClient.h:21
void * AuxiliaryTask
Definition: Bela.h:289