Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
OscReceiver.h
1 #pragma once
2 
3 #include <memory>
4 #include <oscpkt.hh> // neccesary for definition of oscpkt::Message in callback
5 
6 // forward declarations to speed up compilation
7 class AuxTaskNonRT;
8 class UdpServer;
9 
10 #define OSCRECEIVER_POLL_US 5000
11 #define OSCRECEIVER_BUFFERSIZE 65536
12 
25  public:
26  OscReceiver();
27  OscReceiver(int port, std::function<void(oscpkt::Message* msg, void* arg)> on_receive, void* callbackArg = nullptr);
28  ~OscReceiver();
29 
40  void setup(int port, std::function<void(oscpkt::Message* msg, void* arg)> on_receive, void* callbackArg = nullptr);
41 
42  private:
43  bool lShouldStop = false;
44 
45  volatile bool waitingForMessage = false;
46  int waitForMessage(int timeout_ms);
47 
48  std::unique_ptr<UdpServer> socket;
49 
50  std::unique_ptr<AuxTaskNonRT> receive_task;
51  void receive_task_func();
52 
53  std::unique_ptr<oscpkt::PacketReader> pr;
54  char* inBuffer[OSCRECEIVER_BUFFERSIZE];
55 
56  std::function<void(oscpkt::Message* msg, void* arg)> on_receive;
57  void* onReceiveArg = nullptr;
58 };
void setup(int port, std::function< void(oscpkt::Message *msg, void *arg)> on_receive, void *callbackArg=nullptr)
Initiliases OscReceiver.
Definition: OscReceiver.cpp:28
Definition: UdpServer.h:22
OscReceiver provides functions for receiving OSC messages in Bela.
Definition: OscReceiver.h:24
Definition: AuxTaskNonRT.h:20