changeset 773:699b5b130ea2 pitch-align

Fixes to aligner destruction sequence when re-aligning during alignment; hide debug output behind a flag
author Chris Cannam
date Mon, 01 Jun 2020 17:13:09 +0100
parents 8280f7a363d1
children 32e66fcc4cb7
files align/Align.cpp align/ExternalProgramAligner.cpp align/LinearAligner.cpp align/TransformDTWAligner.cpp
diffstat 4 files changed, 40 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/align/Align.cpp	Mon Jun 01 17:12:12 2020 +0100
+++ b/align/Align.cpp	Mon Jun 01 17:13:09 2020 +0100
@@ -102,6 +102,14 @@
     
     std::shared_ptr<Aligner> aligner;
 
+    if (m_aligners.find(toAlign) != m_aligners.end()) {
+        // We don't want a callback on removeAligner to happen during
+        // our own call to addAligner! Disconnect and delete the old
+        // aligner first
+        disconnect(m_aligners[toAlign].get(), nullptr, this, nullptr);
+        m_aligners.erase(toAlign);
+    }
+    
     {
         // Replace the aligner with a new one. This also stops any
         // previously-running alignment, when the old entry is
--- a/align/ExternalProgramAligner.cpp	Mon Jun 01 17:12:12 2020 +0100
+++ b/align/ExternalProgramAligner.cpp	Mon Jun 01 17:13:09 2020 +0100
@@ -39,6 +39,10 @@
 
 ExternalProgramAligner::~ExternalProgramAligner()
 {
+    if (m_process) {
+        disconnect(m_process, nullptr, this, nullptr);
+    }
+    
     delete m_process;
 }
 
--- a/align/LinearAligner.cpp	Mon Jun 01 17:12:12 2020 +0100
+++ b/align/LinearAligner.cpp	Mon Jun 01 17:13:09 2020 +0100
@@ -106,6 +106,7 @@
     auto alignmentModelId = ModelById::add(alignment);
 
     alignment->setPath(path);
+    alignment->setCompletion(100);
     toAlign->setAlignment(alignmentModelId);
     m_document->addNonDerivedModel(alignmentModelId);
 
--- a/align/TransformDTWAligner.cpp	Mon Jun 01 17:12:12 2020 +0100
+++ b/align/TransformDTWAligner.cpp	Mon Jun 01 17:13:09 2020 +0100
@@ -145,9 +145,11 @@
         return;
     }
 
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
     SVCERR << "TransformDTWAligner[" << this << "]: begin(): transform id "
            << m_transform.getIdentifier()
            << " is running on reference model" << endl;
+#endif
 
     message = "";
 
@@ -159,9 +161,11 @@
         return;
     }
 
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
     SVCERR << "TransformDTWAligner[" << this << "]: begin(): transform id "
            << m_transform.getIdentifier()
            << " is running on toAlign model" << endl;
+#endif
 
     connect(referenceOutputModel.get(), SIGNAL(completionChanged(ModelId)),
             this, SLOT(completionChanged(ModelId)));
@@ -195,10 +199,11 @@
     if (!m_incomplete) {
         return;
     }
-/*
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
     SVCERR << "TransformDTWAligner[" << this << "]: completionChanged: "
            << "model " << id << endl;
-*/
+#endif
+    
     auto referenceOutputModel = ModelById::get(m_referenceOutputModel);
     auto toAlignOutputModel = ModelById::get(m_toAlignOutputModel);
     auto alignmentModel = ModelById::getAs<AlignmentModel>(m_alignmentModel);
@@ -225,11 +230,12 @@
         }
 
     } else {
-/*
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
         SVCERR << "TransformDTWAligner[" << this << "]: completionChanged: "
                << "not ready yet: reference completion " << referenceCompletion
                << ", toAlign completion " << toAlignCompletion << endl;
-*/
+#endif
+        
         int completion = std::min(referenceCompletion,
                                   toAlignCompletion);
         completion = (completion * 94) / 100;
@@ -287,6 +293,8 @@
 {
     Path path(sampleRate, resolution);
 
+    path.add(PathPoint(0, 0));
+    
     for (int i = 0; in_range_for(alignment, i); ++i) {
 
         // DTW returns "the index into s2 for each element in s1"
@@ -338,26 +346,32 @@
         s2.push_back(m_magnitudePreprocessor(v));
     }
 
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
     SVCERR << "TransformDTWAligner[" << this << "]: performAlignmentMagnitude: "
            << "Have " << s1.size() << " events from reference, "
            << s2.size() << " from toAlign" << endl;
+#endif
     
     MagnitudeDTW dtw;
     vector<size_t> alignment;
 
     {
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
         SVCERR << "TransformDTWAligner[" << this
                << "]: serialising DTW to avoid over-allocation" << endl;
+#endif
         QMutexLocker locker(&m_dtwMutex);
         alignment = dtw.alignSeries(s1, s2);
     }
 
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
     SVCERR << "TransformDTWAligner[" << this << "]: performAlignmentMagnitude: "
            << "DTW produced " << alignment.size() << " points:" << endl;
     for (int i = 0; in_range_for(alignment, i) && i < 100; ++i) {
         SVCERR << alignment[i] << " ";
     }
     SVCERR << endl;
+#endif
 
     alignmentModel->setPath(makePath(alignment,
                                      refFrames,
@@ -409,6 +423,7 @@
     vector<RiseFallDTW::Value> s1 = preprocess(refValues);
     vector<RiseFallDTW::Value> s2 = preprocess(otherValues);
 
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
     SVCERR << "TransformDTWAligner[" << this << "]: performAlignmentRiseFall: "
            << "Have " << s1.size() << " events from reference, "
            << s2.size() << " from toAlign" << endl;
@@ -424,23 +439,28 @@
         SVCERR << s2[i] << " ";
     }
     SVCERR << endl;
-
+#endif
+    
     RiseFallDTW dtw;
     vector<size_t> alignment;
 
     {
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
         SVCERR << "TransformDTWAligner[" << this
                << "]: serialising DTW to avoid over-allocation" << endl;
+#endif
         QMutexLocker locker(&m_dtwMutex);
         alignment = dtw.alignSeries(s1, s2);
     }
 
+#ifdef DEBUG_TRANSFORM_DTW_ALIGNER
     SVCERR << "TransformDTWAligner[" << this << "]: performAlignmentRiseFall: "
            << "DTW produced " << alignment.size() << " points:" << endl;
     for (int i = 0; i < alignment.size() && i < 100; ++i) {
         SVCERR << alignment[i] << " ";
     }
     SVCERR << endl;
+#endif
 
     alignmentModel->setPath(makePath(alignment,
                                      refFrames,
@@ -450,8 +470,8 @@
 
     alignmentModel->setCompletion(100);
 
-    SVCERR << "TransformDTWAligner[" << this << "]: performAlignmentRiseFall: Done"
-           << endl;
+    SVCERR << "TransformDTWAligner[" << this
+           << "]: performAlignmentRiseFall: Done" << endl;
 
     m_incomplete = false;
     return true;