Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
OscReceiver.h
1 #pragma once
2 
3 #include <functional>
4 #include <memory>
5 #include <vector>
6 #include <oscpkt.hh>
7 
8 class UdpServer;
9 namespace std {
10  class thread;
11 };
24 public:
25  OscReceiver();
26  OscReceiver(int port, std::function<void(oscpkt::Message* msg, const char* addr, void* arg)> on_receive, void* callbackArg = nullptr);
27  ~OscReceiver();
28 
39  void setup(int port, std::function<void(oscpkt::Message* msg, const char* addr, void* arg)> on_receive, void* callbackArg = nullptr);
40 
41 private:
42  bool lShouldStop = false;
43 
44  volatile bool waitingForMessage = false;
45  int waitForMessage(int timeout_ms);
46 
47  std::unique_ptr<UdpServer> socket;
48  std::unique_ptr<std::thread> receive_task;
49 
50  void receive_task_func();
51 
52  std::unique_ptr<oscpkt::PacketReader> pr;
53  std::vector<char> inBuffer;
54 
55  std::function<void(oscpkt::Message* msg, const char* addr, void* arg)> on_receive;
56  void* onReceiveArg = nullptr;
57 };
Definition: UdpServer.h:22
OscReceiver provides functions for receiving OSC messages in Bela.
Definition: OscReceiver.h:23
void setup(int port, std::function< void(oscpkt::Message *msg, const char *addr, void *arg)> on_receive, void *callbackArg=nullptr)
Initiliases OscReceiver.
Definition: OscReceiver.cpp:37