1111#include " EventBroadcaster.h"
1212#include " EventBroadcasterEditor.h"
1313
14- EventBroadcaster::ZMQContext* EventBroadcaster::sharedContext = nullptr ;
15- CriticalSection EventBroadcaster::sharedContextLock{};
16-
17- EventBroadcaster::ZMQContext::ZMQContext (const ScopedLock& lock)
14+ EventBroadcaster::ZMQContext::ZMQContext ()
1815#ifdef ZEROMQ
1916 : context(zmq_ctx_new())
2017#else
2118 : context(nullptr )
2219#endif
23- {
24- sharedContext = this ;
25- }
20+ {}
2621
2722// ZMQContext is a ReferenceCountedObject with a pointer in each instance's
2823// socket pointer, so this only happens when the last instance is destroyed.
2924EventBroadcaster::ZMQContext::~ZMQContext ()
3025{
31- ScopedLock lock (sharedContextLock);
32- sharedContext = nullptr ;
3326#ifdef ZEROMQ
3427 zmq_ctx_destroy (context);
3528#endif
@@ -49,18 +42,6 @@ EventBroadcaster::ZMQSocket::ZMQSocket()
4942 : socket (nullptr )
5043 , boundPort (0 )
5144{
52- ScopedLock lock (sharedContextLock);
53- if (sharedContext == nullptr )
54- {
55- // first one, create the context
56- context = new ZMQContext (lock);
57- }
58- else
59- {
60- // use already-created context
61- context = sharedContext;
62- }
63-
6445#ifdef ZEROMQ
6546 socket = context->createZMQSocket ();
6647#endif
@@ -122,6 +103,7 @@ int EventBroadcaster::ZMQSocket::unbind()
122103 {
123104 boundPort = 0 ;
124105 }
106+ return status;
125107 }
126108#endif
127109 return 0 ;
@@ -157,7 +139,10 @@ AudioProcessorEditor* EventBroadcaster::createEditor()
157139
158140int EventBroadcaster::getListeningPort () const
159141{
160- if (zmqSocket == nullptr ) { return 0 ; }
142+ if (zmqSocket == nullptr )
143+ {
144+ return 0 ;
145+ }
161146 return zmqSocket->getBoundPort ();
162147}
163148
@@ -197,7 +182,7 @@ int EventBroadcaster::setListeningPort(int port, bool forceRestart)
197182 }
198183 }
199184
200- if (status != 0 && zmqSocket)
185+ if (status != 0 && zmqSocket != nullptr )
201186 {
202187 // try to rebind current socket to previous port
203188 zmqSocket->bind (currPort);
@@ -208,7 +193,7 @@ int EventBroadcaster::setListeningPort(int port, bool forceRestart)
208193
209194 // update editor
210195 auto editor = static_cast <EventBroadcasterEditor*>(getEditor ());
211- if (editor)
196+ if (editor != nullptr )
212197 {
213198 editor->setDisplayedPort (getListeningPort ());
214199 }
@@ -229,7 +214,7 @@ void EventBroadcaster::sendEvent(const MidiMessage& event, float eventSampleRate
229214 double timestampSeconds = double (Event::getTimestamp (event)) / eventSampleRate;
230215 uint16 type = Event::getBaseType (event);
231216
232- if (! zmqSocket)
217+ if (zmqSocket == nullptr )
233218 {
234219 std::cout << " Failed to send message: no socket" << std::endl;
235220 }
0 commit comments