Skip to content

Commit 067c3b9

Browse files
committed
Update Record Node and Synchronizer logic for setting main sync stream
1 parent 1635fa7 commit 067c3b9

5 files changed

Lines changed: 80 additions & 39 deletions

File tree

Source/Processors/GenericProcessor/GenericProcessor.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,12 +1060,25 @@ void GenericProcessor::update()
10601060
else if (param->getType() == Parameter::TTL_LINE_PARAM)
10611061
{
10621062
TtlLineParameter* p = (TtlLineParameter*) param;
1063-
stream->addParameter (new TtlLineParameter (*p));
10641063

10651064
// If the stream is hardware synchronized, default the sync line to None
10661065
if (p->syncModeEnabled() && stream->generatesTimestamps())
10671066
{
1068-
stream->getParameter (p->getName())->currentValue = -1;
1067+
TtlLineParameter* p2 = new TtlLineParameter (nullptr,
1068+
p->getScope(),
1069+
p->getName(),
1070+
p->getDisplayName(),
1071+
p->getDescription(),
1072+
p->getMaxAvailableLines(),
1073+
true,
1074+
true,
1075+
p->shouldDeactivateDuringAcquisition());
1076+
p2->currentValue = -1;
1077+
stream->addParameter (p2);
1078+
}
1079+
else
1080+
{
1081+
stream->addParameter (new TtlLineParameter (*p));
10691082
}
10701083
}
10711084
}
@@ -1135,8 +1148,8 @@ void GenericProcessor::update()
11351148

11361149
if (! isMerger() && ! isSource())
11371150
updateSettings(); // allow processors to change custom settings,
1138-
// including creation of streams / channels and
1139-
// setting isEnabled variable
1151+
// including creation of streams / channels and
1152+
// setting isEnabled variable
11401153

11411154
LOGG (" Updated custom settings in ", MS_FROM_START, " milliseconds");
11421155

Source/Processors/Parameter/Parameter.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,6 @@ TtlLineParameter::TtlLineParameter (ParameterOwner* owner,
11231123
{
11241124
jassert ((lineCount >= 0 && lineCount < 256));
11251125
jassert (scope == ParameterScope::STREAM_SCOPE);
1126-
1127-
// Can't have both sync mode and select none
1128-
if (syncMode && selectNone)
1129-
jassertfalse;
11301126
}
11311127

11321128
void TtlLineParameter::setNextValue (var newValue_, bool undoable)
@@ -1135,7 +1131,7 @@ void TtlLineParameter::setNextValue (var newValue_, bool undoable)
11351131
return;
11361132

11371133
if (((int) newValue_ < lineCount && (int) newValue_ >= 0)
1138-
|| (! syncMode && (int) newValue_ == -1)) // -1 is a valid value for non-sync mode
1134+
|| (selectNone && (int) newValue_ == -1)) // -1 is a valid value for non-sync mode
11391135
{
11401136
newValue = newValue_;
11411137

@@ -1339,7 +1335,7 @@ void SelectedStreamParameter::setNextValue (var newValue_, bool undoable)
13391335
return;
13401336

13411337
if (newValue_.isInt()
1342-
&& (int) newValue_ >= 0
1338+
&& (int) newValue_ >= -1
13431339
&& (int) newValue_ < streamNames.size())
13441340
{
13451341
newValue = newValue_;
@@ -1395,7 +1391,7 @@ int SelectedStreamParameter::getSelectedIndex()
13951391
String SelectedStreamParameter::getValueAsString()
13961392
{
13971393
if ((int) currentValue == -1 || streamNames.size() == 0)
1398-
return String();
1394+
return "None";
13991395
else
14001396
return streamNames[(int) currentValue];
14011397
}
@@ -1413,7 +1409,7 @@ void SelectedStreamParameter::fromXml (XmlElement* xml)
14131409

14141410
String SelectedStreamParameter::getChangeDescription()
14151411
{
1416-
return streamNames[(int) currentValue];
1412+
return getValueAsString();
14171413
}
14181414

14191415
TimeParameter::TimeParameter (ParameterOwner* owner,

Source/Processors/Parameter/ParameterEditor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,11 @@ void SyncControlButton::paintButton (Graphics& g, bool isMouseOver, bool isButto
892892
{
893893
if (isMouseOver)
894894
{
895-
g.setColour (Colours::deepskyblue.contrasting (0.1f));
895+
g.setColour (Colour (30, 112, 255).contrasting (0.1f));
896896
}
897897
else
898898
{
899-
g.setColour (Colours::deepskyblue);
899+
g.setColour (Colour (30, 112, 255));
900900
}
901901
break;
902902
}

Source/Processors/RecordNode/RecordNode.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ void RecordNode::parameterValueChanged (Parameter* p)
170170
for (auto stream : dataStreams)
171171
{
172172
String key = stream->getKey();
173-
if (key == streamNames[((SelectedStreamParameter*) p)->getSelectedIndex()])
173+
if (key == streamNames[((SelectedStreamParameter*) p)->getSelectedIndex()]
174+
&& ! synchronizer.streamGeneratesTimestamps (key))
174175
{
175176
synchronizer.setMainDataStream (stream->getKey());
176177
break;
@@ -580,6 +581,28 @@ void RecordNode::updateSettings()
580581
else
581582
++it;
582583
}
584+
585+
// Set the main sync stream from the synchronizer
586+
auto param = getParameter ("main_sync");
587+
Array<String> streamNames = ((SelectedStreamParameter*) param)->getStreamNames();
588+
String mainStreamKey = synchronizer.mainStreamKey;
589+
if (mainStreamKey.isEmpty())
590+
{
591+
param->setNextValue (-1, false); // no main stream selected
592+
}
593+
else
594+
{
595+
int mainStreamIndex = -1;
596+
for (int i = 0; i < streamNames.size(); i++)
597+
{
598+
if (streamNames[i] == mainStreamKey)
599+
{
600+
mainStreamIndex = i;
601+
break;
602+
}
603+
}
604+
param->setNextValue (mainStreamIndex, false); // set main stream index
605+
}
583606
}
584607

585608
bool RecordNode::isSynchronized()

Source/Processors/Synchronizer/Synchronizer.cpp

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void SyncStream::reset (String mainStreamKey)
5252
actualSampleRate = expectedSampleRate;
5353
globalStartTime = 0.0;
5454
isSynchronized = true;
55-
overrideHardwareTimestamps = false; // do not override hardware timestamps for the main stream
55+
overrideHardwareTimestamps = true; // main stream overrides hardware timestamps
5656
}
5757
else
5858
{
@@ -354,51 +354,55 @@ void Synchronizer::reset()
354354
void Synchronizer::prepareForUpdate()
355355
{
356356
previousMainStreamKey = mainStreamKey;
357-
357+
mainStreamKey = String();
358+
dataStreamObjects.clear();
359+
streams.clear();
358360
streamCount = 0;
359-
360-
for (auto [id, stream] : streams)
361-
stream->isActive = false;
362361
}
363362

364363
void Synchronizer::finishedUpdate()
365364
{
365+
if (mainStreamKey.isEmpty() && streamCount > 0)
366+
{
367+
// if no main stream is set, set the first non-hardware-synced stream as the main stream
368+
for (auto stream : dataStreamObjects)
369+
{
370+
if (! streamGeneratesTimestamps (stream->streamKey))
371+
{
372+
mainStreamKey = stream->streamKey;
373+
LOGD ("No main stream set, setting ", mainStreamKey, " as the main stream");
374+
break;
375+
}
376+
}
377+
}
366378
}
367379

368380
void Synchronizer::addDataStream (String streamKey, float expectedSampleRate, bool generatesTimestamps)
369381
{
370382
LOGD ("Synchronizer adding ", streamKey, " with sample rate ", expectedSampleRate);
371-
// if this is the first stream, make it the main one
372-
if (mainStreamKey == "")
373-
mainStreamKey = streamKey;
374383

375384
//std::cout << "Main stream ID: " << mainStreamId << std::endl;
376385

377386
// if there's a stored value, and it appears again,
378387
// re-instantiate this as the main stream
379-
if (mainStreamKey == previousMainStreamKey)
388+
if (streamKey == previousMainStreamKey)
380389
mainStreamKey = previousMainStreamKey;
381390

382-
// if there's no Stream object yet, create a new one
383-
if (streams.count (streamKey) == 0)
384-
{
385-
//std::cout << "Creating new Stream object" << std::endl;
386-
dataStreamObjects.add (new SyncStream (streamKey, expectedSampleRate, this, generatesTimestamps));
387-
streams[streamKey] = dataStreamObjects.getLast();
388-
setSyncLine (streamKey, generatesTimestamps ? -1 : 0); // if the stream generates its own timestamps, set sync line to -1 (no sync line), otherwise set it to 0
389-
}
390-
else
391-
{
392-
// otherwise, indicate that the stream is currently active and update sample rate
393-
streams[streamKey]->isActive = true;
394-
streams[streamKey]->expectedSampleRate = expectedSampleRate;
395-
}
391+
//std::cout << "Creating new Stream object" << std::endl;
392+
dataStreamObjects.add (new SyncStream (streamKey, expectedSampleRate, this, generatesTimestamps));
393+
streams[streamKey] = dataStreamObjects.getLast();
394+
setSyncLine (streamKey, generatesTimestamps ? -1 : 0); // if the stream generates its own timestamps, set sync line to -1 (no sync line), otherwise set it to 0
396395

397396
streamCount++;
398397
}
399398

400399
void Synchronizer::setMainDataStream (String streamKey)
401400
{
401+
if (streams.count (streamKey) == 0)
402+
{
403+
LOGD ("Cannot set ", streamKey, " as main data stream. Stream not found.");
404+
return;
405+
}
402406
LOGD ("Synchronizer setting mainDataStream to ", streamKey);
403407
mainStreamKey = streamKey;
404408
reset();
@@ -516,6 +520,9 @@ bool Synchronizer::isStreamSynced (String streamKey)
516520

517521
bool Synchronizer::streamGeneratesTimestamps (String streamKey)
518522
{
523+
if (streams.count (streamKey) == 0)
524+
return false;
525+
519526
return streams[streamKey]->generatesTimestamps && ! streams[streamKey]->overrideHardwareTimestamps;
520527
}
521528

@@ -535,12 +542,14 @@ SyncStatus Synchronizer::getStatus (String streamKey)
535542

536543
void Synchronizer::hiResTimerCallback()
537544
{
545+
if (mainStreamKey.isEmpty())
546+
return;
538547

539548
const ScopedLock sl (synchronizerLock);
540549

541550
for (auto [key, stream] : streams)
542551
{
543-
if (key != mainStreamKey)
552+
if (key != mainStreamKey && ! streamGeneratesTimestamps (key))
544553
{
545554
stream->syncWith (streams[mainStreamKey]);
546555
}

0 commit comments

Comments
 (0)