changeset 111:c82913d31a53

* Save alignments to session file. Needs much testing.
author Chris Cannam
date Tue, 29 Apr 2008 15:34:17 +0000
parents f57047e0522b
children e54dff673096
files framework/Document.cpp framework/SVFileReader.cpp
diffstat 2 files changed, 94 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/framework/Document.cpp	Tue Apr 29 09:44:44 2008 +0000
+++ b/framework/Document.cpp	Tue Apr 29 15:34:17 2008 +0000
@@ -1019,10 +1019,12 @@
         }
     }
 
+    std::set<Model *> written;
+
     for (ModelMap::const_iterator i = m_models.begin();
 	 i != m_models.end(); ++i) {
 
-        const Model *model = i->first;
+        Model *model = i->first;
 	const ModelRecord &rec = i->second;
 
         if (used.find(model) == used.end()) continue;
@@ -1056,25 +1058,44 @@
         }
 
         if (writeModel) {
-            i->first->toXml(out, indent + "  ");
+            model->toXml(out, indent + "  ");
+            written.insert(model);
         }
 
 	if (haveDerivation) {
             writeBackwardCompatibleDerivation(out, indent + "  ",
-                                              i->first, rec);
+                                              model, rec);
 	}
 
         //!!! We should probably own the PlayParameterRepository
         PlayParameters *playParameters =
-            PlayParameterRepository::getInstance()->getPlayParameters(i->first);
+            PlayParameterRepository::getInstance()->getPlayParameters(model);
         if (playParameters) {
             playParameters->toXml
                 (out, indent + "  ",
                  QString("model=\"%1\"")
-                 .arg(XmlExportable::getObjectExportId(i->first)));
+                 .arg(XmlExportable::getObjectExportId(model)));
         }
     }
 	    
+    //!!!
+
+    // We should write out the alignment models here.  AlignmentModel
+    // needs a toXml that writes out the export IDs of its reference
+    // and aligned models, and then streams its path model.  Note that
+    // this will only work when the alignment is complete, so we
+    // should probably wait for it if it isn't already by this point.
+
+    for (std::set<Model *>::const_iterator i = written.begin();
+	 i != written.end(); ++i) {
+
+        const Model *model = *i;
+        const AlignmentModel *alignment = model->getAlignment();
+        if (!alignment) continue;
+
+        alignment->toXml(out, indent + "  ");
+    }
+
     for (LayerSet::const_iterator i = m_layers.begin();
 	 i != m_layers.end(); ++i) {
 
--- a/framework/SVFileReader.cpp	Tue Apr 29 09:44:44 2008 +0000
+++ b/framework/SVFileReader.cpp	Tue Apr 29 15:34:17 2008 +0000
@@ -32,6 +32,7 @@
 #include "data/model/NoteModel.h"
 #include "data/model/TextModel.h"
 #include "data/model/ImageModel.h"
+#include "data/model/AlignmentModel.h"
 
 #include "transform/TransformFactory.h"
 
@@ -563,6 +564,11 @@
 			(sampleRate, resolution, notifyOnAdd);
                     model->setObjectName(name);
 		    m_models[id] = model;
+                } else if (attributes.value("subtype") == "path") {
+                    PathModel *model = new PathModel
+                        (sampleRate, resolution, notifyOnAdd);
+                    model->setObjectName(name);
+                    m_models[id] = model;
 		} else {
 		    SparseTimeValueModel *model;
                     if (haveMinMax) {
@@ -601,6 +607,57 @@
 	    std::cerr << "WARNING: SV-XML: Unexpected sparse model dimension ("
 		      << dimensions << ")" << std::endl;
 	}
+
+    } else if (type == "alignment") {
+
+        READ_MANDATORY(int, reference, toInt);
+        READ_MANDATORY(int, aligned, toInt);
+        READ_MANDATORY(int, path, toInt);
+
+        Model *refModel = 0, *alignedModel = 0, *pathModel = 0;
+
+        if (m_models.find(reference) != m_models.end()) {
+            refModel = m_models[reference];
+        } else {
+            std::cerr << "WARNING: SV-XML: Unknown reference model id "
+                      << reference << " in alignment model id " << id
+                      << std::endl;
+        }
+
+        if (m_models.find(aligned) != m_models.end()) {
+            alignedModel = m_models[aligned];
+        } else {
+            std::cerr << "WARNING: SV-XML: Unknown aligned model id "
+                      << aligned << " in alignment model id " << id
+                      << std::endl;
+        }
+
+        if (m_models.find(path) != m_models.end()) {
+            pathModel = m_models[path];
+        } else {
+            std::cerr << "WARNING: SV-XML: Unknown path model id "
+                      << path << " in alignment model id " << id
+                      << std::endl;
+        }
+
+        if (refModel && alignedModel && pathModel) {
+            AlignmentModel *model = new AlignmentModel
+                (refModel, alignedModel, 0, 0);
+            PathModel *pm = dynamic_cast<PathModel *>(pathModel);
+            if (!pm) {
+                std::cerr << "WARNING: SV-XML: Model id " << path
+                          << " referenced as path for alignment " << id
+                          << " is not a path model" << std::endl;
+            } else {
+                model->setPath(pm);
+                pm->setCompletion(100);
+            }
+            model->setObjectName(name);
+            m_models[id] = model;
+            alignedModel->setAlignment(model);
+            return true;
+        }
+        
     } else {
 
 	std::cerr << "WARNING: SV-XML: Unexpected model type \""
@@ -825,6 +882,7 @@
     case 2:
 	if (dynamic_cast<SparseTimeValueModel *>(model)) good = true;
 	else if (dynamic_cast<TextModel *>(model)) good = true;
+	else if (dynamic_cast<PathModel *>(model)) good = true;
 	break;
 
     case 3:
@@ -907,6 +965,16 @@
 	return ok;
     }
 
+    PathModel *pm = dynamic_cast<PathModel *>(m_currentDataset);
+
+    if (pm) {
+//        std::cerr << "Current dataset is a path model" << std::endl;
+        int mapframe = attributes.value("mapframe").trimmed().toInt(&ok);
+//        std::cerr << "SVFileReader::addPointToDataset: PathModel: frame = " << frame << ", mapframe = " << mapframe << ", ok = " << ok << std::endl;
+	pm->addPoint(PathModel::Point(frame, mapframe));
+	return ok;
+    }
+
     ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset);
 
     if (im) {