Skip to content

Commit f73a1b2

Browse files
committed
Prevent opening files when recording until all channels have a valid block
1 parent 9ec7b21 commit f73a1b2

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

Source/Processors/RecordNode/RecordNode.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ void RecordNode::setParameter(int parameterIndex, float newValue)
336336
std::cout << "Num Recording Processors: " << procInfo.size() << std::endl;
337337
int numRecordedChannels = channelMap.size();
338338

339+
m_validBlocks.clear();
340+
m_validBlocks.insertMultiple(0, false, numRecordedChannels);
341+
339342
//WARNING: If at some point we record at more that one recordEngine at once, we should change this, as using OwnedArrays only works for the first
340343
EVERY_ENGINE->setChannelMapping(channelMap, chanProcessorMap, chanOrderinProc, procInfo);
341344
m_recordThread->setChannelMap(channelMap);
@@ -485,14 +488,34 @@ void RecordNode::process(AudioSampleBuffer& buffer)
485488
int realChan = channelMap[chan];
486489
int nSamples = getNumSamples(realChan);
487490
int timestamp = getTimestamp(realChan);
488-
m_dataQueue->writeChannel(buffer, chan, realChan, nSamples, timestamp);
491+
bool shouldWrite = m_validBlocks[chan];
492+
if (!shouldWrite && nSamples > 0)
493+
{
494+
shouldWrite = true;
495+
m_validBlocks.set(chan, true);
496+
}
497+
498+
if (shouldWrite)
499+
m_dataQueue->writeChannel(buffer, chan, realChan, nSamples, timestamp);
489500
}
490501

491502
// std::cout << nSamples << " " << samplesWritten << " " << blockIndex << std::endl;
492503
if (!setFirstBlock)
493504
{
494-
m_recordThread->setFirstBlockFlag(true);
495-
setFirstBlock = true;
505+
bool shouldSetFlag = true;
506+
for (int chan = 0; chan < recordChans; ++chan)
507+
{
508+
if (!m_validBlocks[chan])
509+
{
510+
shouldSetFlag = false;
511+
break;
512+
}
513+
}
514+
if (shouldSetFlag)
515+
{
516+
m_recordThread->setFirstBlockFlag(true);
517+
setFirstBlock = true;
518+
}
496519
}
497520

498521
}

Source/Processors/RecordNode/RecordNode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class RecordNode : public GenericProcessor,
216216
ScopedPointer<SpikeMsgQueue> m_spikeQueue;
217217

218218
Array<int> m_recordedChannelMap;
219+
Array<bool> m_validBlocks;
219220

220221
String m_lastSettingsText;
221222

0 commit comments

Comments
 (0)