Skip to content

Commit 32651db

Browse files
committed
Update EventTranslator to manage sync line and main stream relationships for hardware-synced streams
1 parent 333b39f commit 32651db

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

Source/Processors/EventTranslator/EventTranslator.cpp

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void EventTranslator::registerParameters()
6060
"Use this stream as main sync",
6161
{},
6262
0,
63+
false,
6364
true);
6465

6566
// Sync line selection parameter
@@ -90,7 +91,9 @@ void EventTranslator::updateSettings()
9091
{
9192
const uint16 streamId = stream->getStreamId();
9293

93-
synchronizer.addDataStream (stream->getKey(), stream->getSampleRate());
94+
TtlLineParameter* syncLineParam = static_cast<TtlLineParameter*> (stream->getParameter ("sync_line"));
95+
int syncLine = syncLineParam->getSelectedLine();
96+
synchronizer.addDataStream (stream->getKey(), stream->getSampleRate(), syncLine, stream->generatesTimestamps());
9497

9598
EventChannel::Settings s {
9699
EventChannel::Type::TTL,
@@ -107,24 +110,92 @@ void EventTranslator::updateSettings()
107110
}
108111

109112
synchronizer.finishedUpdate();
113+
114+
// Set the main sync stream from the synchronizer
115+
auto param = getParameter ("main_sync");
116+
Array<String> streamNames = ((SelectedStreamParameter*) param)->getStreamNames();
117+
String mainStreamKey = synchronizer.mainStreamKey;
118+
if (mainStreamKey.isEmpty())
119+
{
120+
param->setNextValue (-1, false); // no main stream selected
121+
}
122+
else
123+
{
124+
int mainStreamIndex = -1;
125+
for (int i = 0; i < streamNames.size(); i++)
126+
{
127+
if (streamNames[i] == mainStreamKey)
128+
{
129+
mainStreamIndex = i;
130+
break;
131+
}
132+
}
133+
param->setNextValue (mainStreamIndex, false); // set main stream index
134+
}
110135
}
111136

112137
void EventTranslator::parameterValueChanged (Parameter* p)
113138
{
114139
if (p->getName() == "sync_line")
115140
{
116-
synchronizer.setSyncLine (getDataStream (p->getStreamId())->getKey(), ((TtlLineParameter*) p)->getSelectedLine());
141+
int selectedLine = ((TtlLineParameter*) p)->getSelectedLine();
142+
const String streamKey = getDataStream (p->getStreamId())->getKey();
143+
144+
synchronizer.setSyncLine (streamKey, selectedLine);
145+
146+
// If sync line is set to none and this is the main stream, we need to find another main stream
147+
if (selectedLine == -1 && synchronizer.mainStreamKey == streamKey)
148+
{
149+
int streamIndex = 0;
150+
for (auto stream : dataStreams)
151+
{
152+
if (stream->getStreamId() != p->getStreamId()
153+
&& ! synchronizer.streamGeneratesTimestamps (stream->getKey()))
154+
{
155+
getParameter ("main_sync")->setNextValue (streamIndex, false);
156+
return;
157+
}
158+
streamIndex++;
159+
}
160+
161+
getParameter ("main_sync")->setNextValue (-1, false);
162+
}
163+
else if (selectedLine >= 0 && synchronizer.mainStreamKey.isEmpty())
164+
{
165+
// If the sync line is set, but no main stream is set, we need to set the main stream to the one with the sync line
166+
int streamIndex = 0;
167+
for (auto stream : dataStreams)
168+
{
169+
if (stream->getKey() == streamKey)
170+
{
171+
getParameter ("main_sync")->setNextValue (streamIndex, false);
172+
return;
173+
}
174+
streamIndex++;
175+
}
176+
}
117177
}
118178
else if (p->getName() == "main_sync")
119179
{
120-
Array<String> streamNames = ((SelectedStreamParameter*) p)->getStreamNames();
121-
for (auto stream : dataStreams)
180+
int streamIndex = ((SelectedStreamParameter*) p)->getSelectedIndex();
181+
182+
if (streamIndex == -1)
122183
{
123-
String key = stream->getKey();
124-
if (key == streamNames[((SelectedStreamParameter*) p)->getSelectedIndex()])
184+
synchronizer.setMainDataStream ("");
185+
return;
186+
}
187+
else
188+
{
189+
Array<String> streamNames = ((SelectedStreamParameter*) p)->getStreamNames();
190+
for (auto stream : dataStreams)
125191
{
126-
synchronizer.setMainDataStream (stream->getKey());
127-
break;
192+
String key = stream->getKey();
193+
if (key == streamNames[streamIndex]
194+
&& ! synchronizer.streamGeneratesTimestamps (key))
195+
{
196+
synchronizer.setMainDataStream (stream->getKey());
197+
break;
198+
}
128199
}
129200
}
130201
}
@@ -184,14 +255,14 @@ void EventTranslator::handleTTLEvent (TTLEventPtr event)
184255
if (streamKey == eventStreamKey)
185256
continue; // don't translate events back to the main stream
186257

187-
if (synchronizer.isStreamSynced (streamKey))
258+
if (synchronizer.isStreamSynced (streamKey) && ! synchronizer.streamGeneratesTimestamps (streamKey))
188259
{
189-
// std::cout << "original sample number: " << sampleNumber << std::endl;
260+
// std::cout << "original sample number: " << sampleNumber << std::endl;
190261
//std::cout << "original timestamp: " << timestamp << std::endl;
191262

192263
int64 newSampleNumber = synchronizer.convertTimestampToSampleNumber (streamKey, timestamp);
193264

194-
// std::cout << "new sample number (" << streamId << "): " << newSampleNumber << std::endl;
265+
// std::cout << "new sample number (" << streamId << "): " << newSampleNumber << std::endl;
195266

196267
int64 firstSampleNumberForBlock = getFirstSampleNumberForBlock (streamId);
197268

Source/Processors/Parameter/ParameterEditor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,10 @@ void TtlLineParameterEditor::selectedLineChanged (int newLine)
985985
// If a sync line is assigned, show a warning if the stream generates hardware timestamps
986986
if (syncParam != nullptr)
987987
{
988+
GenericProcessor* syncProcessor = ((GenericProcessor*) syncParam->getOwner());
988989
DataStream* paramStream = ((DataStream*) param->getOwner());
989-
if (! RecordNode::overrideTimestampWarningShown
990+
if (syncProcessor->isRecordNode()
991+
&& ! RecordNode::overrideTimestampWarningShown
990992
&& paramStream->generatesTimestamps()
991993
&& newLine >= 0
992994
&& prevLine == -1)

0 commit comments

Comments
 (0)