comparison align/TransformAligner.cpp @ 761:6429a164b7e1 pitch-align

Schedule alignments with a small delay to avoid too much UI unresponsiveness. Also overhaul error reporting to use signals throughout.
author Chris Cannam
date Wed, 06 May 2020 11:45:27 +0100
parents 31289e8592c7
children dd742e566e60
comparison
equal deleted inserted replaced
757:f32df46d0c84 761:6429a164b7e1
91 TransformId tdId = getTuningDifferenceTransformName(); 91 TransformId tdId = getTuningDifferenceTransformName();
92 return factory->haveTransform(id) && 92 return factory->haveTransform(id) &&
93 (tdId == "" || factory->haveTransform(tdId)); 93 (tdId == "" || factory->haveTransform(tdId));
94 } 94 }
95 95
96 bool 96 void
97 TransformAligner::begin(QString &error) 97 TransformAligner::begin()
98 { 98 {
99 auto reference = 99 auto reference =
100 ModelById::getAs<RangeSummarisableTimeValueModel>(m_reference); 100 ModelById::getAs<RangeSummarisableTimeValueModel>(m_reference);
101 auto other = 101 auto other =
102 ModelById::getAs<RangeSummarisableTimeValueModel>(m_toAlign); 102 ModelById::getAs<RangeSummarisableTimeValueModel>(m_toAlign);
103 103
104 if (!reference || !other) return false; 104 if (!reference || !other) return;
105 105
106 // This involves creating a number of new models: 106 // This involves creating a number of new models:
107 // 107 //
108 // 1. an AggregateWaveModel to provide the mixdowns of the main 108 // 1. an AggregateWaveModel to provide the mixdowns of the main
109 // model and the new model in its two channels, as input to the 109 // model and the new model in its two channels, as input to the
163 163
164 if (beginAlignmentPhase()) { 164 if (beginAlignmentPhase()) {
165 other->setAlignment(m_alignmentModel); 165 other->setAlignment(m_alignmentModel);
166 m_document->addNonDerivedModel(m_alignmentModel); 166 m_document->addNonDerivedModel(m_alignmentModel);
167 } else { 167 } else {
168 error = alignmentModel->getError(); 168 QString error = alignmentModel->getError();
169 ModelById::release(alignmentModel); 169 ModelById::release(alignmentModel);
170 return false; 170 emit failed(m_toAlign, error);
171 return;
171 } 172 }
172 173
173 } else { 174 } else {
174 175
175 // Have a tuning-difference transform id, so run it 176 // Have a tuning-difference transform id, so run it
195 196
196 auto tuningDiffOutputModel = 197 auto tuningDiffOutputModel =
197 ModelById::getAs<SparseTimeValueModel>(m_tuningDiffOutputModel); 198 ModelById::getAs<SparseTimeValueModel>(m_tuningDiffOutputModel);
198 if (!tuningDiffOutputModel) { 199 if (!tuningDiffOutputModel) {
199 SVCERR << "Align::alignModel: ERROR: Failed to create tuning-difference output model (no Tuning Difference plugin?)" << endl; 200 SVCERR << "Align::alignModel: ERROR: Failed to create tuning-difference output model (no Tuning Difference plugin?)" << endl;
200 error = message;
201 ModelById::release(alignmentModel); 201 ModelById::release(alignmentModel);
202 return false; 202 emit failed(m_toAlign, message);
203 return;
203 } 204 }
204 205
205 other->setAlignment(m_alignmentModel); 206 other->setAlignment(m_alignmentModel);
206 m_document->addNonDerivedModel(m_alignmentModel); 207 m_document->addNonDerivedModel(m_alignmentModel);
207 208
216 (aggregateModel->getSampleRate(), 1); 217 (aggregateModel->getSampleRate(), 1);
217 m_tuningDiffProgressModel = ModelById::add(progressModel); 218 m_tuningDiffProgressModel = ModelById::add(progressModel);
218 progressModel->setCompletion(0); 219 progressModel->setCompletion(0);
219 alignmentModel->setPathFrom(m_tuningDiffProgressModel); 220 alignmentModel->setPathFrom(m_tuningDiffProgressModel);
220 } 221 }
221
222 return true;
223 } 222 }
224 223
225 void 224 void
226 TransformAligner::tuningDifferenceCompletionChanged(ModelId tuningDiffOutputModelId) 225 TransformAligner::tuningDifferenceCompletionChanged(ModelId tuningDiffOutputModelId)
227 { 226 {
227 if (m_tuningDiffOutputModel.isNone()) {
228 // we're done, this is probably a spurious queued event
229 return;
230 }
231
228 if (tuningDiffOutputModelId != m_tuningDiffOutputModel) { 232 if (tuningDiffOutputModelId != m_tuningDiffOutputModel) {
229 SVCERR << "WARNING: TransformAligner::tuningDifferenceCompletionChanged: Model " 233 SVCERR << "WARNING: TransformAligner::tuningDifferenceCompletionChanged: Model "
230 << tuningDiffOutputModelId 234 << tuningDiffOutputModelId
231 << " is not ours! (ours is " 235 << " is not ours! (ours is "
232 << m_tuningDiffOutputModel << ")" << endl; 236 << m_tuningDiffOutputModel << ")" << endl;
250 } 254 }
251 255
252 int completion = 0; 256 int completion = 0;
253 bool done = tuningDiffOutputModel->isReady(&completion); 257 bool done = tuningDiffOutputModel->isReady(&completion);
254 258
259 SVDEBUG << "TransformAligner::tuningDifferenceCompletionChanged: model "
260 << m_tuningDiffOutputModel << ", completion = " << completion
261 << ", done = " << done << endl;
262
255 if (!done) { 263 if (!done) {
256 // This will be the completion the alignment model reports, 264 // This will be the completion the alignment model reports,
257 // before the alignment actually begins. It goes up from 0 to 265 // before the alignment actually begins. It goes up from 0 to
258 // 99 (not 100!) and then back to 0 again when we start 266 // 99 (not 100!) and then back to 0 again when we start
259 // calculating the actual path in the following phase 267 // calculating the actual path in the following phase