# HG changeset patch # User Chris Cannam # Date 1591027989 -3600 # Node ID 699b5b130ea275c089fdd762b497a9a5ca1e20cf # Parent 8280f7a363d1c5bdedd1f97f3f0b844d1ffb5836 Fixes to aligner destruction sequence when re-aligning during alignment; hide debug output behind a flag diff -r 8280f7a363d1 -r 699b5b130ea2 align/Align.cpp --- 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; + 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 diff -r 8280f7a363d1 -r 699b5b130ea2 align/ExternalProgramAligner.cpp --- 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; } diff -r 8280f7a363d1 -r 699b5b130ea2 align/LinearAligner.cpp --- 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); diff -r 8280f7a363d1 -r 699b5b130ea2 align/TransformDTWAligner.cpp --- 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(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 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 s1 = preprocess(refValues); vector 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 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;