OSCServer.h
1 /***** OSCServer.h *****/
2 #ifndef __OSCServer_H_INCLUDED__
3 #define __OSCServer_H_INCLUDED__
4 
5 #include <UdpServer.h>
6 #include <oscpkt.hh>
7 #include <Bela.h>
8 #include <queue>
9 
10 #define UDP_RECEIVE_TIMEOUT_MS 20
11 #define UDP_RECEIVE_MAX_LENGTH 16384
12 
13 class OSCServer{
14  public:
15  OSCServer();
16 
17  // must be called once during setup
18  void setup(int port);
19 
20  // returns true if messages are queued
21  // audio-thread safe
22  bool messageWaiting();
23 
24  // removes and returns the oldest message from the queue
25  // audio-thread safe, but don't call unless messageWaiting() returns true
26  oscpkt::Message popMessage();
27 
28  // if there are OSC messages waiting, decode and queue them
29  // not audio-thread safe!
30  void receiveMessageNow(int timeout);
31 
32  private:
33  int port;
34  UdpServer socket;
35 
36  AuxiliaryTask OSCReceiveTask;
37 
38  void createAuxTasks();
39  void messageCheck();
40 
41  static void checkMessages(void*);
42 
43  int inBuffer[UDP_RECEIVE_MAX_LENGTH];
44  std::queue<oscpkt::Message> inQueue;
45  oscpkt::Message poppedMessage;
46  oscpkt::PacketReader pr;
47 };
48 
49 
50 #endif
Definition: UdpServer.h:22
Definition: OSCServer.h:13
Main Bela public API.
void * AuxiliaryTask
Definition: Bela.h:289