From 02deb63e31826edc9ce79941030b6347b723157a Mon Sep 17 00:00:00 2001
From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es>
Date: Tue, 12 Apr 2016 18:01:53 +0200
Subject: [PATCH] Add extra hooks to RecordEngine

---
 Builds/VisualStudio2013/open-ephys.sln        | 20 ++++++++++++++-----
 Source/Processors/RecordNode/RecordEngine.cpp |  4 ++++
 Source/Processors/RecordNode/RecordEngine.h   | 18 +++++++++++++----
 Source/Processors/RecordNode/RecordThread.cpp |  2 ++
 4 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/Builds/VisualStudio2013/open-ephys.sln b/Builds/VisualStudio2013/open-ephys.sln
index 59a9d10ba..8387e176d 100644
--- a/Builds/VisualStudio2013/open-ephys.sln
+++ b/Builds/VisualStudio2013/open-ephys.sln
@@ -1,21 +1,31 @@
-Microsoft Visual Studio Solution File, Format Version 11.00
+Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 2013
-Project("{5A05F353-1D63-394C-DFB0-981BB2309002}") = "open-ephys", "open-ephys.vcxproj", "{9C924D66-7DEC-1AEF-B375-DB8666BFB909}"
+VisualStudioVersion = 12.0.40629.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "open-ephys", "open-ephys.vcxproj", "{9C924D66-7DEC-1AEF-B375-DB8666BFB909}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Win32 = Debug|Win32
-		Release|Win32 = Release|Win32
+		Debug|x64 = Debug|x64
+		Debug64|Win32 = Debug64|Win32
 		Debug64|x64 = Debug64|x64
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
+		Release64|Win32 = Release64|Win32
 		Release64|x64 = Release64|x64
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Debug|Win32.ActiveCfg = Debug|Win32
 		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Debug|Win32.Build.0 = Debug|Win32
-		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Release|Win32.ActiveCfg = Release|Win32
-		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Release|Win32.Build.0 = Release|Win32
+		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Debug|x64.ActiveCfg = Debug|Win32
+		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Debug64|Win32.ActiveCfg = Debug64|x64
 		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Debug64|x64.ActiveCfg = Debug64|x64
 		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Debug64|x64.Build.0 = Debug64|x64
+		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Release|Win32.ActiveCfg = Release|Win32
+		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Release|Win32.Build.0 = Release|Win32
+		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Release|x64.ActiveCfg = Release|Win32
+		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Release64|Win32.ActiveCfg = Release64|x64
 		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Release64|x64.ActiveCfg = Release64|x64
 		{9C924D66-7DEC-1AEF-B375-DB8666BFB909}.Release64|x64.Build.0 = Release64|x64
 	EndGlobalSection
diff --git a/Source/Processors/RecordNode/RecordEngine.cpp b/Source/Processors/RecordNode/RecordEngine.cpp
index 4fb307ad0..1fa5a4831 100644
--- a/Source/Processors/RecordNode/RecordEngine.cpp
+++ b/Source/Processors/RecordNode/RecordEngine.cpp
@@ -44,6 +44,10 @@ void RecordEngine::registerProcessor(const GenericProcessor* processor) {}
 
 void RecordEngine::addChannel(int index, const Channel* chan) {}
 
+void RecordEngine::startChannelBlock() {}
+
+void RecordEngine::endChannelBlock() {}
+
 Channel* RecordEngine::getChannel(int index) const
 {
     return AccessClass::getProcessorGraph()->getRecordNode()->getDataChannel(index);
diff --git a/Source/Processors/RecordNode/RecordEngine.h b/Source/Processors/RecordNode/RecordEngine.h
index 328967230..1be3109c1 100644
--- a/Source/Processors/RecordNode/RecordEngine.h
+++ b/Source/Processors/RecordNode/RecordEngine.h
@@ -73,10 +73,12 @@ public:
 		3-(updateTimestamps*)
     	4-openFiles*
     During recording: (RecordThread loop)
-    	1-(updateTimestamps*)
-		2-writeData*
-		3-writeEvent* (if needed)
-		4-writeSpike* (if needed)
+    	1-(updateTimestamps*) (can be called in a per-channel basis when the circular buffer wraps)
+		2-startChannelBlock*
+		3-writeData* (per channel. Can be called more than once to account for the circular buffer wrap)
+		4-endChannelBlock*
+		4-writeEvent* (if needed)
+		5-writeSpike* (if needed)
     When recording stops:
     	closeFiles*
 
@@ -97,11 +99,19 @@ public:
     */
     virtual void closeFiles() = 0;
 
+	/** Called by the record thread before it starts writing the channels to disk
+	*/
+	virtual void startChannelBlock();
+
     /** Write continuous data for a channel. The raw buffer pointer is passed for speed, 
 		care must be taken to only read the specified number of bytes.
     */
     virtual void writeData(int writeChannel, int realChannel, const float* buffer, int size) = 0;
 
+	/** Called by the record thread after it has written a channel block
+	*/
+	virtual void endChannelBlock();
+
     /** Write a single event to disk.
     */
     virtual void writeEvent(int eventType, const MidiMessage& event, int64 timestamp) = 0;
diff --git a/Source/Processors/RecordNode/RecordThread.cpp b/Source/Processors/RecordNode/RecordThread.cpp
index fcf7cff74..431c924c1 100644
--- a/Source/Processors/RecordNode/RecordThread.cpp
+++ b/Source/Processors/RecordNode/RecordThread.cpp
@@ -114,6 +114,7 @@ void RecordThread::writeData(const AudioSampleBuffer& dataBuffer, int maxSamples
 	Array<CircularBufferIndexes> idx;
 	m_dataQueue->startRead(idx, timestamps, maxSamples);
 	EVERY_ENGINE->updateTimestamps(timestamps);
+	EVERY_ENGINE->startChannelBlock();
 	for (int chan = 0; chan < m_numChannels; ++chan)
 	{
 		if (idx[chan].size1 > 0)
@@ -128,6 +129,7 @@ void RecordThread::writeData(const AudioSampleBuffer& dataBuffer, int maxSamples
 		}
 	}
 	m_dataQueue->stopRead();
+	EVERY_ENGINE->endChannelBlock();
 
 	std::vector<EventMessagePtr> events;
 	int nEvents = m_eventQueue->getEvents(events, maxEvents);
-- 
GitLab