Skip to content

Commit affd667

Browse files
committed
Implemented Q. Event broadcaster sees the events, but they still don't appear on LFP viewer.
1 parent 5384088 commit affd667

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

Source/Plugins/NetworkEvents/NetworkEvents.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ String NetworkEvents::handleSpecialMessages(const String& s)
247247
}
248248
else if (cmd.compareIgnoreCase("TTL") == 0)
249249
{
250-
std::cout << "into ttl event case" << std::endl;
251250
// Default to chan 0 and off
252251
int currEventChannel = 0;
253252
bool onOff = false;
@@ -265,12 +264,10 @@ String NetworkEvents::handleSpecialMessages(const String& s)
265264

266265
if (key.compareIgnoreCase("EventChannel") == 0)
267266
{
268-
std::cout << value << std::endl;
269267
currEventChannel = value.getIntValue();
270268
}
271269
else if (key.compareIgnoreCase("onOff") == 0)
272270
{
273-
std::cout << value << std::endl;
274271
if (value.compareIgnoreCase("on") == 0)
275272
{
276273
onOff = true;
@@ -281,30 +278,36 @@ String NetworkEvents::handleSpecialMessages(const String& s)
281278
}
282279
}
283280
}
281+
{
282+
ScopedLock TTLlock(TTLqueueLock);
283+
TTLQueue.push({ onOff, currEventChannel });
284+
}
284285
}
285-
286-
triggerEvent(getTimestamp(currEventChannel), currEventChannel, onOff);
286+
287+
287288
return "TTL Handled";
288289
}
289290

290291
return String ("NotHandled");
291292
}
292293

293-
void NetworkEvents::triggerEvent(juce::int64 bufferTs, int eventChannel, bool onOff)
294+
void NetworkEvents::triggerEvent(StringTTL TTLmsg)
294295
{
295-
if (onOff)
296+
if (TTLmsg.onOff)
296297
{
297-
juce::uint8 ttlDataOn = 1 << eventChannel;
298-
int currEventChan = eventChannel;
299-
TTLEventPtr eventOn = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOn, sizeof(juce::uint8), eventChannel);
298+
juce::uint8 ttlDataOn = 1 << TTLmsg.eventChannel;
299+
int currEventChannel = TTLmsg.eventChannel;
300+
TTLEventPtr eventOn = TTLEvent::createTTLEvent(TTLChannel, CoreServices::getGlobalTimestamp(), &ttlDataOn, sizeof(juce::uint8), currEventChannel);
301+
std::cout << "adding true event from ne" << std::endl;
300302
addEvent(TTLChannel, eventOn, 0);
301303
}
302304
else
303305
{
304306
juce::uint8 ttlDataOff = 0;
305-
int currEventChan = eventChannel;
306-
TTLEventPtr eventOff = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOff, sizeof(juce::uint8), eventChannel);
307-
addEvent(TTLChannel, eventOff, 0);
307+
int currEventChannel = TTLmsg.eventChannel;
308+
TTLEventPtr eventOff = TTLEvent::createTTLEvent(TTLChannel, CoreServices::getGlobalTimestamp(), &ttlDataOff, sizeof(juce::uint8), currEventChannel);
309+
std::cout << "adding false event from ne" << std::endl;
310+
addEvent(TTLChannel, eventOff, 0 );
308311
}
309312
}
310313

@@ -320,6 +323,14 @@ void NetworkEvents::process (AudioSampleBuffer& buffer)
320323
postTimestamppedStringToMidiBuffer (msg);
321324
networkMessagesQueue.pop();
322325
}
326+
327+
ScopedLock TTLlock(TTLqueueLock);
328+
while (!TTLQueue.empty())
329+
{
330+
const StringTTL& TTLmsg = TTLQueue.front();
331+
triggerEvent(TTLmsg);
332+
TTLQueue.pop();
333+
}
323334
}
324335

325336

Source/Plugins/NetworkEvents/NetworkEvents.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ class NetworkEvents : public GenericProcessor
9191
int64 timestamp;
9292
};
9393

94+
struct StringTTL
95+
{
96+
bool onOff;
97+
int eventChannel;
98+
};
99+
94100
class ZMQContext : public ReferenceCountedObject
95101
{
96102
public:
@@ -178,11 +184,14 @@ class NetworkEvents : public GenericProcessor
178184

179185
std::queue<StringTS> networkMessagesQueue;
180186
CriticalSection queueLock;
187+
188+
std::queue<StringTTL> TTLQueue;
189+
CriticalSection TTLqueueLock;
181190

182191
const EventChannel* messageChannel{ nullptr };
183192
const EventChannel* TTLChannel{ nullptr };
184193

185-
void triggerEvent(juce::int64 bufferTs, int eventChannel, bool OnOff);
194+
void triggerEvent(StringTTL TTLmsg);
186195

187196
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkEvents);
188197
};

0 commit comments

Comments
 (0)