changeset 664:06db8f3ceb95 single-point

Update so Document owns the alignment model's input aggregate model, just as any other model
author Chris Cannam
date Thu, 04 Apr 2019 11:16:29 +0100
parents 351b1302064e
children 21673429dba5
files framework/Align.cpp framework/Align.h framework/Document.cpp framework/SVFileReader.cpp
diffstat 4 files changed, 40 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/framework/Align.cpp	Tue Apr 02 14:45:57 2019 +0100
+++ b/framework/Align.cpp	Thu Apr 04 11:16:29 2019 +0100
@@ -14,6 +14,7 @@
 */
 
 #include "Align.h"
+#include "Document.h"
 
 #include "data/model/WaveFileModel.h"
 #include "data/model/ReadOnlyWaveFileModel.h"
@@ -33,7 +34,7 @@
 #include <QApplication>
 
 bool
-Align::alignModel(Model *ref, Model *other)
+Align::alignModel(Document *doc, Model *ref, Model *other)
 {
     QSettings settings;
     settings.beginGroup("Preferences");
@@ -42,9 +43,9 @@
     settings.endGroup();
 
     if (useProgram && (program != "")) {
-        return alignModelViaProgram(ref, other, program);
+        return alignModelViaProgram(doc, ref, other, program);
     } else {
-        return alignModelViaTransform(ref, other);
+        return alignModelViaTransform(doc, ref, other);
     }
 }
 
@@ -69,7 +70,7 @@
 }
 
 bool
-Align::alignModelViaTransform(Model *ref, Model *other)
+Align::alignModelViaTransform(Document *doc, Model *ref, Model *other)
 {
     RangeSummarisableTimeValueModel *reference = qobject_cast
         <RangeSummarisableTimeValueModel *>(ref);
@@ -106,7 +107,9 @@
     components.push_back(AggregateWaveModel::ModelChannelSpec
                          (rm, -1));
 
-    Model *aggregateModel = new AggregateWaveModel(components);
+    AggregateWaveModel *aggregateModel = new AggregateWaveModel(components);
+    doc->addAggregateModel(aggregateModel);
+    
     ModelTransformer::Input aggregate(aggregateModel);
 
     TransformId id = getAlignmentTransformName();
@@ -146,7 +149,7 @@
     path->setCompletion(0);
 
     AlignmentModel *alignmentModel = new AlignmentModel
-        (reference, other, aggregateModel, path);
+        (reference, other, path);
 
     connect(alignmentModel, SIGNAL(completionChanged()),
             this, SLOT(alignmentCompletionChanged()));
@@ -169,7 +172,7 @@
 }
 
 bool
-Align::alignModelViaProgram(Model *ref, Model *other, QString program)
+Align::alignModelViaProgram(Document *, Model *ref, Model *other, QString program)
 {
     WaveFileModel *reference = qobject_cast<WaveFileModel *>(ref);
     WaveFileModel *rm = qobject_cast<WaveFileModel *>(other);
@@ -204,7 +207,7 @@
     m_error = "";
     
     AlignmentModel *alignmentModel =
-        new AlignmentModel(reference, other, nullptr, nullptr);
+        new AlignmentModel(reference, other, nullptr);
     rm->setAlignment(alignmentModel);
 
     QProcess *process = new QProcess;
--- a/framework/Align.h	Tue Apr 02 14:45:57 2019 +0100
+++ b/framework/Align.h	Thu Apr 04 11:16:29 2019 +0100
@@ -23,6 +23,7 @@
 
 class Model;
 class AlignmentModel;
+class Document;
 
 class Align : public QObject
 {
@@ -47,10 +48,18 @@
      * Align object will simply share the process or document
      * lifespan.
      */
-    bool alignModel(Model *reference, Model *other); // via user preference
+    bool alignModel(Document *doc,
+                    Model *reference,
+                    Model *other); // via user preference
     
-    bool alignModelViaTransform(Model *reference, Model *other);
-    bool alignModelViaProgram(Model *reference, Model *other, QString program);
+    bool alignModelViaTransform(Document *doc,
+                                Model *reference,
+                                Model *other);
+
+    bool alignModelViaProgram(Document *doc,
+                              Model *reference,
+                              Model *other,
+                              QString program);
 
     /**
      * Return true if the alignment facility is available (relevant
--- a/framework/Document.cpp	Tue Apr 02 14:45:57 2019 +0100
+++ b/framework/Document.cpp	Thu Apr 04 11:16:29 2019 +0100
@@ -434,7 +434,7 @@
     SVDEBUG << "Models now: ";
     for (const auto &r: m_models) {
         SVDEBUG << r.model << " ";
-    } 
+    }
     SVDEBUG << endl;
     SVDEBUG << "Old main model: " << oldMainModel << endl;
 #endif
@@ -791,6 +791,12 @@
         return;
     }
 
+#ifdef DEBUG_DOCUMENT
+    SVDEBUG << "Document::releaseModel(" << model << ", type "
+            << model->getTypeName() << ", name \""
+            << model->objectName() << "\")" << endl;
+#endif
+    
     if (model == m_mainModel) {
         return;
     }
@@ -804,12 +810,17 @@
             SVCERR << "WARNING: Document::releaseModel: model " << model
                    << " reference count is zero already!" << endl;
         } else {
+#ifdef DEBUG_DOCUMENT
+            SVDEBUG << "Lowering refcount from " << mitr->refcount << endl;
+#endif
             if (--mitr->refcount == 0) {
                 toDelete = true;
             }
         }
     } else if (m_aggregateModels.find(model) != m_aggregateModels.end()) {
+#ifdef DEBUG_DOCUMENT
         SVDEBUG << "Document::releaseModel: is an aggregate model" << endl;
+#endif
         toDelete = true;
     } else { 
         SVCERR << "WARNING: Document::releaseModel: Unfound model "
@@ -889,14 +900,14 @@
     }
     if (!found) {
         SVDEBUG << "Document::deleteLayer: Layer "
-                  << layer << " (" << typeid(layer).name() <<
+                  << layer << " (typeid " << typeid(layer).name() <<
                   ") does not exist, or has already been deleted "
                   << "(this may not be as serious as it sounds)" << endl;
         return;
     }
 
 #ifdef DEBUG_DOCUMENT
-    SVDEBUG << "Document::deleteLayer: Removing, now have "
+    SVDEBUG << "Document::deleteLayer: Removing (and about to release model), now have "
               << m_layers.size() << " layers" << endl;
 #endif
 
@@ -1115,11 +1126,11 @@
         // unaligned model just by looking at the model itself,
         // without also knowing what the main model is
         SVDEBUG << "Document::alignModel(" << model << "): is main model, setting appropriately" << endl;
-        rm->setAlignment(new AlignmentModel(model, model, nullptr, nullptr));
+        rm->setAlignment(new AlignmentModel(model, model, nullptr));
         return;
     }
 
-    if (!m_align->alignModel(m_mainModel, rm)) {
+    if (!m_align->alignModel(this, m_mainModel, rm)) {
         SVCERR << "Alignment failed: " << m_align->getError() << endl;
         emit alignmentFailed(m_align->getError());
     }
--- a/framework/SVFileReader.cpp	Tue Apr 02 14:45:57 2019 +0100
+++ b/framework/SVFileReader.cpp	Thu Apr 04 11:16:29 2019 +0100
@@ -792,7 +792,7 @@
 
         if (refModel && alignedModel && pathModel) {
             AlignmentModel *model = new AlignmentModel
-                (refModel, alignedModel, nullptr, nullptr);
+                (refModel, alignedModel, nullptr);
             PathModel *pm = dynamic_cast<PathModel *>(pathModel);
             if (!pm) {
                 SVCERR << "WARNING: SV-XML: Model id " << path