Skip to content

Commit af64466

Browse files
committed
Receiving ttl event, unsure if correctly triggering event
1 parent 1f54cc5 commit af64466

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

Source/Plugins/NetworkEvents/NetworkEvents.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ void NetworkEvents::createEventChannels()
117117
"OS high resolution timer count when the event was received", "timestamp.software"));
118118
eventChannelArray.add(chan);
119119
messageChannel = chan;
120+
121+
EventChannel* TTLchan = new EventChannel(EventChannel::TTL, 8, 1, CoreServices::getGlobalSampleRate(), this);
122+
TTLchan->setName("Network Events output");
123+
TTLchan->setDescription("Triggers whenever \"TTL\" is received on the port.");
124+
TTLchan->setIdentifier("network.ttl.event");
125+
eventChannelArray.add(TTLchan);
126+
TTLChannel = TTLchan;
120127
}
121128

122129

@@ -238,10 +245,76 @@ String NetworkEvents::handleSpecialMessages(const String& s)
238245
status += CoreServices::RecordNode::getExperimentNumber();
239246
return status;
240247
}
248+
else if (cmd.compareIgnoreCase("TTL") == 0)
249+
{
250+
std::cout << "into ttl event case" << std::endl;
251+
// Default to chan 0 and off
252+
int currEventChannel = 0;
253+
bool onOff = false;
254+
/** First set optional parameters (name/value pairs)*/
255+
if (s.contains("="))
256+
{
257+
String params = s.substring(cmd.length()).trim();
258+
StringPairArray dict = parseNetworkMessage(params);
259+
260+
StringArray keys = dict.getAllKeys();
261+
for (int i = 0; i < keys.size(); ++i)
262+
{
263+
String key = keys[i];
264+
String value = dict[key];
265+
266+
if (key.compareIgnoreCase("EventChannel") == 0)
267+
{
268+
std::cout << value << std::endl;
269+
currEventChannel = value.getIntValue();
270+
}
271+
else if (key.compareIgnoreCase("onOff") == 0)
272+
{
273+
std::cout << value << std::endl;
274+
if (value.compareIgnoreCase("on") == 0)
275+
{
276+
onOff = true;
277+
}
278+
else
279+
{
280+
onOff = false;
281+
}
282+
}
283+
}
284+
}
285+
286+
if (triggerEvent(getTimestamp(currEventChannel), currEventChannel, onOff))
287+
{
288+
return "Success";
289+
}
290+
else
291+
{
292+
return "Failed";
293+
}
294+
}
241295

242296
return String ("NotHandled");
243297
}
244298

299+
bool NetworkEvents::triggerEvent(juce::int64 bufferTs, int eventChannel, bool onOff)
300+
{
301+
if (onOff)
302+
{
303+
juce::uint8 ttlDataOn = 1 << eventChannel;
304+
int currEventChan = eventChannel;
305+
TTLEventPtr eventOn = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOn, sizeof(juce::uint8), eventChannel);
306+
addEvent(TTLChannel, eventOn, 0);
307+
}
308+
else
309+
{
310+
juce::uint8 ttlDataOff = 0;
311+
int currEventChan = eventChannel;
312+
TTLEventPtr eventOff = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOff, sizeof(juce::uint8), eventChannel);
313+
addEvent(TTLChannel, eventOff, 0);
314+
}
315+
return true;
316+
}
317+
245318

246319
void NetworkEvents::process (AudioSampleBuffer& buffer)
247320
{

Source/Plugins/NetworkEvents/NetworkEvents.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ class NetworkEvents : public GenericProcessor
180180
CriticalSection queueLock;
181181

182182
const EventChannel* messageChannel{ nullptr };
183+
const EventChannel* TTLChannel{ nullptr };
184+
185+
bool triggerEvent(juce::int64 bufferTs, int eventChannel, bool OnOff);
183186

184187
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkEvents);
185188
};

0 commit comments

Comments
 (0)