From af64466da1c4f2df7ae7552dc4d027394e37bce7 Mon Sep 17 00:00:00 2001 From: Mark Schatza Date: Fri, 14 Dec 2018 16:55:55 -0600 Subject: [PATCH 1/7] Receiving ttl event, unsure if correctly triggering event --- .../Plugins/NetworkEvents/NetworkEvents.cpp | 73 +++++++++++++++++++ Source/Plugins/NetworkEvents/NetworkEvents.h | 3 + 2 files changed, 76 insertions(+) diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp index 2fafd835c8..beea7faa6c 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp +++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp @@ -117,6 +117,13 @@ void NetworkEvents::createEventChannels() "OS high resolution timer count when the event was received", "timestamp.software")); eventChannelArray.add(chan); messageChannel = chan; + + EventChannel* TTLchan = new EventChannel(EventChannel::TTL, 8, 1, CoreServices::getGlobalSampleRate(), this); + TTLchan->setName("Network Events output"); + TTLchan->setDescription("Triggers whenever \"TTL\" is received on the port."); + TTLchan->setIdentifier("network.ttl.event"); + eventChannelArray.add(TTLchan); + TTLChannel = TTLchan; } @@ -238,10 +245,76 @@ String NetworkEvents::handleSpecialMessages(const String& s) status += CoreServices::RecordNode::getExperimentNumber(); return status; } + else if (cmd.compareIgnoreCase("TTL") == 0) + { + std::cout << "into ttl event case" << std::endl; + // Default to chan 0 and off + int currEventChannel = 0; + bool onOff = false; + /** First set optional parameters (name/value pairs)*/ + if (s.contains("=")) + { + String params = s.substring(cmd.length()).trim(); + StringPairArray dict = parseNetworkMessage(params); + + StringArray keys = dict.getAllKeys(); + for (int i = 0; i < keys.size(); ++i) + { + String key = keys[i]; + String value = dict[key]; + + if (key.compareIgnoreCase("EventChannel") == 0) + { + std::cout << value << std::endl; + currEventChannel = value.getIntValue(); + } + else if (key.compareIgnoreCase("onOff") == 0) + { + std::cout << value << std::endl; + if (value.compareIgnoreCase("on") == 0) + { + onOff = true; + } + else + { + onOff = false; + } + } + } + } + + if (triggerEvent(getTimestamp(currEventChannel), currEventChannel, onOff)) + { + return "Success"; + } + else + { + return "Failed"; + } + } return String ("NotHandled"); } +bool NetworkEvents::triggerEvent(juce::int64 bufferTs, int eventChannel, bool onOff) +{ + if (onOff) + { + juce::uint8 ttlDataOn = 1 << eventChannel; + int currEventChan = eventChannel; + TTLEventPtr eventOn = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOn, sizeof(juce::uint8), eventChannel); + addEvent(TTLChannel, eventOn, 0); + } + else + { + juce::uint8 ttlDataOff = 0; + int currEventChan = eventChannel; + TTLEventPtr eventOff = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOff, sizeof(juce::uint8), eventChannel); + addEvent(TTLChannel, eventOff, 0); + } + return true; +} + void NetworkEvents::process (AudioSampleBuffer& buffer) { diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.h b/Source/Plugins/NetworkEvents/NetworkEvents.h index da11027d84..a9dc7b54af 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.h +++ b/Source/Plugins/NetworkEvents/NetworkEvents.h @@ -180,6 +180,9 @@ class NetworkEvents : public GenericProcessor CriticalSection queueLock; const EventChannel* messageChannel{ nullptr }; + const EventChannel* TTLChannel{ nullptr }; + + bool triggerEvent(juce::int64 bufferTs, int eventChannel, bool OnOff); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkEvents); }; From 5384088e035ddfd5710e5960e9bd2b4a0710c60d Mon Sep 17 00:00:00 2001 From: Mark Schatza Date: Fri, 14 Dec 2018 17:11:35 -0600 Subject: [PATCH 2/7] Minor changes to remove un-needed returns --- Source/Plugins/NetworkEvents/NetworkEvents.cpp | 13 +++---------- Source/Plugins/NetworkEvents/NetworkEvents.h | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp index beea7faa6c..1cb13de47d 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp +++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp @@ -283,20 +283,14 @@ String NetworkEvents::handleSpecialMessages(const String& s) } } - if (triggerEvent(getTimestamp(currEventChannel), currEventChannel, onOff)) - { - return "Success"; - } - else - { - return "Failed"; - } + triggerEvent(getTimestamp(currEventChannel), currEventChannel, onOff); + return "TTL Handled"; } return String ("NotHandled"); } -bool NetworkEvents::triggerEvent(juce::int64 bufferTs, int eventChannel, bool onOff) +void NetworkEvents::triggerEvent(juce::int64 bufferTs, int eventChannel, bool onOff) { if (onOff) { @@ -312,7 +306,6 @@ bool NetworkEvents::triggerEvent(juce::int64 bufferTs, int eventChannel, bool on TTLEventPtr eventOff = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOff, sizeof(juce::uint8), eventChannel); addEvent(TTLChannel, eventOff, 0); } - return true; } diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.h b/Source/Plugins/NetworkEvents/NetworkEvents.h index a9dc7b54af..f4b7c3a137 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.h +++ b/Source/Plugins/NetworkEvents/NetworkEvents.h @@ -182,7 +182,7 @@ class NetworkEvents : public GenericProcessor const EventChannel* messageChannel{ nullptr }; const EventChannel* TTLChannel{ nullptr }; - bool triggerEvent(juce::int64 bufferTs, int eventChannel, bool OnOff); + void triggerEvent(juce::int64 bufferTs, int eventChannel, bool OnOff); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkEvents); }; From affd6672fd47121d27514d3af8dcc99c3bb76c67 Mon Sep 17 00:00:00 2001 From: Mark Schatza Date: Fri, 14 Dec 2018 19:08:46 -0600 Subject: [PATCH 3/7] Implemented Q. Event broadcaster sees the events, but they still don't appear on LFP viewer. --- .../Plugins/NetworkEvents/NetworkEvents.cpp | 37 ++++++++++++------- Source/Plugins/NetworkEvents/NetworkEvents.h | 11 +++++- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp index 1cb13de47d..b5fba5d1a5 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp +++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp @@ -247,7 +247,6 @@ String NetworkEvents::handleSpecialMessages(const String& s) } else if (cmd.compareIgnoreCase("TTL") == 0) { - std::cout << "into ttl event case" << std::endl; // Default to chan 0 and off int currEventChannel = 0; bool onOff = false; @@ -265,12 +264,10 @@ String NetworkEvents::handleSpecialMessages(const String& s) if (key.compareIgnoreCase("EventChannel") == 0) { - std::cout << value << std::endl; currEventChannel = value.getIntValue(); } else if (key.compareIgnoreCase("onOff") == 0) { - std::cout << value << std::endl; if (value.compareIgnoreCase("on") == 0) { onOff = true; @@ -281,30 +278,36 @@ String NetworkEvents::handleSpecialMessages(const String& s) } } } + { + ScopedLock TTLlock(TTLqueueLock); + TTLQueue.push({ onOff, currEventChannel }); + } } - - triggerEvent(getTimestamp(currEventChannel), currEventChannel, onOff); + + return "TTL Handled"; } return String ("NotHandled"); } -void NetworkEvents::triggerEvent(juce::int64 bufferTs, int eventChannel, bool onOff) +void NetworkEvents::triggerEvent(StringTTL TTLmsg) { - if (onOff) + if (TTLmsg.onOff) { - juce::uint8 ttlDataOn = 1 << eventChannel; - int currEventChan = eventChannel; - TTLEventPtr eventOn = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOn, sizeof(juce::uint8), eventChannel); + juce::uint8 ttlDataOn = 1 << TTLmsg.eventChannel; + int currEventChannel = TTLmsg.eventChannel; + TTLEventPtr eventOn = TTLEvent::createTTLEvent(TTLChannel, CoreServices::getGlobalTimestamp(), &ttlDataOn, sizeof(juce::uint8), currEventChannel); + std::cout << "adding true event from ne" << std::endl; addEvent(TTLChannel, eventOn, 0); } else { juce::uint8 ttlDataOff = 0; - int currEventChan = eventChannel; - TTLEventPtr eventOff = TTLEvent::createTTLEvent(TTLChannel, bufferTs, &ttlDataOff, sizeof(juce::uint8), eventChannel); - addEvent(TTLChannel, eventOff, 0); + int currEventChannel = TTLmsg.eventChannel; + TTLEventPtr eventOff = TTLEvent::createTTLEvent(TTLChannel, CoreServices::getGlobalTimestamp(), &ttlDataOff, sizeof(juce::uint8), currEventChannel); + std::cout << "adding false event from ne" << std::endl; + addEvent(TTLChannel, eventOff, 0 ); } } @@ -320,6 +323,14 @@ void NetworkEvents::process (AudioSampleBuffer& buffer) postTimestamppedStringToMidiBuffer (msg); networkMessagesQueue.pop(); } + + ScopedLock TTLlock(TTLqueueLock); + while (!TTLQueue.empty()) + { + const StringTTL& TTLmsg = TTLQueue.front(); + triggerEvent(TTLmsg); + TTLQueue.pop(); + } } diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.h b/Source/Plugins/NetworkEvents/NetworkEvents.h index f4b7c3a137..de6b29feab 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.h +++ b/Source/Plugins/NetworkEvents/NetworkEvents.h @@ -91,6 +91,12 @@ class NetworkEvents : public GenericProcessor int64 timestamp; }; + struct StringTTL + { + bool onOff; + int eventChannel; + }; + class ZMQContext : public ReferenceCountedObject { public: @@ -178,11 +184,14 @@ class NetworkEvents : public GenericProcessor std::queue networkMessagesQueue; CriticalSection queueLock; + + std::queue TTLQueue; + CriticalSection TTLqueueLock; const EventChannel* messageChannel{ nullptr }; const EventChannel* TTLChannel{ nullptr }; - void triggerEvent(juce::int64 bufferTs, int eventChannel, bool OnOff); + void triggerEvent(StringTTL TTLmsg); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkEvents); }; From 4901278105be42f456080faedfbfa43a07ff252e Mon Sep 17 00:00:00 2001 From: Mark Schatza Date: Mon, 17 Dec 2018 09:56:41 -0600 Subject: [PATCH 4/7] Cleaned up some logic and added checks for queue --- .../Plugins/NetworkEvents/NetworkEvents.cpp | 100 +++++++++--------- Source/Plugins/NetworkEvents/NetworkEvents.h | 4 +- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp index b5fba5d1a5..16e80eec6a 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp +++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp @@ -109,7 +109,8 @@ void NetworkEvents::restartConnection() void NetworkEvents::createEventChannels() { - EventChannel* chan = new EventChannel(EventChannel::TEXT, 1, MAX_MESSAGE_LENGTH, CoreServices::getGlobalSampleRate(), this); + juce::int64 timestamp = CoreServices::getGlobalSampleRate(); + EventChannel* chan = new EventChannel(EventChannel::TEXT, 1, MAX_MESSAGE_LENGTH, timestamp, this); chan->setName("Network messages"); chan->setDescription("Messages received through the network events module"); chan->setIdentifier("external.network.rawData"); @@ -118,10 +119,10 @@ void NetworkEvents::createEventChannels() eventChannelArray.add(chan); messageChannel = chan; - EventChannel* TTLchan = new EventChannel(EventChannel::TTL, 8, 1, CoreServices::getGlobalSampleRate(), this); + EventChannel* TTLchan = new EventChannel(EventChannel::TTL, 8, 1, timestamp, this); TTLchan->setName("Network Events output"); TTLchan->setDescription("Triggers whenever \"TTL\" is received on the port."); - TTLchan->setIdentifier("network.ttl.event"); + TTLchan->setIdentifier("external.network.ttl"); eventChannelArray.add(TTLchan); TTLChannel = TTLchan; } @@ -135,11 +136,11 @@ AudioProcessorEditor* NetworkEvents::createEditor () } -void NetworkEvents::postTimestamppedStringToMidiBuffer (const StringTS& s) +void NetworkEvents::postTimestamppedStringToMidiBuffer (const StringTS& s, juce::int64 timestamp) { MetaDataValueArray md; md.add(new MetaDataValue(MetaDataDescriptor::INT64, 1, &s.timestamp)); - TextEventPtr event = TextEvent::createTextEvent(messageChannel, CoreServices::getGlobalTimestamp(), s.str, md); + TextEventPtr event = TextEvent::createTextEvent(messageChannel, timestamp, s.str, md); addEvent(messageChannel, event, 0); } @@ -245,44 +246,50 @@ String NetworkEvents::handleSpecialMessages(const String& s) status += CoreServices::RecordNode::getExperimentNumber(); return status; } - else if (cmd.compareIgnoreCase("TTL") == 0) + else if (cmd.compareIgnoreCase ("TTL") == 0) { // Default to chan 0 and off - int currEventChannel = 0; + int channel = 0; bool onOff = false; /** First set optional parameters (name/value pairs)*/ - if (s.contains("=")) + String params = s.substring(cmd.length()).trim(); + StringPairArray dict = parseNetworkMessage(params); + + StringArray keys = dict.getAllKeys(); + for (int i = 0; i < keys.size(); ++i) { - String params = s.substring(cmd.length()).trim(); - StringPairArray dict = parseNetworkMessage(params); + String key = keys[i]; + int value = dict[key].getIntValue(); - StringArray keys = dict.getAllKeys(); - for (int i = 0; i < keys.size(); ++i) + if (key.compareIgnoreCase("Channel") == 0) { - String key = keys[i]; - String value = dict[key]; - - if (key.compareIgnoreCase("EventChannel") == 0) + //Make sure in range + if (value <= 8 && value >= 0) { - currEventChannel = value.getIntValue(); + channel = value; } - else if (key.compareIgnoreCase("onOff") == 0) + else { - if (value.compareIgnoreCase("on") == 0) - { - onOff = true; - } - else - { - onOff = false; - } + //Throw some kind of error here } } + else if (key.compareIgnoreCase("on") == 0) { - ScopedLock TTLlock(TTLqueueLock); - TTLQueue.push({ onOff, currEventChannel }); + onOff = value; } } + { + ScopedLock TTLlock(TTLqueueLock); + if (CoreServices::getAcquisitionStatus()) + { + TTLQueue.push({ onOff, channel }); + } + else + { + //Throw some error + } + } + return "TTL Handled"; @@ -291,45 +298,36 @@ String NetworkEvents::handleSpecialMessages(const String& s) return String ("NotHandled"); } -void NetworkEvents::triggerEvent(StringTTL TTLmsg) +void NetworkEvents::triggerEvent(StringTTL TTLmsg, juce::int64 timestamp) { - if (TTLmsg.onOff) - { - juce::uint8 ttlDataOn = 1 << TTLmsg.eventChannel; - int currEventChannel = TTLmsg.eventChannel; - TTLEventPtr eventOn = TTLEvent::createTTLEvent(TTLChannel, CoreServices::getGlobalTimestamp(), &ttlDataOn, sizeof(juce::uint8), currEventChannel); - std::cout << "adding true event from ne" << std::endl; - addEvent(TTLChannel, eventOn, 0); - } - else - { - juce::uint8 ttlDataOff = 0; - int currEventChannel = TTLmsg.eventChannel; - TTLEventPtr eventOff = TTLEvent::createTTLEvent(TTLChannel, CoreServices::getGlobalTimestamp(), &ttlDataOff, sizeof(juce::uint8), currEventChannel); - std::cout << "adding false event from ne" << std::endl; - addEvent(TTLChannel, eventOff, 0 ); - } + juce::uint8 ttlData = TTLmsg.onOff << TTLmsg.eventChannel; + TTLEventPtr event = TTLEvent::createTTLEvent(TTLChannel, timestamp, &ttlData, sizeof(juce::uint8), TTLmsg.eventChannel); + std::cout << "adding event from ne" << std::endl; + addEvent(TTLChannel, event, 0); } void NetworkEvents::process (AudioSampleBuffer& buffer) { setTimestampAndSamples(CoreServices::getGlobalTimestamp(),0); + juce::int64 timestamp = CoreServices::getGlobalTimestamp(); ScopedLock lock(queueLock); while (! networkMessagesQueue.empty()) { const StringTS& msg = networkMessagesQueue.front(); - postTimestamppedStringToMidiBuffer (msg); + postTimestamppedStringToMidiBuffer (msg, timestamp); networkMessagesQueue.pop(); } - ScopedLock TTLlock(TTLqueueLock); - while (!TTLQueue.empty()) { - const StringTTL& TTLmsg = TTLQueue.front(); - triggerEvent(TTLmsg); - TTLQueue.pop(); + ScopedLock TTLlock(TTLqueueLock); + while (!TTLQueue.empty()) + { + const StringTTL& TTLmsg = TTLQueue.front(); + triggerEvent(TTLmsg, timestamp); + TTLQueue.pop(); + } } } diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.h b/Source/Plugins/NetworkEvents/NetworkEvents.h index de6b29feab..fad1b9501b 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.h +++ b/Source/Plugins/NetworkEvents/NetworkEvents.h @@ -152,7 +152,7 @@ class NetworkEvents : public GenericProcessor JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Responder); }; - void postTimestamppedStringToMidiBuffer(const StringTS& s); + void postTimestamppedStringToMidiBuffer(const StringTS& s, juce::int64 timestamp); String handleSpecialMessages(const String& s); @@ -191,7 +191,7 @@ class NetworkEvents : public GenericProcessor const EventChannel* messageChannel{ nullptr }; const EventChannel* TTLChannel{ nullptr }; - void triggerEvent(StringTTL TTLmsg); + void triggerEvent(StringTTL TTLmsg, juce::int64 timestamp); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkEvents); }; From 078f505e6ceb6ec84b584af4b29d53e2fdeda335 Mon Sep 17 00:00:00 2001 From: Mark Schatza Date: Mon, 17 Dec 2018 11:10:41 -0600 Subject: [PATCH 5/7] Update scope and comments --- .../Plugins/NetworkEvents/NetworkEvents.cpp | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp index 16e80eec6a..596eb15e4a 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp +++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp @@ -123,6 +123,7 @@ void NetworkEvents::createEventChannels() TTLchan->setName("Network Events output"); TTLchan->setDescription("Triggers whenever \"TTL\" is received on the port."); TTLchan->setIdentifier("external.network.ttl"); + // Possibly add meta data (reason for ttl event?) eventChannelArray.add(TTLchan); TTLChannel = TTLchan; } @@ -215,8 +216,8 @@ String NetworkEvents::handleSpecialMessages(const String& s) if (CoreServices::getRecordingStatus()) { CoreServices::setRecordingStatus (false); - return String ("StoppedRecording"); - } + } + return String("StoppedRecording"); } else if (cmd.compareIgnoreCase ("IsAcquiring") == 0) { @@ -248,10 +249,10 @@ String NetworkEvents::handleSpecialMessages(const String& s) } else if (cmd.compareIgnoreCase ("TTL") == 0) { - // Default to chan 0 and off + // Default to channel 0 and off (if no info sent) int channel = 0; bool onOff = false; - /** First set optional parameters (name/value pairs)*/ + /** Set optional parameters (name/value pairs)*/ String params = s.substring(cmd.length()).trim(); StringPairArray dict = parseNetworkMessage(params); @@ -263,14 +264,14 @@ String NetworkEvents::handleSpecialMessages(const String& s) if (key.compareIgnoreCase("Channel") == 0) { - //Make sure in range + // Make sure in range if (value <= 8 && value >= 0) { channel = value; } else { - //Throw some kind of error here + jassertfalse; } } else if (key.compareIgnoreCase("on") == 0) @@ -284,10 +285,6 @@ String NetworkEvents::handleSpecialMessages(const String& s) { TTLQueue.push({ onOff, channel }); } - else - { - //Throw some error - } } @@ -302,7 +299,6 @@ void NetworkEvents::triggerEvent(StringTTL TTLmsg, juce::int64 timestamp) { juce::uint8 ttlData = TTLmsg.onOff << TTLmsg.eventChannel; TTLEventPtr event = TTLEvent::createTTLEvent(TTLChannel, timestamp, &ttlData, sizeof(juce::uint8), TTLmsg.eventChannel); - std::cout << "adding event from ne" << std::endl; addEvent(TTLChannel, event, 0); } @@ -312,14 +308,16 @@ void NetworkEvents::process (AudioSampleBuffer& buffer) setTimestampAndSamples(CoreServices::getGlobalTimestamp(),0); juce::int64 timestamp = CoreServices::getGlobalTimestamp(); - ScopedLock lock(queueLock); - while (! networkMessagesQueue.empty()) { - const StringTS& msg = networkMessagesQueue.front(); - postTimestamppedStringToMidiBuffer (msg, timestamp); - networkMessagesQueue.pop(); + ScopedLock lock(queueLock); + while (!networkMessagesQueue.empty()) + { + const StringTS& msg = networkMessagesQueue.front(); + postTimestamppedStringToMidiBuffer(msg, timestamp); + networkMessagesQueue.pop(); + } } - + { ScopedLock TTLlock(TTLqueueLock); while (!TTLQueue.empty()) From 1ea3b559513481d48cf027139d153a041c73cffc Mon Sep 17 00:00:00 2001 From: Mark Schatza Date: Fri, 21 Dec 2018 09:56:42 -0600 Subject: [PATCH 6/7] Cleaned and finished up. --- Source/Plugins/NetworkEvents/NetworkEvents.cpp | 15 +++++++-------- Source/Plugins/NetworkEvents/NetworkEvents.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp index 179bbf3530..34edae1afb 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp +++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp @@ -99,7 +99,6 @@ void NetworkEvents::createEventChannels() TTLchan->setName("Network Events output"); TTLchan->setDescription("Triggers whenever \"TTL\" is received on the port."); TTLchan->setIdentifier("external.network.ttl"); - // Possibly add meta data (reason for ttl event?) eventChannelArray.add(TTLchan); TTLChannel = TTLchan; } @@ -225,9 +224,9 @@ String NetworkEvents::handleSpecialMessages(const String& s) } else if (cmd.compareIgnoreCase ("TTL") == 0) { - // Default to channel 0 and off (if no info sent) - int channel = 0; - bool onOff = false; + // Default to channel 0 and off (if no optional info sent) + int channel = 1; + bool onOff = 0; /** Set optional parameters (name/value pairs)*/ String params = s.substring(cmd.length()).trim(); StringPairArray dict = parseNetworkMessage(params); @@ -241,7 +240,7 @@ String NetworkEvents::handleSpecialMessages(const String& s) if (key.compareIgnoreCase("Channel") == 0) { // Make sure in range - if (value <= 8 && value >= 0) + if (value <= 8 && value >= 1) { channel = value; } @@ -265,13 +264,13 @@ String NetworkEvents::handleSpecialMessages(const String& s) - return "TTL Handled"; + return "TTL Handled: Channel=" + String(channel) + " on=" + String(onOff); } return String ("NotHandled"); } -void NetworkEvents::triggerEvent(StringTTL TTLmsg, juce::int64 timestamp) +void NetworkEvents::triggerTTLEvent(StringTTL TTLmsg, juce::int64 timestamp) { juce::uint8 ttlData = TTLmsg.onOff << TTLmsg.eventChannel; TTLEventPtr event = TTLEvent::createTTLEvent(TTLChannel, timestamp, &ttlData, sizeof(juce::uint8), TTLmsg.eventChannel); @@ -299,7 +298,7 @@ void NetworkEvents::process (AudioSampleBuffer& buffer) while (!TTLQueue.empty()) { const StringTTL& TTLmsg = TTLQueue.front(); - triggerEvent(TTLmsg, timestamp); + triggerTTLEvent(TTLmsg, timestamp); TTLQueue.pop(); } } diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.h b/Source/Plugins/NetworkEvents/NetworkEvents.h index 3ff867d5ce..b8c2ba2aad 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.h +++ b/Source/Plugins/NetworkEvents/NetworkEvents.h @@ -186,7 +186,7 @@ class NetworkEvents : public GenericProcessor const EventChannel* messageChannel{ nullptr }; const EventChannel* TTLChannel{ nullptr }; - void triggerEvent(StringTTL TTLmsg, juce::int64 timestamp); + void triggerTTLEvent(StringTTL TTLmsg, juce::int64 timestamp); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkEvents); }; From 022c80bbe593736c0c045b8bf1fac4294147397d Mon Sep 17 00:00:00 2001 From: Mark Schatza Date: Fri, 21 Dec 2018 13:51:59 -0600 Subject: [PATCH 7/7] Updated getSampleRate variable --- Source/Plugins/NetworkEvents/NetworkEvents.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp index 34edae1afb..9630f1deef 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp +++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp @@ -85,8 +85,8 @@ void NetworkEvents::restartConnection() void NetworkEvents::createEventChannels() { - juce::int64 timestamp = CoreServices::getGlobalSampleRate(); - EventChannel* chan = new EventChannel(EventChannel::TEXT, 1, MAX_MESSAGE_LENGTH, timestamp, this); + float sampleRate = CoreServices::getGlobalSampleRate(); + EventChannel* chan = new EventChannel(EventChannel::TEXT, 1, MAX_MESSAGE_LENGTH, sampleRate, this); chan->setName("Network messages"); chan->setDescription("Messages received through the network events module"); chan->setIdentifier("external.network.rawData"); @@ -95,7 +95,7 @@ void NetworkEvents::createEventChannels() eventChannelArray.add(chan); messageChannel = chan; - EventChannel* TTLchan = new EventChannel(EventChannel::TTL, 8, 1, timestamp, this); + EventChannel* TTLchan = new EventChannel(EventChannel::TTL, 8, 1, sampleRate, this); TTLchan->setName("Network Events output"); TTLchan->setDescription("Triggers whenever \"TTL\" is received on the port."); TTLchan->setIdentifier("external.network.ttl");