changeset 1688:901f37d32060

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 0e0947896fd3
children ea1aa24ebf89
files data/model/AggregateWaveModel.cpp data/model/AlignmentModel.cpp data/model/AlignmentModel.h data/model/FFTModel.cpp
diffstat 4 files changed, 12 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/AggregateWaveModel.cpp	Wed Feb 27 12:31:12 2019 +0000
+++ 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 Feb 27 12:31:12 2019 +0000
+++ 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),
@@ -54,9 +52,6 @@
 
 AlignmentModel::~AlignmentModel()
 {
-    if (m_inputModel) m_inputModel->aboutToDelete();
-    delete m_inputModel;
-
     if (m_rawPath) m_rawPath->aboutToDelete();
     delete m_rawPath;
 
@@ -212,9 +207,6 @@
             constructPath();
             constructReversePath();
             
-            if (m_inputModel) m_inputModel->aboutToDelete();
-            delete m_inputModel;
-            m_inputModel = nullptr;
         }
     }
 
--- a/data/model/AlignmentModel.h	Wed Feb 27 12:31:12 2019 +0000
+++ 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;
@@ -72,8 +71,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 Feb 27 12:31:12 2019 +0000
+++ 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) {