@@ -39,7 +39,8 @@ RecordNode::RecordNode()
3939 isRecording(false ),
4040 hasRecorded(false ),
4141 settingsNeeded(false ),
42- receivedSoftwareTime(false )
42+ receivedSoftwareTime(false ),
43+ numSubprocessors(0 )
4344{
4445 setProcessorType (PROCESSOR_TYPE_RECORD_NODE);
4546
@@ -267,82 +268,96 @@ void RecordNode::updateChannelStates(int srcIndex, int subProcIdx, std::vector<b
267268
268269void RecordNode::updateSubprocessorMap ()
269270{
270-
271- std::vector<int > procIds;
272-
273- int masterSubprocessor = -1 ;
274- int eventIndex = 0 ;
275-
276- for (int ch = 0 ; ch < dataChannelArray.size (); ch++)
277- {
278-
279- DataChannel* chan = dataChannelArray[ch];
280- int sourceID = chan->getSourceNodeID ();
281- int subProcID = chan->getSubProcessorIdx ();
282-
283- if (!std::count (procIds.begin (), procIds.end (), sourceID))
284- procIds.push_back (sourceID);
285-
286- if (!dataChannelStates[sourceID][subProcID].size ())
287- {
288- synchronizer->addSubprocessor (chan->getSourceNodeID (), chan->getSubProcessorIdx (), chan->getSampleRate ());
289- eventIndex++;
290-
291- if (masterSubprocessor < 0 )
292- {
293- masterSubprocessor = chan->getSourceNodeID ();
294- synchronizer->setMasterSubprocessor (chan->getSourceNodeID (), chan->getSubProcessorIdx ());
295- }
296-
297- int orderInSubprocessor = 0 ;
298- while (ch < dataChannelArray.size () && dataChannelArray[ch]->getSubProcessorIdx () == subProcID && dataChannelArray[ch]->getSourceNodeID () == sourceID)
299- {
300- dataChannelStates[sourceID][subProcID].push_back (CONTINUOUS_CHANNELS_ON_BY_DEFAULT);
301- dataChannelOrder[ch] = orderInSubprocessor++;
302- ch++;
303- }
304- ch--;
305-
306- fifoUsage[sourceID][subProcID] = 0 .0f ;
307- }
308-
309- }
310-
311- std::map<int , std::map<int , std::vector<bool >>>::iterator it;
312- std::map<int , std::vector<bool >>::iterator ptr;
313-
314- numSubprocessors = 0 ;
315- for (it = dataChannelStates.begin (); it != dataChannelStates.end (); it++)
316- {
317-
318- for (ptr = it->second .begin (); ptr != it->second .end (); ptr++) {
319- if (!std::count (procIds.begin (), procIds.end (), it->first ))
320- dataChannelStates.erase (it->first );
321- else
322- numSubprocessors++;
323- }
324- }
325-
326- eventMap.clear ();
327- syncChannelMap.clear ();
328- syncOrderMap.clear ();
329- for (int ch = 0 ; ch < eventChannelArray.size (); ch++)
330- {
331-
332- EventChannel* chan = eventChannelArray[ch];
333- int sourceID = chan->getSourceNodeID ();
334- int subProcID = chan->getSubProcessorIdx ();
335-
336- eventMap[sourceID][subProcID] = chan->getNumChannels ();
337-
338- if (dataChannelStates[sourceID][subProcID].size () && !syncChannelMap[sourceID][subProcID])
339- {
340- syncOrderMap[sourceID][subProcID] = ch;
341- syncChannelMap[sourceID][subProcID] = 0 ;
342- synchronizer->setSyncChannel (chan->getSourceNodeID (), chan->getSubProcessorIdx (), ch);
343- }
344-
345- }
271+
272+ std::map<int , std::vector<int >> inputs;
273+
274+ int updatedNumSubprocessors = 0 ;
275+ int ch = 0 ;
276+
277+ while (ch < dataChannelArray.size ())
278+ {
279+
280+ DataChannel* chan = dataChannelArray[ch];
281+ int sourceID = chan->getSourceNodeID ();
282+ int subProcIdx = chan->getSubProcessorIdx ();
283+
284+ if (inputs.empty () || inputs[sourceID].empty () || inputs[sourceID].back () != subProcIdx)
285+ {
286+ // Found a new subprocessor
287+ inputs[sourceID].push_back (subProcIdx);
288+ fifoUsage[sourceID][subProcIdx] = 0 .0f ;
289+ updatedNumSubprocessors++;
290+ }
291+
292+ // Add any new sources
293+ if (!dataChannelStates.count (sourceID) || !dataChannelStates[sourceID].count (subProcIdx))
294+ {
295+ int orderInSubprocessor = 0 ;
296+ synchronizer->addSubprocessor (chan->getSourceNodeID (), chan->getSubProcessorIdx (), chan->getSampleRate ());
297+ if (synchronizer->masterProcessor < 0 )
298+ {
299+ synchronizer->setMasterSubprocessor (chan->getSourceNodeID (), chan->getSubProcessorIdx ());
300+ }
301+ while (ch < dataChannelArray.size () && dataChannelArray[ch]->getSubProcessorIdx () == subProcIdx)
302+ {
303+ dataChannelStates[sourceID][dataChannelArray[ch]->getSubProcessorIdx ()].push_back (CONTINUOUS_CHANNELS_ON_BY_DEFAULT);
304+ dataChannelOrder[ch] = orderInSubprocessor++;
305+ ch++;
306+ }
307+ }
308+ else
309+ {
310+ ch++;
311+ // Don't do anything
312+ }
313+
314+ }
315+
316+ // Remove any stale processors
317+ std::vector<int > sources;
318+ for (auto const & sourceID : inputs)
319+ sources.push_back (sourceID.first );
320+ std::vector<int > toErase;
321+
322+ std::map<int , std::map<int , std::vector<bool >>>::iterator it;
323+ for (it = dataChannelStates.begin (); it != dataChannelStates.end (); it++)
324+ {
325+ if (std::find (sources.begin (), sources.end (), it->first ) == sources.end ())
326+ toErase.push_back (it->first );
327+ }
328+
329+ for (int i = 0 ; i < toErase.size (); i++)
330+ dataChannelStates.erase (toErase[i]);
331+
332+ if (numSubprocessors != updatedNumSubprocessors && static_cast <RecordNodeEditor*> (getEditor ())->subprocessorsVisible )
333+ {
334+ numSubprocessors = updatedNumSubprocessors;
335+ static_cast <RecordNodeEditor*> (getEditor ())->showSubprocessorFifos (false );
336+ static_cast <RecordNodeEditor*> (getEditor ())->buttonEvent (static_cast <RecordNodeEditor*> (getEditor ())->fifoDrawerButton );
337+ }
338+
339+ numSubprocessors = updatedNumSubprocessors;
340+
341+ eventMap.clear ();
342+ syncChannelMap.clear ();
343+ syncOrderMap.clear ();
344+ for (int ch = 0 ; ch < eventChannelArray.size (); ch++)
345+ {
346+
347+ EventChannel* chan = eventChannelArray[ch];
348+ int sourceID = chan->getSourceNodeID ();
349+ int subProcID = chan->getSubProcessorIdx ();
350+
351+ eventMap[sourceID][subProcID] = chan->getNumChannels ();
352+
353+ if (dataChannelStates[sourceID][subProcID].size () && !syncChannelMap[sourceID][subProcID])
354+ {
355+ syncOrderMap[sourceID][subProcID] = ch;
356+ syncChannelMap[sourceID][subProcID] = 0 ;
357+ synchronizer->setSyncChannel (chan->getSourceNodeID (), chan->getSubProcessorIdx (), ch);
358+ }
359+
360+ }
346361
347362}
348363
@@ -732,4 +747,4 @@ void RecordNode::registerRecordEngine(RecordEngine *engine)
732747void RecordNode::clearRecordEngines ()
733748{
734749 engineArray.clear ();
735- }
750+ }
0 commit comments