From 4ea79bfac5524d2601cb9877f380d017452723fd Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Tue, 4 Feb 2014 00:57:51 -0500
Subject: [PATCH] Add 'allFilesOpened' check to make sure recording doesn't
 start until all files have been opened

---
 Source/Processors/RecordNode.cpp | 10 +++++++++-
 Source/Processors/RecordNode.h   |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/Source/Processors/RecordNode.cpp b/Source/Processors/RecordNode.cpp
index a8ee52c83..ed48582ba 100755
--- a/Source/Processors/RecordNode.cpp
+++ b/Source/Processors/RecordNode.cpp
@@ -36,6 +36,7 @@ RecordNode::RecordNode()
 
     isProcessing = false;
     isRecording = false;
+    allFilesOpened = false;
     blockIndex = 0;
     signalFilesShouldClose = false;
 
@@ -383,6 +384,8 @@ void RecordNode::setParameter(int parameterIndex, float newValue)
             }
         }
 
+        allFilesOpened = true;
+
     }
     else if (parameterIndex == 0)
     {
@@ -470,10 +473,13 @@ void RecordNode::openFile(Channel* ch)
         //std::cout << header << std::endl;
         std::cout << "File ID: " << chFile << ", number of bytes: " << header.getNumBytesAsUTF8() << std::endl;
 
+
         fwrite(header.toUTF8(), 1, header.getNumBytesAsUTF8(), chFile);
 
         std::cout << "Wrote header." << std::endl;
 
+        std::cout << "Block index: " << blockIndex << std::endl;
+
     }
     else
     {
@@ -583,6 +589,8 @@ void RecordNode::closeAllFiles()
     closeFile(eventChannel);
 
     blockIndex = 0; // back to the beginning of the block
+
+    allFilesOpened = false;
 }
 
 bool RecordNode::enable()
@@ -769,7 +777,7 @@ void RecordNode::process(AudioSampleBuffer& buffer,
     // CONSTRAINTS:
     // samplesWritten must equal nSamples by the end of the process() method
 
-    if (isRecording)
+    if (isRecording && allFilesOpened)
     {
 
         // FIRST: cycle through events -- extract the TTLs and the timestamps
diff --git a/Source/Processors/RecordNode.h b/Source/Processors/RecordNode.h
index b0c4eafac..8c8f58a67 100755
--- a/Source/Processors/RecordNode.h
+++ b/Source/Processors/RecordNode.h
@@ -122,6 +122,7 @@ public:
     bool newDirectoryNeeded;
 
     bool isRecording;
+    bool allFilesOpened;
 
     /** Generate a Matlab-compatible datestring */
     String generateDateString();
-- 
GitLab