@@ -41,17 +41,12 @@ CriticalSection NetworkEvents::sharedContextLock{};
4141NetworkEvents::NetworkEvents ()
4242 : GenericProcessor (" Network Events" )
4343 , Thread (" NetworkThread" )
44- , threshold (200.0 )
45- , bufferZone (5 .0f )
46- , state (false )
4744 , restart (false )
4845 , changeResponder (false )
46+ , urlport (0 )
4947{
5048 setProcessorType (PROCESSOR_TYPE_SOURCE);
5149
52- firstTime = true ;
53- urlport = 0 ;
54-
5550 if (!setNewListeningPort (5556 ))
5651 {
5752 // resort to choosing a port automatically
@@ -133,59 +128,7 @@ AudioProcessorEditor* NetworkEvents::createEditor ()
133128}
134129
135130
136- void NetworkEvents::setParameter (int parameterIndex, float newValue)
137- {
138- /*
139- editor->updateParameterButtons(parameterIndex);
140-
141- Parameter& p = parameters.getReference(parameterIndex);
142- p.setValue(newValue, 0);
143-
144- threshold = newValue;
145- */
146- // std::cout << float(p[0]) << std::endl;
147- }
148-
149-
150- void NetworkEvents::initSimulation ()
151- {
152- Time t;
153-
154- const int64 secondsToTicks = t.getHighResolutionTicksPerSecond ();
155- simulationStartTime = 3 * secondsToTicks + t.getHighResolutionTicks (); // start 10 seconds after
156-
157- simulation.push (StringTS (" ClearDesign" , simulationStartTime));
158- simulation.push (StringTS (" NewDesign Test" , simulationStartTime + 0.5 * secondsToTicks));
159- simulation.push (StringTS (" AddCondition Name GoRight TrialTypes 1 2 3" , simulationStartTime + 0.6 * secondsToTicks));
160- simulation.push (StringTS (" AddCondition Name GoLeft TrialTypes 4 5 6" , simulationStartTime + 0.6 * secondsToTicks));
161- }
162-
163-
164- void NetworkEvents::simulateDesignAndTrials ()
165- {
166- Time t;
167- while (simulation.size () > 0 )
168- {
169- int64 currenttime = t.getHighResolutionTicks ();
170- StringTS S = simulation.front ();
171- if (currenttime > S.timestamp )
172- {
173- // handle special messages
174- handleSpecialMessages (S.str );
175-
176- postTimestamppedStringToMidiBuffer (S);
177- // getUIComponent()->getLogWindow()->addLineToLog(S.getString());
178- simulation.pop ();
179- }
180- else
181- {
182- break ;
183- }
184- }
185-
186- }
187-
188- void NetworkEvents::postTimestamppedStringToMidiBuffer (StringTS s)
131+ void NetworkEvents::postTimestamppedStringToMidiBuffer (const StringTS& s)
189132{
190133 MetaDataValueArray md;
191134 md.add (new MetaDataValue (MetaDataDescriptor::INT64, 1 , &s.timestamp ));
@@ -194,114 +137,8 @@ void NetworkEvents::postTimestamppedStringToMidiBuffer (StringTS s)
194137}
195138
196139
197- void NetworkEvents::simulateStopRecord ()
198- {
199- Time t;
200- simulation.push (StringTS (" StopRecord" , t.getHighResolutionTicks ()));
201- }
202-
203-
204- void NetworkEvents::simulateStartRecord ()
205- {
206- Time t;
207- simulation.push (StringTS (" StartRecord" , t.getHighResolutionTicks ()));
208- }
209-
210-
211- void NetworkEvents::simulateSingleTrial ()
212- {
213- std::cout << " Simulating trial." << std::endl;
214-
215- const int numTrials = 1 ;
216- const float ITI = 0.7 ;
217- const float TrialLength = 0.4 ;
218-
219- Time t;
220-
221- if (firstTime)
222- {
223- firstTime = false ;
224- initSimulation ();
225- }
226-
227- int64 secondsToTicks = t.getHighResolutionTicksPerSecond ();
228- simulationStartTime = 3 * secondsToTicks + t.getHighResolutionTicks (); // start 10 seconds after
229-
230- // trial every 5 seconds
231- for (int k = 0 ; k < numTrials; ++k)
232- {
233- simulation.push (StringTS (" TrialStart" , simulationStartTime + ITI * k * secondsToTicks));
234-
235- if (k % 2 == 0 )
236- // 100 ms after trial start
237- simulation.push (StringTS (" TrialType 2" , simulationStartTime + (ITI * k + 0.1 ) * secondsToTicks));
238- else
239- // 100 ms after trial start
240- simulation.push (StringTS (" TrialType 4" , simulationStartTime + (ITI * k + 0.1 ) * secondsToTicks));
241-
242- // 100 ms after trial start
243- simulation.push (StringTS (" TrialAlign" , simulationStartTime + (ITI * k + 0.1 ) * secondsToTicks));
244- // 300 ms after trial start
245- simulation.push (StringTS (" TrialOutcome 1" , simulationStartTime + (ITI * k + 0.3 ) * secondsToTicks));
246- // 400 ms after trial start
247- simulation.push (StringTS (" TrialEnd" , simulationStartTime + (ITI * k + TrialLength) * secondsToTicks));
248- }
249- }
250-
251-
252140String NetworkEvents::handleSpecialMessages (const String& s)
253141{
254- /*
255- std::vector<String> input = msg.splitString(' ');
256- if (input[0] == "StartRecord")
257- {
258- getUIComponent()->getLogWindow()->addLineToLog("Remote triggered start recording");
259-
260- if (input.size() > 1)
261- {
262- getUIComponent()->getLogWindow()->addLineToLog("Remote setting session name to "+input[1]);
263- // session name was also given.
264- getProcessorGraph()->getRecordNode()->setDirectoryName(input[1]);
265- }
266- const MessageManagerLock mmLock;
267- getControlPanel()->recordButton->setToggleState(true,true);
268- return String("OK");
269- // getControlPanel()->placeMessageInQueue("StartRecord");
270- } if (input[0] == "SetSessionName")
271- {
272- getProcessorGraph()->getRecordNode()->setDirectoryName(input[1]);
273- } else if (input[0] == "StopRecord")
274- {
275- const MessageManagerLock mmLock;
276- //getControlPanel()->placeMessageInQueue("StopRecord");
277- getControlPanel()->recordButton->setToggleState(false,true);
278- return String("OK");
279- } else if (input[0] == "ProcessorCommunication")
280- {
281- ProcessorGraph *g = getProcessorGraph();
282- Array<GenericProcessor*> p = g->getListOfProcessors();
283- for (int k=0;k<p.size();k++)
284- {
285- if (p[k]->getName().toLowerCase() == input[1].toLowerCase())
286- {
287- String Query="";
288- for (int i=2;i<input.size();i++)
289- {
290- if (i == input.size()-1)
291- Query+=input[i];
292- else
293- Query+=input[i]+" ";
294- }
295-
296- return p[k]->interProcessorCommunication(Query);
297- }
298- }
299-
300- return String("OK");
301- }
302-
303- */
304-
305142 /* * Command is first substring */
306143 String cmd = s.initialSectionNotContaining (" " );
307144
@@ -413,7 +250,7 @@ void NetworkEvents::process (AudioSampleBuffer& buffer)
413250 ScopedLock lock (queueLock);
414251 while (! networkMessagesQueue.empty ())
415252 {
416- StringTS msg = networkMessagesQueue.front ();
253+ const StringTS& msg = networkMessagesQueue.front ();
417254 postTimestamppedStringToMidiBuffer (msg);
418255 networkMessagesQueue.pop ();
419256 }
@@ -483,18 +320,16 @@ void NetworkEvents::run()
483320 }
484321
485322 // received message. read string from the buffer.
486- String msgStr = String::fromUTF8 (buffer, result);
487-
323+ String msg = String::fromUTF8 (buffer, result);
488324 {
489- StringTS Msg (msgStr, timestamp_software);
490325 ScopedLock lock (queueLock);
491- networkMessagesQueue.push (Msg );
326+ networkMessagesQueue.push ({ msg, timestamp_software } );
492327 }
493328
494- CoreServices::sendStatusMessage (" Network event received: " + msgStr );
329+ CoreServices::sendStatusMessage (" Network event received: " + msg );
495330 // std::cout << "Received message!" << std::endl;
496331
497- String response = handleSpecialMessages (msgStr );
332+ String response = handleSpecialMessages (msg );
498333
499334 if (responder->send (response) == -1 )
500335 {
@@ -506,11 +341,6 @@ void NetworkEvents::run()
506341}
507342
508343
509- int NetworkEvents::getDefaultNumOutputs () const
510- {
511- return 0 ;
512- }
513-
514344bool NetworkEvents::isReady ()
515345{
516346 return true ;
@@ -599,66 +429,6 @@ String NetworkEvents::getEndpoint(uint16 port)
599429}
600430
601431
602- /* ** StringTS ***/
603-
604- NetworkEvents::StringTS::StringTS ()
605- : timestamp(0 )
606- {}
607-
608-
609- NetworkEvents::StringTS::StringTS (String S, int64 ts_software)
610- : str(S)
611- , timestamp(ts_software)
612- {}
613-
614-
615- NetworkEvents::StringTS::StringTS (MidiMessage& event)
616- : timestamp(EventBase::getTimestamp(event))
617- {
618- if (Event::getEventType (event) != EventChannel::EventChannelTypes::TEXT)
619- {
620- return ; // only handles text events
621- }
622-
623- const uint8* dataptr = event.getRawData ();
624- // relying on null terminator to get end of string...
625- str = String::fromUTF8 (reinterpret_cast <const char *>(dataptr + EVENT_BASE_SIZE));
626- }
627-
628-
629- std::vector<String> NetworkEvents::StringTS::splitString (char sep) const
630- {
631- String curr;
632-
633- std::list<String> ls;
634- for (int k = 0 ; k < str.length (); ++k)
635- {
636- if (str[k] != sep)
637- {
638- curr += str[k];
639- }
640- else
641- {
642- ls.push_back (curr);
643- while (str[k] == sep && k < str.length ())
644- ++k;
645-
646- curr = " " ;
647- if (str[k] != sep && k < str.length ())
648- curr += str[k];
649- }
650- }
651- if (str.length () > 0 )
652- {
653- if (str[str.length () - 1 ] != sep)
654- ls.push_back (curr);
655- }
656-
657- std::vector<String> Svec (ls.begin (), ls.end ());
658- return Svec;
659- }
660-
661-
662432/* ** ZMQContext ***/
663433
664434NetworkEvents::ZMQContext::ZMQContext (const ScopedLock& lock)
0 commit comments