@@ -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
0 commit comments