Skip to content

Commit 3286ebf

Browse files
committed
Move network record control to network events module
1 parent 97d0271 commit 3286ebf

4 files changed

Lines changed: 108 additions & 122 deletions

File tree

Source/Processors/NetworkEvents/NetworkEvents.cpp

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,23 +409,78 @@ String NetworkEvents::handleSpecialMessages(StringTS msg)
409409
/** Start/stop data acquisition */
410410
String s = msg.getString();
411411

412+
/** Command is first substring */
413+
StringArray inputs = StringArray::fromTokens(s, " ");
414+
String cmd = String(inputs[0]);
415+
412416
const MessageManagerLock mmLock;
413-
if (s.compareIgnoreCase("StartAcquisition") == 0)
417+
if (cmd.compareIgnoreCase("StartAcquisition") == 0)
414418
{
415419
if (!CoreServices::getAcquisitionStatus())
416420
{
417421
CoreServices::setAcquisitionStatus(true);
418422
}
419423
return String("StartedAcquisition");
420424
}
421-
else if (s.compareIgnoreCase("StopAcquisition") == 0)
425+
else if (cmd.compareIgnoreCase("StopAcquisition") == 0)
422426
{
423427
if (CoreServices::getAcquisitionStatus())
424428
{
425429
CoreServices::setAcquisitionStatus(false);
426430
}
427431
return String("StoppedAcquisition");
428432
}
433+
else if (String("StartRecord").compareIgnoreCase(cmd) == 0)
434+
{
435+
if (!CoreServices::getRecordingStatus() && CoreServices::getAcquisitionStatus())
436+
{
437+
/** First set optional parameters (name/value pairs)*/
438+
if (s.contains("="))
439+
{
440+
String params = s.substring(cmd.length());
441+
StringPairArray dict = parseNetworkMessage(params);
442+
443+
StringArray keys = dict.getAllKeys();
444+
for (int i = 0; i<keys.size(); i++)
445+
{
446+
String key = keys[i];
447+
String value = dict[key];
448+
449+
if (key.compareIgnoreCase("CreateNewDir") == 0)
450+
{
451+
if (value.compareIgnoreCase("1") == 0)
452+
{
453+
CoreServices::createNewRecordingDir();
454+
}
455+
}
456+
else if (key.compareIgnoreCase("RecDir") == 0)
457+
{
458+
CoreServices::setRecordingDirectory(value);
459+
}
460+
else if (key.compareIgnoreCase("PrependText") == 0)
461+
{
462+
CoreServices::setPrependTextToRecordingDir(value);
463+
}
464+
else if (key.compareIgnoreCase("AppendText") == 0)
465+
{
466+
CoreServices::setAppendTextToRecordingDir(value);
467+
}
468+
}
469+
}
470+
471+
/** Start recording */
472+
CoreServices::setRecordingStatus(true);
473+
return String("StartedRecording");
474+
}
475+
}
476+
else if (String("StopRecord").compareIgnoreCase(cmd) == 0)
477+
{
478+
if (CoreServices::getRecordingStatus())
479+
{
480+
CoreServices::setRecordingStatus(false);
481+
return String("StoppedRecording");
482+
}
483+
}
429484
else
430485
{
431486
return String("NotHandled");
@@ -590,3 +645,51 @@ void NetworkEvents::createZmqContext()
590645
zmqcontext = zmq_ctx_new(); //<-- this is only available in version 3+
591646
#endif
592647
}
648+
649+
StringPairArray NetworkEvents::parseNetworkMessage(String msg)
650+
{
651+
StringArray splitted;
652+
splitted.addTokens(msg, "=", "");
653+
654+
StringPairArray dict = StringPairArray();
655+
String key = "";
656+
String value = "";
657+
for (int i = 0; i<splitted.size() - 1; i++)
658+
{
659+
String s1 = splitted[i];
660+
String s2 = splitted[i + 1];
661+
662+
/** Get key */
663+
if (!key.isEmpty())
664+
{
665+
if (s1.contains(" "))
666+
{
667+
int i1 = s1.lastIndexOf(" ");
668+
key = s1.substring(i1 + 1);
669+
}
670+
else
671+
{
672+
key = s1;
673+
}
674+
}
675+
else
676+
{
677+
key = s1.trim();
678+
}
679+
680+
/** Get value */
681+
if (i < splitted.size() - 2)
682+
{
683+
int i1 = s2.lastIndexOf(" ");
684+
value = s2.substring(0, i1);
685+
}
686+
else
687+
{
688+
value = s2;
689+
}
690+
691+
dict.set(key, value);
692+
}
693+
694+
return dict;
695+
}

Source/Processors/NetworkEvents/NetworkEvents.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class NetworkEvents : public GenericProcessor, public Thread
117117
void handleEvent(int eventType, MidiMessage& event, int samplePos);
118118
void createZmqContext();
119119

120+
//* Split network message into name/value pairs (name1=val1 name2=val2 etc) */
121+
StringPairArray parseNetworkMessage(String msg);
122+
120123
StringTS createStringTS(String S, int64 t);
121124

122125
static void* zmqcontext;

Source/Processors/RecordControl/RecordControl.cpp

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -111,123 +111,7 @@ void RecordControl::handleEvent(int eventType, MidiMessage& event, int)
111111
CoreServices::setRecordingStatus(!CoreServices::getRecordingStatus());
112112
}
113113
}
114-
else if (eventType == MESSAGE)
115-
{
116-
handleNetworkEvent(event);
117-
}
118114

119115
}
120116

121-
void RecordControl::handleNetworkEvent(MidiMessage& event)
122-
{
123-
/** Extract network message from midi event */
124-
const uint8* dataptr = event.getRawData();
125-
int bufferSize = event.getRawDataSize();
126-
int len = bufferSize - 6; // 6 for initial event prefix
127-
String msg = String((const char*)(dataptr + 6), len);
128-
129-
/** Command is first substring */
130-
StringArray inputs = StringArray::fromTokens(msg, " ");
131-
String cmd = String(inputs[0]);
132-
133-
const MessageManagerLock mmLock;
134-
135-
if (String("StartRecord").compareIgnoreCase(cmd) == 0)
136-
{
137-
if (!CoreServices::getRecordingStatus())
138-
{
139-
/** First set optional parameters (name/value pairs)*/
140-
if (msg.contains("="))
141-
{
142-
String s = msg.substring(cmd.length());
143-
StringPairArray dict = parseNetworkMessage(s);
144-
145-
StringArray keys = dict.getAllKeys();
146-
for (int i=0; i<keys.size(); i++)
147-
{
148-
String key = keys[i];
149-
String value = dict[key];
150-
151-
if (key.compareIgnoreCase("CreateNewDir") == 0)
152-
{
153-
if (value.compareIgnoreCase("1") == 0)
154-
{
155-
CoreServices::createNewRecordingDir();
156-
}
157-
}
158-
else if (key.compareIgnoreCase("RecDir") == 0)
159-
{
160-
CoreServices::setRecordingDirectory(value);
161-
}
162-
else if (key.compareIgnoreCase("PrependText") == 0)
163-
{
164-
CoreServices::setPrependTextToRecordingDir(value);
165-
}
166-
else if (key.compareIgnoreCase("AppendText") == 0)
167-
{
168-
CoreServices::setAppendTextToRecordingDir(value);
169-
}
170-
}
171-
}
172-
173-
/** Start recording */
174-
CoreServices::setRecordingStatus(true);
175-
}
176-
}
177-
else if (String("StopRecord").compareIgnoreCase(cmd) == 0)
178-
{
179-
if (CoreServices::getRecordingStatus())
180-
{
181-
CoreServices::setRecordingStatus(false);
182-
}
183-
}
184-
}
185-
186-
StringPairArray RecordControl::parseNetworkMessage(String msg)
187-
{
188-
StringArray splitted;
189-
splitted.addTokens(msg, "=", "");
190-
191-
StringPairArray dict = StringPairArray();
192-
String key = "";
193-
String value = "";
194-
for (int i=0; i<splitted.size()-1; i++)
195-
{
196-
String s1 = splitted[i];
197-
String s2 = splitted[i+1];
198-
199-
/** Get key */
200-
if (!key.isEmpty())
201-
{
202-
if (s1.contains(" "))
203-
{
204-
int i1 = s1.lastIndexOf(" ");
205-
key = s1.substring(i1+1);
206-
}
207-
else
208-
{
209-
key = s1;
210-
}
211-
}
212-
else
213-
{
214-
key = s1.trim();
215-
}
216-
217-
/** Get value */
218-
if (i < splitted.size() - 2)
219-
{
220-
int i1 = s2.lastIndexOf(" ");
221-
value = s2.substring(0, i1);
222-
}
223-
else
224-
{
225-
value = s2;
226-
}
227-
228-
dict.set(key, value);
229-
}
230-
231-
return dict;
232-
}
233117

Source/Processors/RecordControl/RecordControl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ class RecordControl : public GenericProcessor
4747
void setParameter(int, float);
4848
void updateTriggerChannel(int newChannel);
4949
void handleEvent(int eventType, MidiMessage& event, int);
50-
void handleNetworkEvent(MidiMessage& event);
51-
52-
//* Split network message into name/value pairs (name1=val1 name2=val2 etc) */
53-
StringPairArray parseNetworkMessage(String msg);
5450

5551
bool enable();
5652

0 commit comments

Comments
 (0)