Mercurial > hg > svapp
comparison align/TransformAligner.cpp @ 768:1b1960009be6 pitch-align
Provide callback for output preprocessing before DTW, use it for freq-pitch conversion; use direct setting of completion on alignment models instead of creating fake outputs for completion only
| author | Chris Cannam | 
|---|---|
| date | Fri, 22 May 2020 17:17:44 +0100 | 
| parents | dd742e566e60 | 
| children | a316cb6fed81 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 767:dd742e566e60 | 768:1b1960009be6 | 
|---|---|
| 48 if (other) { | 48 if (other) { | 
| 49 other->setAlignment({}); | 49 other->setAlignment({}); | 
| 50 } | 50 } | 
| 51 } | 51 } | 
| 52 | 52 | 
| 53 ModelById::release(m_tuningDiffProgressModel); | |
| 54 ModelById::release(m_tuningDiffOutputModel); | 53 ModelById::release(m_tuningDiffOutputModel); | 
| 55 ModelById::release(m_pathOutputModel); | 54 ModelById::release(m_pathOutputModel); | 
| 56 } | 55 } | 
| 57 | 56 | 
| 58 QString | 57 QString | 
| 115 // 2b. a SparseTimeValueModel which will be automatically created | 114 // 2b. a SparseTimeValueModel which will be automatically created | 
| 116 // by FeatureExtractionPluginTransformer when running the MATCH | 115 // by FeatureExtractionPluginTransformer when running the MATCH | 
| 117 // plugin to perform alignment (so containing the alignment path). | 116 // plugin to perform alignment (so containing the alignment path). | 
| 118 // This is m_pathOutputModel. | 117 // This is m_pathOutputModel. | 
| 119 // | 118 // | 
| 120 // 2c. a SparseTimeValueModel used solely to provide faked | |
| 121 // completion information to the AlignmentModel while a | |
| 122 // TuningDifference calculation is going on. We call this | |
| 123 // m_tuningDiffProgressModel. | |
| 124 // | |
| 125 // 3. an AlignmentModel, which stores the path and carries out | 119 // 3. an AlignmentModel, which stores the path and carries out | 
| 126 // alignment lookups on it. This one is m_alignmentModel. | 120 // alignment lookups on it. This one is m_alignmentModel. | 
| 127 // | 121 // | 
| 128 // Models 1 and 3 are registered with the document, which will | 122 // Models 1 and 3 are registered with the document, which will | 
| 129 // eventually release them. We don't release them here except in | 123 // eventually release them. We don't release them here except in | 
| 130 // the case where an activity fails before the point where we | 124 // the case where an activity fails before the point where we | 
| 131 // would otherwise have registered them with the document. | 125 // would otherwise have registered them with the document. | 
| 132 // | 126 // | 
| 133 // Models 2a (m_tuningDiffOutputModel), 2b (m_pathOutputModel) and | 127 // Models 2a (m_tuningDiffOutputModel) and 2b (m_pathOutputModel) | 
| 134 // 2c (m_tuningDiffProgressModel) are not registered with the | 128 // are not registered with the document, because they are not | 
| 135 // document, because they are not intended to persist, and also | 129 // intended to persist. These have to be released by us when | 
| 136 // Model 2c (m_tuningDiffProgressModel) is a bodge that we are | |
| 137 // embarrassed about, so we try to manage it ourselves without | |
| 138 // anyone else noticing. These have to be released by us when | |
| 139 // finished with, but their lifespans do not extend beyond the end | 130 // finished with, but their lifespans do not extend beyond the end | 
| 140 // of the alignment procedure, so this should be ok. | 131 // of the alignment procedure, so this should be ok. | 
| 141 | 132 | 
| 142 AggregateWaveModel::ChannelSpecList components; | 133 AggregateWaveModel::ChannelSpecList components; | 
| 143 components.push_back | 134 components.push_back | 
| 207 m_document->addNonDerivedModel(m_alignmentModel); | 198 m_document->addNonDerivedModel(m_alignmentModel); | 
| 208 | 199 | 
| 209 connect(tuningDiffOutputModel.get(), | 200 connect(tuningDiffOutputModel.get(), | 
| 210 SIGNAL(completionChanged(ModelId)), | 201 SIGNAL(completionChanged(ModelId)), | 
| 211 this, SLOT(tuningDifferenceCompletionChanged(ModelId))); | 202 this, SLOT(tuningDifferenceCompletionChanged(ModelId))); | 
| 212 | |
| 213 // This model exists only so that the AlignmentModel can get a | |
| 214 // completion value from somewhere while the tuning difference | |
| 215 // calculation is going on | |
| 216 auto progressModel = std::make_shared<SparseTimeValueModel> | |
| 217 (aggregateModel->getSampleRate(), 1); | |
| 218 m_tuningDiffProgressModel = ModelById::add(progressModel); | |
| 219 progressModel->setCompletion(0); | |
| 220 alignmentModel->setPathFrom(m_tuningDiffProgressModel); | |
| 221 } | 203 } | 
| 222 } | 204 } | 
| 223 | 205 | 
| 224 void | 206 void | 
| 225 TransformAligner::tuningDifferenceCompletionChanged(ModelId tuningDiffOutputModelId) | 207 TransformAligner::tuningDifferenceCompletionChanged(ModelId tuningDiffOutputModelId) | 
| 264 // This will be the completion the alignment model reports, | 246 // This will be the completion the alignment model reports, | 
| 265 // before the alignment actually begins. It goes up from 0 to | 247 // before the alignment actually begins. It goes up from 0 to | 
| 266 // 99 (not 100!) and then back to 0 again when we start | 248 // 99 (not 100!) and then back to 0 again when we start | 
| 267 // calculating the actual path in the following phase | 249 // calculating the actual path in the following phase | 
| 268 int clamped = (completion == 100 ? 99 : completion); | 250 int clamped = (completion == 100 ? 99 : completion); | 
| 269 auto progressModel = | 251 alignmentModel->setCompletion(clamped); | 
| 270 ModelById::getAs<SparseTimeValueModel>(m_tuningDiffProgressModel); | |
| 271 if (progressModel) { | |
| 272 progressModel->setCompletion(clamped); | |
| 273 } | |
| 274 return; | 252 return; | 
| 275 } | 253 } | 
| 276 | 254 | 
| 277 m_tuningFrequency = 440.f; | 255 m_tuningFrequency = 440.f; | 
| 278 | 256 | 
| 284 } | 262 } | 
| 285 | 263 | 
| 286 ModelById::release(tuningDiffOutputModel); | 264 ModelById::release(tuningDiffOutputModel); | 
| 287 m_tuningDiffOutputModel = {}; | 265 m_tuningDiffOutputModel = {}; | 
| 288 | 266 | 
| 289 alignmentModel->setPathFrom({}); // replace m_tuningDiffProgressModel | |
| 290 ModelById::release(m_tuningDiffProgressModel); | |
| 291 m_tuningDiffProgressModel = {}; | |
| 292 | |
| 293 beginAlignmentPhase(); | 267 beginAlignmentPhase(); | 
| 294 } | 268 } | 
| 295 | 269 | 
| 296 bool | 270 bool | 
| 297 TransformAligner::beginAlignmentPhase() | 271 TransformAligner::beginAlignmentPhase() | 
