changeset 611:dd97f7b3d120

* Add start frame get/set to EditableDenseThreeDimensionalModel and use it when importing grids from CSV with timings attached
author Chris Cannam
date Fri, 11 Sep 2009 15:42:32 +0000
parents 0a9e960fca53
children 75f154085a4d
files data/fileio/CSVFileReader.cpp data/model/EditableDenseThreeDimensionalModel.cpp data/model/EditableDenseThreeDimensionalModel.h
diffstat 3 files changed, 42 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp	Fri Sep 11 11:41:22 2009 +0000
+++ b/data/fileio/CSVFileReader.cpp	Fri Sep 11 15:42:32 2009 +0000
@@ -99,7 +99,14 @@
     size_t windowSize = m_format.getWindowSize();
 
     if (timingType == CSVFormat::ExplicitTiming) {
-	windowSize = 1;
+        if (modelType == CSVFormat::ThreeDimensionalModel) {
+            // This will be overridden later if more than one line
+            // appears in our file, but we want to choose a default
+            // that's likely to be visible
+            windowSize = 1024;
+        } else {
+            windowSize = 1;
+        }
 	if (timeUnits == CSVFormat::TimeSeconds) {
 	    sampleRate = m_mainModelSampleRate;
 	}
@@ -119,6 +126,7 @@
     float min = 0.0, max = 0.0;
 
     size_t frameNo = 0;
+    size_t startFrame = 0; // for calculation of dense model resolution
 
     while (!in.atEnd()) {
 
@@ -245,10 +253,23 @@
 
                     bool ok = false;
                     float value = list[i].toFloat(&ok);
-                    values.push_back(value);
+
+                    if (i > 0 || timingType != CSVFormat::ExplicitTiming) {
+                        values.push_back(value);
+                    }
 	    
-                    if ((lineno == 0 && i == 0) || value < min) min = value;
-                    if ((lineno == 0 && i == 0) || value > max) max = value;
+                    bool firstEver = (lineno == 0 && i == 0);
+
+                    if (firstEver || value < min) min = value;
+                    if (firstEver || value > max) max = value;
+
+                    if (firstEver) {
+                        startFrame = frameNo;
+                        model3->setStartFrame(startFrame);
+                    } else if (lineno == 1 &&
+                               timingType == CSVFormat::ExplicitTiming) {
+                        model3->setResolution(frameNo - startFrame);
+                    }
 
                     if (!ok) {
                         if (warnings < warnLimit) {
@@ -268,7 +289,7 @@
 //                std::cerr << "Setting bin values for count " << lineno << ", frame "
 //                          << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << std::endl;
 
-                model3->setColumn(frameNo / model3->getResolution(), values);
+                model3->setColumn(lineno, values);
             }
 
             ++lineno;
--- a/data/model/EditableDenseThreeDimensionalModel.cpp	Fri Sep 11 11:41:22 2009 +0000
+++ b/data/model/EditableDenseThreeDimensionalModel.cpp	Fri Sep 11 15:42:32 2009 +0000
@@ -34,6 +34,7 @@
                                                                        size_t yBinCount,
                                                                        CompressionType compression,
                                                                        bool notifyOnAdd) :
+    m_startFrame(0),
     m_sampleRate(sampleRate),
     m_resolution(resolution),
     m_yBinCount(yBinCount),
@@ -63,7 +64,13 @@
 size_t
 EditableDenseThreeDimensionalModel::getStartFrame() const
 {
-    return 0;
+    return m_startFrame;
+}
+
+void
+EditableDenseThreeDimensionalModel::setStartFrame(size_t f)
+{
+    m_startFrame = f; 
 }
 
 size_t
@@ -489,12 +496,13 @@
 
     Model::toXml
 	(out, indent,
-         QString("type=\"dense\" dimensions=\"3\" windowSize=\"%1\" yBinCount=\"%2\" minimum=\"%3\" maximum=\"%4\" dataset=\"%5\" %6")
+         QString("type=\"dense\" dimensions=\"3\" windowSize=\"%1\" yBinCount=\"%2\" minimum=\"%3\" maximum=\"%4\" dataset=\"%5\" startFrame=\"%6\" %7")
 	 .arg(m_resolution)
 	 .arg(m_yBinCount)
 	 .arg(m_minimum)
 	 .arg(m_maximum)
 	 .arg(getObjectExportId(&m_data))
+         .arg(m_startFrame)
 	 .arg(extraAttributes));
 
     out << indent;
--- a/data/model/EditableDenseThreeDimensionalModel.h	Fri Sep 11 11:41:22 2009 +0000
+++ b/data/model/EditableDenseThreeDimensionalModel.h	Fri Sep 11 15:42:32 2009 +0000
@@ -58,6 +58,11 @@
     
 
     /**
+     * Set the frame offset of the first column.
+     */
+    virtual void setStartFrame(size_t);
+
+    /**
      * Return the number of sample frames covered by each set of bins.
      */
     virtual size_t getResolution() const;
@@ -157,6 +162,7 @@
 
     std::vector<QString> m_binNames;
 
+    size_t m_startFrame;
     size_t m_sampleRate;
     size_t m_resolution;
     size_t m_yBinCount;