comparison transform/ModelTransformerFactory.cpp @ 850:dba8a02b0413 tonioni_multi_transform

Update the rest of the transforms stuff, so now it builds and runs again
author Chris Cannam
date Mon, 02 Dec 2013 12:29:09 +0000
parents 418cd2064769
children 13803edd513d
comparison
equal deleted inserted replaced
849:418cd2064769 850:dba8a02b0413
32 32
33 #include <iostream> 33 #include <iostream>
34 #include <set> 34 #include <set>
35 35
36 #include <QRegExp> 36 #include <QRegExp>
37
38 using std::vector;
37 39
38 ModelTransformerFactory * 40 ModelTransformerFactory *
39 ModelTransformerFactory::m_instance = new ModelTransformerFactory; 41 ModelTransformerFactory::m_instance = new ModelTransformerFactory;
40 42
41 ModelTransformerFactory * 43 ModelTransformerFactory *
161 163
162 return input; 164 return input;
163 } 165 }
164 166
165 ModelTransformer * 167 ModelTransformer *
166 ModelTransformerFactory::createTransformer(const Transform &transform, 168 ModelTransformerFactory::createTransformer(const Transforms &transforms,
167 const ModelTransformer::Input &input) 169 const ModelTransformer::Input &input)
168 { 170 {
169 ModelTransformer *transformer = 0; 171 ModelTransformer *transformer = 0;
170 172
171 QString id = transform.getPluginIdentifier(); 173 QString id = transforms[0].getPluginIdentifier();
172 174
173 if (FeatureExtractionPluginFactory::instanceFor(id)) { 175 if (FeatureExtractionPluginFactory::instanceFor(id)) {
174 176
175 transformer = 177 transformer =
176 new FeatureExtractionModelTransformer(input, transform); 178 new FeatureExtractionModelTransformer(input, transforms, FeatureExtractionModelTransformer::FlexiNoteOutputModel); //!!! gross
177 179
178 } else if (RealTimePluginFactory::instanceFor(id)) { 180 } else if (RealTimePluginFactory::instanceFor(id)) {
179 181
180 transformer = 182 transformer =
181 new RealTimeEffectModelTransformer(input, transform); 183 new RealTimeEffectModelTransformer(input, transforms[0]);
182 184
183 } else { 185 } else {
184 SVDEBUG << "ModelTransformerFactory::createTransformer: Unknown transform \"" 186 SVDEBUG << "ModelTransformerFactory::createTransformer: Unknown transform \""
185 << transform.getIdentifier() << "\"" << endl; 187 << transforms[0].getIdentifier() << "\"" << endl;
186 return transformer; 188 return transformer;
187 } 189 }
188 190
189 if (transformer) transformer->setObjectName(transform.getIdentifier()); 191 if (transformer) transformer->setObjectName(transforms[0].getIdentifier());
190 return transformer; 192 return transformer;
191 } 193 }
192 194
193 Model * 195 Model *
194 ModelTransformerFactory::transform(const Transform &transform, 196 ModelTransformerFactory::transform(const Transform &transform,
195 const ModelTransformer::Input &input, 197 const ModelTransformer::Input &input,
196 QString &message) 198 QString &message)
197 { 199 {
198 SVDEBUG << "ModelTransformerFactory::transform: Constructing transformer with input model " << input.getModel() << endl; 200 SVDEBUG << "ModelTransformerFactory::transform: Constructing transformer with input model " << input.getModel() << endl;
199 201
200 ModelTransformer *t = createTransformer(transform, input); 202 Transforms transforms;
201 if (!t) return 0; 203 transforms.push_back(transform);
202 204 vector<Model *> mm = transformMultiple(transforms, input, message);
203 connect(t, SIGNAL(finished()), this, SLOT(transformerFinished())); 205 if (mm.empty()) return 0;
204 206 else return mm[0];
205 m_runningTransformers.insert(t);
206
207 t->start();
208 Model *model = t->detachOutputModel();
209
210 if (model) {
211 QString imn = input.getModel()->objectName();
212 QString trn =
213 TransformFactory::getInstance()->getTransformFriendlyName
214 (transform.getIdentifier());
215 if (imn != "") {
216 if (trn != "") {
217 model->setObjectName(tr("%1: %2").arg(imn).arg(trn));
218 } else {
219 model->setObjectName(imn);
220 }
221 } else if (trn != "") {
222 model->setObjectName(trn);
223 }
224 } else {
225 t->wait();
226 }
227
228 message = t->getMessage();
229
230 return model;
231 } 207 }
232 208
233 vector<Model *> 209 vector<Model *>
234 ModelTransformerFactory::transformMultiple(const Transforms &transforms, 210 ModelTransformerFactory::transformMultiple(const Transforms &transforms,
235 const ModelTransformer::Input &input, 211 const ModelTransformer::Input &input,
236 QString &message) 212 QString &message)
237 { 213 {
238 SVDEBUG << "ModelTransformerFactory::transformMultiple: Constructing transformer with input model " << input.getModel() << endl; 214 SVDEBUG << "ModelTransformerFactory::transformMultiple: Constructing transformer with input model " << input.getModel() << endl;
239 215
240 ModelTransformer *t = createTransformer(transforms, input); 216 ModelTransformer *t = createTransformer(transforms, input);
241 if (!t) return 0; 217 if (!t) return vector<Model *>();
242 218
243 connect(t, SIGNAL(finished()), this, SLOT(transformerFinished())); 219 connect(t, SIGNAL(finished()), this, SLOT(transformerFinished()));
244 220
245 m_runningTransformers.insert(t); 221 m_runningTransformers.insert(t);
246 222
247 t->start(); 223 t->start();
248 Model *model = t->detachOutputModel(); 224 vector<Model *> models = t->detachOutputModels();
249 225
250 if (model) { 226 if (!models.empty()) {
251 QString imn = input.getModel()->objectName(); 227 QString imn = input.getModel()->objectName();
252 QString trn = 228 QString trn =
253 TransformFactory::getInstance()->getTransformFriendlyName 229 TransformFactory::getInstance()->getTransformFriendlyName
254 (transform.getIdentifier()); 230 (transforms[0].getIdentifier());
255 if (imn != "") { 231 for (int i = 0; i < models.size(); ++i) {
256 if (trn != "") { 232 if (imn != "") {
257 model->setObjectName(tr("%1: %2").arg(imn).arg(trn)); 233 if (trn != "") {
258 } else { 234 models[i]->setObjectName(tr("%1: %2").arg(imn).arg(trn));
259 model->setObjectName(imn); 235 } else {
236 models[i]->setObjectName(imn);
237 }
238 } else if (trn != "") {
239 models[i]->setObjectName(trn);
260 } 240 }
261 } else if (trn != "") {
262 model->setObjectName(trn);
263 } 241 }
264 } else { 242 } else {
265 t->wait(); 243 t->wait();
266 } 244 }
267 245
268 message = t->getMessage(); 246 message = t->getMessage();
269 247
270 return model; 248 return models;
271 } 249 }
272 250
273 void 251 void
274 ModelTransformerFactory::transformerFinished() 252 ModelTransformerFactory::transformerFinished()
275 { 253 {
304 for (TransformerSet::iterator i = m_runningTransformers.begin(); 282 for (TransformerSet::iterator i = m_runningTransformers.begin();
305 i != m_runningTransformers.end(); ++i) { 283 i != m_runningTransformers.end(); ++i) {
306 284
307 ModelTransformer *t = *i; 285 ModelTransformer *t = *i;
308 286
309 if (t->getInputModel() == m || t->getOutputModel() == m) { 287 if (t->getInputModel() == m) {
310 affected.insert(t); 288 affected.insert(t);
289 } else {
290 vector<Model *> mm = t->getOutputModels();
291 for (int i = 0; i < (int)mm.size(); ++i) {
292 if (mm[i] == m) affected.insert(t);
293 }
311 } 294 }
312 } 295 }
313 296
314 for (TransformerSet::iterator i = affected.begin(); 297 for (TransformerSet::iterator i = affected.begin();
315 i != affected.end(); ++i) { 298 i != affected.end(); ++i) {