@@ -346,9 +346,17 @@ void BinaryRecording::openFiles(File rootFolder, int experimentNumber, int recor
346346 jsonFile->setProperty (" channels" , jsonSpikeChannels.getReference (i));
347347 }
348348
349- Array<NpyType> msgType;
350- msgType.add (NpyType (" sync_text" , BaseType::CHAR, 256 ));
351- m_syncTextFile = new NpyFile (basepath + " sync_text.npy" , msgType);
349+ File syncFile = File (basepath + " sync_messages.txt" );
350+ Result res = syncFile.create ();
351+ if (res.failed ())
352+ {
353+ std::cerr << " Error creating sync text file:" << res.getErrorMessage () << std::endl;
354+ }
355+ else
356+ {
357+ m_syncTextFile = syncFile.createOutputStream ();
358+ }
359+
352360 m_recordingNum = recordingNumber;
353361
354362 DynamicObject::Ptr jsonSettingsFile = new DynamicObject ();
@@ -504,8 +512,8 @@ void BinaryRecording::writeData(int writeChannel, int realChannel, const float*
504512 double multFactor = 1 / (float (0x7fff ) * getDataChannel (realChannel)->getBitVolts ());
505513 FloatVectorOperations::copyWithMultiply (m_scaledBuffer.getData (), buffer, multFactor, size);
506514 AudioDataConverters::convertFloatToInt16LE (m_scaledBuffer.getData (), m_intBuffer.getData (), size);
507-
508- m_DataFiles[m_fileIndexes[writeChannel]] ->writeChannel (getTimestamp (writeChannel)- m_startTS[writeChannel],m_channelIndexes[writeChannel],m_intBuffer.getData (),size);
515+ int fileIndex = m_fileIndexes[writeChannel];
516+ m_DataFiles[fileIndex] ->writeChannel (getTimestamp (writeChannel) - m_startTS[writeChannel], m_channelIndexes[writeChannel], m_intBuffer.getData (), size);
509517
510518 if (m_channelIndexes[writeChannel] == 0 )
511519 {
@@ -515,7 +523,8 @@ void BinaryRecording::writeData(int writeChannel, int realChannel, const float*
515523 {
516524 m_tsBuffer[i] = (baseTS + i);
517525 }
518- m_dataTimestampFiles[m_fileIndexes[writeChannel]]->writeData (m_tsBuffer, size*sizeof (int64));
526+ m_dataTimestampFiles[fileIndex]->writeData (m_tsBuffer, size*sizeof (int64));
527+ m_dataTimestampFiles[fileIndex]->increaseRecordCount (size);
519528 }
520529}
521530
@@ -576,12 +585,14 @@ void BinaryRecording::writeEvent(int eventIndex, const MidiMessage& event)
576585 chanFile->writeData (&chan, sizeof (uint16));
577586 }
578587 writeEventMetaData (ev.get (), rec->metaDataFile );
588+ increaseEventCounts (rec);
579589}
580590
581591void BinaryRecording::writeTimestampSyncText (uint16 sourceID, uint16 sourceIdx, int64 timestamp, float , String text)
582592{
583- text.paddedRight (' ' , 256 );
584- m_syncTextFile->writeData (text.toUTF8 (), 256 );
593+ if (!m_syncTextFile)
594+ return ;
595+ m_syncTextFile->writeText (text + " \n " , false , false );
585596}
586597
587598
@@ -593,7 +604,7 @@ void BinaryRecording::writeSpike(int electrodeIndex, const SpikeEvent* spike)
593604 uint16 spikeChannel = m_spikeChannelIndexes[electrodeIndex];
594605
595606 int totalSamples = channel->getTotalSamples () * channel->getNumChannels ();
596-
607+
597608
598609 if (totalSamples > m_bufferSize) // Shouldn't happen, and if it happens it'll be slow, but better this than crashing. Will be reset on file close and reset.
599610 {
@@ -629,8 +640,16 @@ void BinaryRecording::writeSpike(int electrodeIndex, const SpikeEvent* spike)
629640
630641 uint16 sortedID = spike->getSortedID ();
631642 sortedFile->writeData (&sortedID, sizeof (uint16));
643+ increaseEventCounts (rec);
644+ }
632645
633- writeEventMetaData (spike, rec->metaDataFile );
646+ void BinaryRecording::increaseEventCounts (EventRecording* rec)
647+ {
648+ rec->mainFile ->increaseRecordCount ();
649+ rec->timestampFile ->increaseRecordCount ();
650+ if (rec->extraFile ) rec->extraFile ->increaseRecordCount ();
651+ if (rec->channelFile ) rec->channelFile ->increaseRecordCount ();
652+ if (rec->metaDataFile ) rec->metaDataFile ->increaseRecordCount ();
634653}
635654
636655RecordEngineManager* BinaryRecording::getEngineManager ()
0 commit comments