changeset 1686:e73baeead27f single-point

Model deletion issues - the AlignmentModel doesn't actually need to know about the input aggregate model; the document should own it instead
author Chris Cannam
date Thu, 04 Apr 2019 11:15:43 +0100
parents 0e9840a381b5
children 1bbea26ea21a
files data/model/AggregateWaveModel.cpp data/model/AlignmentModel.cpp data/model/AlignmentModel.h data/model/FFTModel.cpp
diffstat 4 files changed, 13 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/AggregateWaveModel.cpp	Wed Apr 03 16:19:20 2019 +0100
+++ b/data/model/AggregateWaveModel.cpp	Thu Apr 04 11:15:43 2019 +0100
@@ -46,6 +46,7 @@
 
 AggregateWaveModel::~AggregateWaveModel()
 {
+    SVDEBUG << "AggregateWaveModel::~AggregateWaveModel" << endl;
 }
 
 void
@@ -61,7 +62,7 @@
 bool
 AggregateWaveModel::isOK() const
 {
-    if (m_invalidated) {
+    if (m_invalidated || m_components.empty()) {
         return false;
     }
     for (ChannelSpecList::const_iterator i = m_components.begin();
@@ -120,13 +121,15 @@
 sv_samplerate_t
 AggregateWaveModel::getSampleRate() const
 {
-    if (m_components.empty()) return 0;
+    if (m_invalidated || m_components.empty()) return 0;
     return m_components.begin()->model->getSampleRate();
 }
 
 floatvec_t
 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
 {
+    if (m_invalidated || m_components.empty()) return {};
+    
     int ch0 = channel, ch1 = channel;
     if (channel == -1) {
         ch0 = 0;
--- a/data/model/AlignmentModel.cpp	Wed Apr 03 16:19:20 2019 +0100
+++ b/data/model/AlignmentModel.cpp	Thu Apr 04 11:15:43 2019 +0100
@@ -21,11 +21,9 @@
 
 AlignmentModel::AlignmentModel(Model *reference,
                                Model *aligned,
-                               Model *inputModel,
                                SparseTimeValueModel *path) :
     m_reference(reference),
     m_aligned(aligned),
-    m_inputModel(inputModel),
     m_rawPath(path),
     m_path(nullptr),
     m_reversePath(nullptr),
@@ -55,9 +53,6 @@
 AlignmentModel::~AlignmentModel()
 {
     SVDEBUG << "AlignmentModel(" << this << ")::~AlignmentModel()" << endl;
-    
-    if (m_inputModel) m_inputModel->aboutToDelete();
-    delete m_inputModel;
 
     if (m_rawPath) m_rawPath->aboutToDelete();
     delete m_rawPath;
@@ -214,10 +209,7 @@
             constructPath();
             constructReversePath();
 
-            SVDEBUG << "AlignmentModel: path complete, deleting input" << endl;
-            if (m_inputModel) m_inputModel->aboutToDelete();
-            delete m_inputModel;
-            m_inputModel = nullptr;
+            SVDEBUG << "AlignmentModel: path complete" << endl;
         }
     }
 
--- a/data/model/AlignmentModel.h	Wed Apr 03 16:19:20 2019 +0100
+++ b/data/model/AlignmentModel.h	Thu Apr 04 11:15:43 2019 +0100
@@ -32,8 +32,7 @@
 public:
     AlignmentModel(Model *reference,
                    Model *aligned,
-                   Model *inputModel, // probably an AggregateWaveModel; may be null; I take ownership
-                   SparseTimeValueModel *path); // I take ownership
+                   SparseTimeValueModel *path);
     ~AlignmentModel();
 
     bool isOK() const override;
@@ -82,8 +81,6 @@
     Model *m_reference; // I don't own this
     Model *m_aligned; // I don't own this
 
-    Model *m_inputModel; // I own this
-
     SparseTimeValueModel *m_rawPath; // I own this
     mutable PathModel *m_path; // I own this
     mutable PathModel *m_reversePath; // I own this
--- a/data/model/FFTModel.cpp	Wed Apr 03 16:19:20 2019 +0100
+++ b/data/model/FFTModel.cpp	Thu Apr 04 11:15:43 2019 +0100
@@ -61,9 +61,12 @@
 
     m_fft.initFloat();
 
-    connect(model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
+    connect(model, SIGNAL(modelChanged()),
+            this, SIGNAL(modelChanged()));
     connect(model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
             this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)));
+    connect(model, SIGNAL(aboutToBeDeleted()),
+            this, SLOT(sourceModelAboutToBeDeleted()));
 }
 
 FFTModel::~FFTModel()
@@ -273,6 +276,8 @@
 FFTModel::getSourceDataUncached(pair<sv_frame_t, sv_frame_t> range) const
 {
     Profiler profiler("FFTModel::getSourceDataUncached");
+
+    if (!m_model) return {};
     
     decltype(range.first) pfx = 0;
     if (range.first < 0) {