iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugOSC_internal.h
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
20#include <cstring>
21#include <ctime>
22#include <functional>
23#include <memory>
24
25#include "jnetlib/jnetlib.h"
26
27#include "IPlugPlatform.h"
28#include "IPlugLogger.h"
29#include "IPlugOSC_msg.h"
30#include "IPlugTimer.h"
31
32
33BEGIN_IPLUG_NAMESPACE
34
35#ifndef OSC_TIMER_RATE
36static constexpr int OSC_TIMER_RATE = 100;
37#endif
38
39using OSCLogFunc = std::function<void(WDL_String& log)>;
40
42{
43public:
44 OSCDevice(const char* dest, int maxpacket, int sendsleep, struct sockaddr_in* listen_addr);
45
46 virtual ~OSCDevice();
47 void RunInput();
48 void RunOutput();
49 void AddInstance(void (*callback)(void* d1, int dev_idx, int msglen, void* msg), void* d1, int dev_idx);
50 void OnMessage(char type, const unsigned char* msg, int len);
51 void SendOSC(const char* src, int len);
52
53private:
54 struct rec
55 {
56 void (*callback)(void* d1, int dev_idx, int msglen, void* msg);
57 void* data1;
58 int dev_idx;
59 };
60
61 WDL_TypedBuf<rec> mInstances;
62public:
63 double mLastOpenTime = 0;
64 bool mHasInput = false;
65 bool mHasOutput = false;
66
67 SOCKET mSendSocket;
68 int mMaxMacketSize, mSendSleep;
69 WDL_String mDestination;
70
71 struct sockaddr_in mSendAddress, mReceiveAddress;
72 WDL_Queue mSendQueue, mReceiveQueue;
73};
74
76{
77 struct incomingEvent
78 {
79 OSCDevice* dev_ptr;
80 int sz; // size of msg
81 unsigned char msg[3];
82 };
83
84public:
85 OSCInterface(OSCLogFunc logFunc = nullptr);
86
87 virtual ~OSCInterface();
88
89 OSCInterface(const OSCInterface&) = delete;
90 OSCInterface& operator=(const OSCInterface&) = delete;
91
92 OSCDevice* CreateReceiver(WDL_String& log, int port = 8000);
93 OSCDevice* CreateSender(WDL_String& log, const char* ip = "127.0.0.1", int port = 8000);
94
95public:
96 virtual void OnOSCMessage(OscMessageRead& msg) {};
97 void SetLogFunc(OSCLogFunc logFunc) { mLogFunc = logFunc; }
98
99protected:
102 void RemoveDevice(OSCDevice* device);
103
104private:
105 static void MessageCallback(void *d1, int dev_idx, int msglen, void *msg);
106
107 void OnTimer(Timer& timer);
108
109 WDL_PtrList<OSCDevice> mDevices;
110
111protected:
112 OSCLogFunc mLogFunc;
113 std::unique_ptr<Timer> mTimer;
114 WDL_HeapBuf mIncomingEvents; // incomingEvent list, each is 8-byte aligned
115 WDL_Mutex mIncomingEvents_mutex;
116};
117
118END_IPLUG_NAMESPACE
IPlug logging a.k.a tracing functionality.
Include to get consistently named preprocessor macros for different platforms and logging functionali...
This file includes classes for implementing timers - in order to get a regular callback on the main t...
void RemoveDevice(OSCDevice *device)
Remove a device from the device list and delete it.
Base class for timer.
Definition: IPlugTimer.h:40