changeset 47:7bd5773d4372

add intervalModel reading
author lbajardsilogic
date Wed, 16 May 2007 11:28:48 +0000
parents b8d1d1f5d2c9
children a8dcc1ca82c4
files sv/document/SVFileReader.cpp sv/document/SVFileReader.h
diffstat 2 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sv/document/SVFileReader.cpp	Tue May 15 15:04:32 2007 +0000
+++ b/sv/document/SVFileReader.cpp	Wed May 16 11:28:48 2007 +0000
@@ -30,6 +30,7 @@
 #include "data/model/SparseTimeValueModel.h"
 #include "data/model/NoteModel.h"
 #include "data/model/TextModel.h"
+#include "data/model/IntervalModel.h"
 
 #include "view/Pane.h"
 
@@ -174,6 +175,10 @@
 
 	ok = addRowToDataset(attributes);
 
+    } else if (name == "interval") {
+	
+	ok = addIntervalToDataset(attributes);
+
     } else if (name == "layer") {
 
         addUnaddedModels(); // all models must be specified before first layer
@@ -527,7 +532,19 @@
 	    std::cerr << "WARNING: SV-XML: Unexpected sparse model dimension ("
 		      << dimensions << ")" << std::endl;
 	}
-    } else {
+    } else if (type == "interval") 
+	{
+		READ_MANDATORY(int, dimensions, toInt);
+		READ_MANDATORY(int, resolution, toInt);
+		bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
+		int dataset = attributes.value("dataset").trimmed().toInt(&ok);
+		if (ok) m_awaitingDatasets[dataset] = id;
+
+		IntervalModel * model = new IntervalModel(sampleRate, resolution, notifyOnAdd);
+		m_models[id] = model;
+		return true;
+
+	} else {
 
 	std::cerr << "WARNING: SV-XML: Unexpected model type \""
 		  << type.toLocal8Bit().data() << "\" for model id " << id << std::endl;
@@ -752,6 +769,7 @@
 	    m_datasetSeparator = attributes.value("separator");
 	    good = true;
 	}
+	else if (dynamic_cast<IntervalModel *>(model)) good = true;
 	break;
     }
 
@@ -969,6 +987,25 @@
     return true;
 }
 
+bool
+SVFileReader::addIntervalToDataset(const QXmlAttributes &attributes)
+{
+    bool ok = false;
+
+    IntervalModel *im = dynamic_cast<IntervalModel*>(m_currentDataset);
+	if (im)
+	{
+		READ_MANDATORY(int, start, toInt);
+		READ_MANDATORY(int, end, toInt);
+		QString label = attributes.value("label");
+		float value = 0.0;
+		value = attributes.value("value").trimmed().toFloat(&ok);
+		im->addInterval(start, end, label, value);
+		ok = true;
+	}
+	return ok;
+}
+
 bool
 SVFileReader::readPlayParameters(const QXmlAttributes &attributes)
 {
--- a/sv/document/SVFileReader.h	Tue May 15 15:04:32 2007 +0000
+++ b/sv/document/SVFileReader.h	Wed May 16 11:28:48 2007 +0000
@@ -191,6 +191,7 @@
     bool addBinToDataset(const QXmlAttributes &);
     bool addPointToDataset(const QXmlAttributes &);
     bool addRowToDataset(const QXmlAttributes &);
+	bool addIntervalToDataset(const QXmlAttributes &);
     bool readRowData(const QString &);
     bool readDerivation(const QXmlAttributes &);
     bool readPlayParameters(const QXmlAttributes &);