-
Notifications
You must be signed in to change notification settings - Fork 676
/
EventBroadcaster.h
86 lines (66 loc) · 2.41 KB
/
EventBroadcaster.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
==============================================================================
EventBroadcaster.h
Created: 22 May 2015 3:31:50pm
Author: Christopher Stawarz
==============================================================================
*/
#ifndef EVENTBROADCASTER_H_INCLUDED
#define EVENTBROADCASTER_H_INCLUDED
#include <ProcessorHeaders.h>
#ifdef ZEROMQ
#ifdef WIN32
#include <zmq.h>
#include <zmq_utils.h>
#else
#include <zmq.h>
#endif
#endif
#include <memory>
class EventBroadcaster : public GenericProcessor
{
public:
EventBroadcaster();
AudioProcessorEditor* createEditor() override;
int getListeningPort() const;
// returns 0 on success, else the errno value for the error that occurred.
int setListeningPort (int port, bool forceRestart = false);
void process (AudioSampleBuffer& continuousBuffer) override;
void handleEvent (const EventChannel* channelInfo, const MidiMessage& event, int samplePosition = 0) override;
void handleSpike(const SpikeChannel* channelInfo, const MidiMessage& event, int samplePosition = 0) override;
void saveCustomParametersToXml (XmlElement* parentElement) override;
void loadCustomParametersFromXml() override;
private:
class ZMQContext : public ReferenceCountedObject
{
public:
ZMQContext(const ScopedLock& lock);
~ZMQContext() override;
void* createZMQSocket();
private:
void* context;
};
static void closeZMQSocket(void* socket);
class ZMQSocketPtr : public std::unique_ptr<void, decltype(&closeZMQSocket)>
{
public:
ZMQSocketPtr();
~ZMQSocketPtr();
private:
ReferenceCountedObjectPtr<ZMQContext> context;
};
int unbindZMQSocket();
int rebindZMQSocket();
void sendEvent(const MidiMessage& event, float eventSampleRate) const;
static String getEndpoint(int port);
// called from getListeningPort() depending on success/failure of ZMQ operations
void reportActualListeningPort(int port);
// share a "dumb" pointer that doesn't take part in reference counting.
// want the context to be terminated by the time the static members are
// destroyed (see: https://github.com/zeromq/libzmq/issues/1708)
static ZMQContext* sharedContext;
static CriticalSection sharedContextLock;
ZMQSocketPtr zmqSocket;
int listeningPort;
};
#endif // EVENTBROADCASTER_H_INCLUDED