diff data/model/AlignmentModel.cpp @ 407:88ad01799040

* Save alignments to session file. Needs much testing.
author Chris Cannam
date Tue, 29 Apr 2008 15:34:17 +0000
parents 62789d79b98f
children 115f60df1e4d
line wrap: on
line diff
--- a/data/model/AlignmentModel.cpp	Tue Apr 29 10:59:19 2008 +0000
+++ b/data/model/AlignmentModel.cpp	Tue Apr 29 15:34:17 2008 +0000
@@ -42,17 +42,28 @@
         
         connect(m_rawPath, SIGNAL(completionChanged()),
                 this, SLOT(pathCompletionChanged()));
+
+        constructPath();
+        constructReversePath();
     }
 
-    constructPath();
-    constructReversePath();
+    if (m_rawPath && m_rawPath->isReady()) {
+        pathCompletionChanged();
+    }
 }
 
 AlignmentModel::~AlignmentModel()
 {
+    if (m_inputModel) m_inputModel->aboutToDelete();
     delete m_inputModel;
+
+    if (m_rawPath) m_rawPath->aboutToDelete();
     delete m_rawPath;
+
+    if (m_path) m_path->aboutToDelete();
     delete m_path;
+
+    if (m_reversePath) m_reversePath->aboutToDelete();
     delete m_reversePath;
 }
 
@@ -157,6 +168,7 @@
 {
     if (m_pathComplete) {
         std::cerr << "AlignmentModel: deleting raw path model" << std::endl;
+        if (m_rawPath) m_rawPath->aboutToDelete();
         delete m_rawPath;
         m_rawPath = 0;
     }
@@ -192,7 +204,8 @@
 
             constructPath();
             constructReversePath();
-
+            
+            if (m_inputModel) m_inputModel->aboutToDelete();
             delete m_inputModel;
             m_inputModel = 0;
         }
@@ -237,6 +250,7 @@
 AlignmentModel::constructReversePath() const
 {
     if (!m_reversePath) {
+/*!!!
         if (!m_rawPath) {
             std::cerr << "ERROR: AlignmentModel::constructReversePath: "
                       << "No raw path available" << std::endl;
@@ -244,12 +258,23 @@
         }
         m_reversePath = new PathModel
             (m_rawPath->getSampleRate(), m_rawPath->getResolution(), false);
+*/
+        if (!m_path) {
+            std::cerr << "ERROR: AlignmentModel::constructReversePath: "
+                      << "No forward path available" << std::endl;
+            return;
+        }
+        m_reversePath = new PathModel
+            (m_path->getSampleRate(), m_path->getResolution(), false);
     } else {
+/*!!!
         if (!m_rawPath) return;
+*/
+        if (!m_path) return;
     }
         
     m_reversePath->clear();
-
+/*!!!
     SparseTimeValueModel::PointList points = m_rawPath->getPoints();
         
     for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
@@ -259,6 +284,16 @@
         long rframe = lrintf(value * m_aligned->getSampleRate());
         m_reversePath->addPoint(PathPoint(rframe, frame));
     }
+*/
+
+    PathModel::PointList points = m_path->getPoints();
+        
+    for (PathModel::PointList::const_iterator i = points.begin();
+         i != points.end(); ++i) {
+        long frame = i->frame;
+        long rframe = i->mapframe;
+        m_reversePath->addPoint(PathPoint(rframe, frame));
+    }
 
 #ifdef DEBUG_ALIGNMENT_MODEL
     std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl;
@@ -333,4 +368,34 @@
 
     return resultFrame;
 }
+
+void
+AlignmentModel::setPath(PathModel *path)
+{
+    if (m_path) m_path->aboutToDelete();
+    delete m_path;
+    m_path = path;
+    constructReversePath();
+}
     
+void
+AlignmentModel::toXml(QTextStream &stream,
+                      QString indent,
+                      QString extraAttributes) const
+{
+    if (!m_path) {
+        std::cerr << "AlignmentModel::toXml: no path" << std::endl;
+        return;
+    }
+
+    m_path->toXml(stream, indent, "");
+
+    Model::toXml(stream, indent,
+                 QString("type=\"alignment\" reference=\"%1\" aligned=\"%2\" path=\"%3\" %4")
+                 .arg(getObjectExportId(m_reference))
+                 .arg(getObjectExportId(m_aligned))
+                 .arg(getObjectExportId(m_path))
+                 .arg(extraAttributes));
+}
+
+