comparison framework/Align.cpp @ 702:e4d92aaa689c

Abandon ongoing alignment if asked to re-align before it has completed
author Chris Cannam
date Wed, 14 Aug 2019 13:55:12 +0100
parents e3dc68cc07f9
children 0a43c88cea48 286bd8bb13cc
comparison
equal deleted inserted replaced
701:e3dc68cc07f9 702:e4d92aaa689c
86 TransformId tdId = getTuningDifferenceTransformName(); 86 TransformId tdId = getTuningDifferenceTransformName();
87 return factory->haveTransform(id) && 87 return factory->haveTransform(id) &&
88 (tdId == "" || factory->haveTransform(tdId)); 88 (tdId == "" || factory->haveTransform(tdId));
89 } 89 }
90 90
91 void
92 Align::abandonOngoingAlignment(ModelId otherId)
93 {
94 auto other = ModelById::getAs<RangeSummarisableTimeValueModel>(otherId);
95 if (!other) {
96 return;
97 }
98
99 ModelId alignmentModelId = other->getAlignment();
100 if (alignmentModelId.isNone()) {
101 return;
102 }
103
104 SVCERR << "Align::abandonOngoingAlignment: An alignment is ongoing for model "
105 << otherId << " (alignment model id " << alignmentModelId
106 << "), abandoning it..." << endl;
107
108 other->setAlignment({});
109
110 for (auto pp: m_pendingProcesses) {
111 if (alignmentModelId == pp.second) {
112 QProcess *process = pp.first;
113 m_pendingProcesses.erase(process);
114 SVCERR << "Align::abandonOngoingAlignment: Killing external "
115 << "alignment process " << process << "..." << endl;
116 delete process; // kills the process itself
117 break;
118 }
119 }
120
121 if (m_pendingAlignments.find(alignmentModelId) !=
122 m_pendingAlignments.end()) {
123 SVCERR << "Align::abandonOngoingAlignment: Releasing path output model "
124 << m_pendingAlignments[alignmentModelId]
125 << "..." << endl;
126 ModelById::release(m_pendingAlignments[alignmentModelId]);
127 SVCERR << "Align::abandonOngoingAlignment: Dropping alignment model "
128 << alignmentModelId
129 << " from pending alignments..." << endl;
130 m_pendingAlignments.erase(alignmentModelId);
131 }
132
133 for (auto ptd: m_pendingTuningDiffs) {
134 if (alignmentModelId == ptd.second.alignment) {
135 SVCERR << "Align::abandonOngoingAlignment: Releasing preparatory model "
136 << ptd.second.preparatory << "..." << endl;
137 ModelById::release(ptd.second.preparatory);
138 SVCERR << "Align::abandonOngoingAlignment: Releasing pending tuning-diff model "
139 << ptd.first << "..." << endl;
140 ModelById::release(ptd.first);
141 SVCERR << "Align::abandonOngoingAlignment: Dropping tuning-diff model "
142 << ptd.first
143 << " from pending tuning diffs..." << endl;
144 m_pendingTuningDiffs.erase(ptd.first);
145 break;
146 }
147 }
148
149 SVCERR << "Align::abandonOngoingAlignment: done" << endl;
150 }
151
91 bool 152 bool
92 Align::alignModelViaTransform(Document *doc, 153 Align::alignModelViaTransform(Document *doc,
93 ModelId referenceId, 154 ModelId referenceId,
94 ModelId otherId, 155 ModelId otherId,
95 QString &error) 156 QString &error)
100 ModelById::getAs<RangeSummarisableTimeValueModel>(referenceId); 161 ModelById::getAs<RangeSummarisableTimeValueModel>(referenceId);
101 auto other = 162 auto other =
102 ModelById::getAs<RangeSummarisableTimeValueModel>(otherId); 163 ModelById::getAs<RangeSummarisableTimeValueModel>(otherId);
103 164
104 if (!reference || !other) return false; 165 if (!reference || !other) return false;
105 166
167 // There may be an alignment already happening; we should stop it,
168 // which we can do by discarding the output models for its
169 // transforms
170 abandonOngoingAlignment(otherId);
171
106 // This involves creating a number of new models: 172 // This involves creating a number of new models:
107 // 173 //
108 // 1. an AggregateWaveModel to provide the mixdowns of the main 174 // 1. an AggregateWaveModel to provide the mixdowns of the main
109 // model and the new model in its two channels, as input to the 175 // model and the new model in its two channels, as input to the
110 // MATCH plugin. We just call this one aggregateModel 176 // MATCH plugin. We just call this one aggregateModel
243 309
244 if (m_pendingTuningDiffs.find(tuningDiffOutputModelId) == 310 if (m_pendingTuningDiffs.find(tuningDiffOutputModelId) ==
245 m_pendingTuningDiffs.end()) { 311 m_pendingTuningDiffs.end()) {
246 SVDEBUG << "NOTE: Align::tuningDifferenceCompletionChanged: Model " 312 SVDEBUG << "NOTE: Align::tuningDifferenceCompletionChanged: Model "
247 << tuningDiffOutputModelId 313 << tuningDiffOutputModelId
248 << " not found in pending tuning diff map, probably " 314 << " not found in pending tuning diff map, presuming "
249 << "completed already" << endl; 315 << "completed or abandoned" << endl;
250 return; 316 return;
251 } 317 }
252 318
253 auto tuningDiffOutputModel = 319 auto tuningDiffOutputModel =
254 ModelById::getAs<SparseTimeValueModel>(tuningDiffOutputModelId); 320 ModelById::getAs<SparseTimeValueModel>(tuningDiffOutputModelId);