Mercurial > hg > svapp
comparison framework/Document.cpp @ 420:662aef012679 alignment_view
Start making it possible to get alignment from an external program (not wired up yet though)
author | Chris Cannam |
---|---|
date | Fri, 14 Nov 2014 17:24:40 +0000 |
parents | 8039c7352ae2 |
children | 33fae747db7e |
comparison
equal
deleted
inserted
replaced
419:8039c7352ae2 | 420:662aef012679 |
---|---|
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #include "Document.h" | 16 #include "Document.h" |
17 | |
18 #include "Align.h" | |
17 | 19 |
18 #include "data/model/WaveFileModel.h" | 20 #include "data/model/WaveFileModel.h" |
19 #include "data/model/WritableWaveFileModel.h" | 21 #include "data/model/WritableWaveFileModel.h" |
20 #include "data/model/DenseThreeDimensionalModel.h" | 22 #include "data/model/DenseThreeDimensionalModel.h" |
21 #include "data/model/DenseTimeValueModel.h" | 23 #include "data/model/DenseTimeValueModel.h" |
1082 SVDEBUG << "Document::alignModel(" << model << "): is main model, setting appropriately" << endl; | 1084 SVDEBUG << "Document::alignModel(" << model << "): is main model, setting appropriately" << endl; |
1083 rm->setAlignment(new AlignmentModel(model, model, 0, 0)); | 1085 rm->setAlignment(new AlignmentModel(model, model, 0, 0)); |
1084 return; | 1086 return; |
1085 } | 1087 } |
1086 | 1088 |
1087 // This involves creating three new models: | 1089 Align a; |
1088 | 1090 if (!a.alignModelViaTransform(m_mainModel, rm)) { |
1089 // 1. an AggregateWaveModel to provide the mixdowns of the main | 1091 cerr << "Alignment failed: " << a.getError() << endl; |
1090 // model and the new model in its two channels, as input to the | 1092 emit alignmentFailed(a.getError()); |
1091 // MATCH plugin | 1093 } |
1092 | |
1093 // 2. a SparseTimeValueModel, which is the model automatically | |
1094 // created by FeatureExtractionPluginTransformer when running the | |
1095 // MATCH plugin (thus containing the alignment path) | |
1096 | |
1097 // 3. an AlignmentModel, which stores the path model and carries | |
1098 // out alignment lookups on it. | |
1099 | |
1100 // The first two of these are provided as arguments to the | |
1101 // constructor for the third, which takes responsibility for | |
1102 // deleting them. The AlignmentModel, meanwhile, is passed to the | |
1103 // new model we are aligning, which also takes responsibility for | |
1104 // it. We should not have to delete any of these new models here. | |
1105 | |
1106 AggregateWaveModel::ChannelSpecList components; | |
1107 | |
1108 components.push_back(AggregateWaveModel::ModelChannelSpec | |
1109 (m_mainModel, -1)); | |
1110 | |
1111 components.push_back(AggregateWaveModel::ModelChannelSpec | |
1112 (rm, -1)); | |
1113 | |
1114 Model *aggregateModel = new AggregateWaveModel(components); | |
1115 ModelTransformer::Input aggregate(aggregateModel); | |
1116 | |
1117 TransformId id = "vamp:match-vamp-plugin:match:path"; //!!! configure | |
1118 | |
1119 TransformFactory *tf = TransformFactory::getInstance(); | |
1120 | |
1121 Transform transform = tf->getDefaultTransformFor | |
1122 (id, aggregateModel->getSampleRate()); | |
1123 | |
1124 transform.setStepSize(transform.getBlockSize()/2); | |
1125 transform.setParameter("serialise", 1); | |
1126 transform.setParameter("smooth", 0); | |
1127 | |
1128 SVDEBUG << "Document::alignModel: Alignment transform step size " << transform.getStepSize() << ", block size " << transform.getBlockSize() << endl; | |
1129 | |
1130 ModelTransformerFactory *mtf = ModelTransformerFactory::getInstance(); | |
1131 | |
1132 QString message; | |
1133 Model *transformOutput = mtf->transform(transform, aggregate, message); | |
1134 | |
1135 if (!transformOutput) { | |
1136 transform.setStepSize(0); | |
1137 transformOutput = mtf->transform(transform, aggregate, message); | |
1138 } | |
1139 | |
1140 SparseTimeValueModel *path = dynamic_cast<SparseTimeValueModel *> | |
1141 (transformOutput); | |
1142 | |
1143 if (!path) { | |
1144 cerr << "Document::alignModel: ERROR: Failed to create alignment path (no MATCH plugin?)" << endl; | |
1145 emit alignmentFailed(id, message); | |
1146 delete transformOutput; | |
1147 delete aggregateModel; | |
1148 return; | |
1149 } | |
1150 | |
1151 path->setCompletion(0); | |
1152 | |
1153 AlignmentModel *alignmentModel = new AlignmentModel | |
1154 (m_mainModel, model, aggregateModel, path); | |
1155 | |
1156 rm->setAlignment(alignmentModel); | |
1157 } | 1094 } |
1158 | 1095 |
1159 void | 1096 void |
1160 Document::alignModels() | 1097 Document::alignModels() |
1161 { | 1098 { |