Skip to content

Commit 1f54cc5

Browse files
committed
Remove unused code
1 parent 46fdcae commit 1f54cc5

3 files changed

Lines changed: 12 additions & 320 deletions

File tree

Source/Plugins/NetworkEvents/NetworkEvents.cpp

Lines changed: 7 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,12 @@ CriticalSection NetworkEvents::sharedContextLock{};
4141
NetworkEvents::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-
252140
String 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-
514344
bool 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

664434
NetworkEvents::ZMQContext::ZMQContext(const ScopedLock& lock)

Source/Plugins/NetworkEvents/NetworkEvents.h

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
#include <ProcessorHeaders.h>
3939

40-
#include <vector>
4140
#include <list>
4241
#include <queue>
4342

@@ -60,8 +59,6 @@ class NetworkEvents : public GenericProcessor
6059

6160
void process (AudioSampleBuffer& buffer) override;
6261

63-
void setParameter (int parameterIndex, float newValue) override;
64-
6562
void createEventChannels() override;
6663

6764
void setEnabledState (bool newState) override;
@@ -76,18 +73,7 @@ class NetworkEvents : public GenericProcessor
7673

7774
// =========================================================================
7875

79-
int getDefaultNumOutputs() const;
80-
81-
//int64 getExtrapolatedHardwareTimestamp (int64 softwareTS) const;
82-
83-
std::vector<String> splitString (String S, char sep);
84-
85-
void initSimulation();
86-
void simulateDesignAndTrials ();
87-
void simulateSingleTrial();
88-
void simulateStartRecord();
89-
void simulateStopRecord();
90-
void run();
76+
void run() override;
9177

9278
// passing 0 corresponds to wildcard ("*") and picks any available port
9379
// returns true on success, false on failure
@@ -99,20 +85,10 @@ class NetworkEvents : public GenericProcessor
9985
void restartConnection();
10086

10187
private:
102-
// combines a string and a timestamp
103-
class StringTS
88+
struct StringTS
10489
{
105-
public:
106-
StringTS();
107-
StringTS(String S, int64 ts_software = CoreServices::getGlobalTimestamp());
108-
StringTS(MidiMessage& event);
109-
110-
std::vector<String> splitString(char sep) const;
111-
11290
String str;
113-
juce::int64 timestamp;
114-
115-
JUCE_LEAK_DETECTOR(StringTS);
91+
int64 timestamp;
11692
};
11793

11894
class ZMQContext : public ReferenceCountedObject
@@ -170,7 +146,7 @@ class NetworkEvents : public GenericProcessor
170146
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Responder);
171147
};
172148

173-
void postTimestamppedStringToMidiBuffer(StringTS s);
149+
void postTimestamppedStringToMidiBuffer(const StringTS& s);
174150

175151
String handleSpecialMessages(const String& s);
176152

@@ -200,19 +176,9 @@ class NetworkEvents : public GenericProcessor
200176

201177
uint16 urlport; // 0 indicates not connected
202178

203-
float threshold;
204-
float bufferZone;
205-
206-
bool state;
207-
bool firstTime;
208-
209179
std::queue<StringTS> networkMessagesQueue;
210-
std::queue<StringTS> simulation;
211-
212180
CriticalSection queueLock;
213181

214-
int64 simulationStartTime;
215-
216182
const EventChannel* messageChannel{ nullptr };
217183

218184
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkEvents);

0 commit comments

Comments
 (0)