From 19706f462384ec786af3d2cdbcd648f470eba6a4 Mon Sep 17 00:00:00 2001
From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es>
Date: Fri, 1 Sep 2017 16:18:18 +0200
Subject: [PATCH] Change sync messages to plain text for easier access

---
 .../Plugins/BinaryWriter/BinaryRecording.cpp  | 20 +++++++++++++------
 Source/Plugins/BinaryWriter/BinaryRecording.h |  2 +-
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/Source/Plugins/BinaryWriter/BinaryRecording.cpp b/Source/Plugins/BinaryWriter/BinaryRecording.cpp
index 3e3f5dd1d..66217317a 100644
--- a/Source/Plugins/BinaryWriter/BinaryRecording.cpp
+++ b/Source/Plugins/BinaryWriter/BinaryRecording.cpp
@@ -346,9 +346,17 @@ void BinaryRecording::openFiles(File rootFolder, int experimentNumber, int recor
 		jsonFile->setProperty("channels", jsonSpikeChannels.getReference(i));
 	}
 
-	Array<NpyType> msgType;
-	msgType.add(NpyType("sync_text", BaseType::CHAR, 256));
-	m_syncTextFile = new NpyFile(basepath + "sync_text.npy", msgType);
+	File syncFile = File(basepath + "sync_messages.txt");
+	Result res = syncFile.create();
+	if (res.failed())
+	{
+		std::cerr << "Error creating sync text file:" << res.getErrorMessage() << std::endl;
+	}
+	else
+	{
+		m_syncTextFile = syncFile.createOutputStream();
+	}
+	
 	m_recordingNum = recordingNumber;
 
 	DynamicObject::Ptr jsonSettingsFile = new DynamicObject();
@@ -582,9 +590,9 @@ void BinaryRecording::writeEvent(int eventIndex, const MidiMessage& event)
 
 void BinaryRecording::writeTimestampSyncText(uint16 sourceID, uint16 sourceIdx, int64 timestamp, float, String text)
 {
-	text.paddedRight(' ', 256);
-	m_syncTextFile->writeData(text.toUTF8(), 256);
-	m_syncTextFile->increaseRecordCount();
+	if (!m_syncTextFile)
+		return;
+	m_syncTextFile->writeText(text + "\n", false, false);
 }
 
 
diff --git a/Source/Plugins/BinaryWriter/BinaryRecording.h b/Source/Plugins/BinaryWriter/BinaryRecording.h
index d70f8a3a9..962c5a7a8 100644
--- a/Source/Plugins/BinaryWriter/BinaryRecording.h
+++ b/Source/Plugins/BinaryWriter/BinaryRecording.h
@@ -103,7 +103,7 @@ namespace BinaryRecordingEngine
 		OwnedArray<EventRecording> m_eventFiles;
 		OwnedArray<EventRecording> m_spikeFiles;
 		OwnedArray<NpyFile> m_dataTimestampFiles;
-		ScopedPointer<NpyFile> m_syncTextFile;
+		ScopedPointer<FileOutputStream> m_syncTextFile;
 
 		Array<unsigned int> m_spikeFileIndexes;
 		Array<uint16> m_spikeChannelIndexes;
-- 
GitLab