comparison transform/TransformFactory.cpp @ 64:4d59dc469b0f

* Ensure plugin parameters for a transform are saved in the .sv file and restored in case the plugin has to be run again * Make plugin dialog offer options for mixdown/single-channel use if the file has more than one channels but the plugin only accepts one * Fix incorrect samplerate playback for second file loaded if its samplerate differed from first * Add Zoom to Fit and Select Visible Range menu options, split out Import Audio into main model and secondary model options * Add stubs for cut, copy and paste operations (not implemented yet)
author Chris Cannam
date Thu, 30 Mar 2006 13:18:11 +0000
parents ba405e5e69d3
children 7afcfe666910
comparison
equal deleted inserted replaced
63:ba405e5e69d3 64:4d59dc469b0f
21 #include "plugin/FeatureExtractionPluginFactory.h" 21 #include "plugin/FeatureExtractionPluginFactory.h"
22 #include "plugin/RealTimePluginFactory.h" 22 #include "plugin/RealTimePluginFactory.h"
23 23
24 #include "widgets/PluginParameterDialog.h" 24 #include "widgets/PluginParameterDialog.h"
25 25
26 #include "model/DenseTimeValueModel.h"
27
26 #include <iostream> 28 #include <iostream>
27 #include <set> 29 #include <set>
28 30
29 #include <QRegExp> 31 #include <QRegExp>
30 32
294 return m_transforms[name].configurable; 296 return m_transforms[name].configurable;
295 } else return false; 297 } else return false;
296 } 298 }
297 299
298 bool 300 bool
301 TransformFactory::getTransformChannelRange(TransformName name,
302 int &min, int &max)
303 {
304 QString id = name.section(':', 0, 2);
305
306 if (FeatureExtractionPluginFactory::instanceFor(id)) {
307
308 FeatureExtractionPlugin *plugin =
309 FeatureExtractionPluginFactory::instanceFor(id)->
310 instantiatePlugin(id, 48000);
311 if (!plugin) return false;
312
313 min = plugin->getMinChannelCount();
314 max = plugin->getMaxChannelCount();
315 delete plugin;
316
317 return true;
318
319 } else if (RealTimePluginFactory::instanceFor(id)) {
320
321 const RealTimePluginDescriptor *descriptor =
322 RealTimePluginFactory::instanceFor(id)->
323 getPluginDescriptor(id);
324 if (!descriptor) return false;
325
326 min = descriptor->audioInputPortCount;
327 max = descriptor->audioInputPortCount;
328
329 return true;
330 }
331
332 return false;
333 }
334
335 bool
299 TransformFactory::getConfigurationForTransform(TransformName name, 336 TransformFactory::getConfigurationForTransform(TransformName name,
300 Model *inputModel, 337 Model *inputModel,
338 int &channel,
301 QString &configurationXml) 339 QString &configurationXml)
302 { 340 {
303 QString id = name.section(':', 0, 2); 341 QString id = name.section(':', 0, 2);
304 QString output = name.section(':', 3); 342 QString output = name.section(':', 3);
305 343
323 361
324 if (plugin) { 362 if (plugin) {
325 if (configurationXml != "") { 363 if (configurationXml != "") {
326 plugin->setParametersFromXml(configurationXml); 364 plugin->setParametersFromXml(configurationXml);
327 } 365 }
328 PluginParameterDialog *dialog = new PluginParameterDialog(plugin); 366
367 int sourceChannels = 1;
368 if (dynamic_cast<DenseTimeValueModel *>(inputModel)) {
369 sourceChannels = dynamic_cast<DenseTimeValueModel *>(inputModel)
370 ->getChannelCount();
371 }
372
373 int minChannels = 1, maxChannels = sourceChannels;
374 getTransformChannelRange(name, minChannels, maxChannels);
375
376 int targetChannels = sourceChannels;
377 if (sourceChannels < minChannels) targetChannels = minChannels;
378 if (sourceChannels > maxChannels) targetChannels = maxChannels;
379
380 int defaultChannel = channel;
381
382 PluginParameterDialog *dialog = new PluginParameterDialog(plugin,
383 sourceChannels,
384 targetChannels,
385 defaultChannel);
329 if (dialog->exec() == QDialog::Accepted) { 386 if (dialog->exec() == QDialog::Accepted) {
330 ok = true; 387 ok = true;
331 } 388 }
332 configurationXml = plugin->toXmlString(); 389 configurationXml = plugin->toXmlString();
390 channel = dialog->getChannel();
333 delete dialog; 391 delete dialog;
334 delete plugin; 392 delete plugin;
335 } 393 }
336 394
337 if (ok) m_lastConfigurations[name] = configurationXml; 395 if (ok) m_lastConfigurations[name] = configurationXml;
339 return ok; 397 return ok;
340 } 398 }
341 399
342 Transform * 400 Transform *
343 TransformFactory::createTransform(TransformName name, Model *inputModel, 401 TransformFactory::createTransform(TransformName name, Model *inputModel,
344 QString configurationXml, bool start) 402 int channel, QString configurationXml, bool start)
345 { 403 {
346 Transform *transform = 0; 404 Transform *transform = 0;
347 405
406 //!!! use channel
407
348 QString id = name.section(':', 0, 2); 408 QString id = name.section(':', 0, 2);
349 QString output = name.section(':', 3); 409 QString output = name.section(':', 3);
350 410
351 if (FeatureExtractionPluginFactory::instanceFor(id)) { 411 if (FeatureExtractionPluginFactory::instanceFor(id)) {
352 transform = new FeatureExtractionPluginTransform(inputModel, 412 transform = new FeatureExtractionPluginTransform(inputModel,
353 id, 413 id,
414 channel,
354 configurationXml, 415 configurationXml,
355 output); 416 output);
356 } else if (RealTimePluginFactory::instanceFor(id)) { 417 } else if (RealTimePluginFactory::instanceFor(id)) {
357 transform = new RealTimePluginTransform(inputModel, 418 transform = new RealTimePluginTransform(inputModel,
358 id, 419 id,
420 channel,
359 configurationXml, 421 configurationXml,
360 getTransformUnits(name), 422 getTransformUnits(name),
361 output.toInt()); 423 output.toInt());
362 } else { 424 } else {
363 std::cerr << "TransformFactory::createTransform: Unknown transform " 425 std::cerr << "TransformFactory::createTransform: Unknown transform "
369 return transform; 431 return transform;
370 } 432 }
371 433
372 Model * 434 Model *
373 TransformFactory::transform(TransformName name, Model *inputModel, 435 TransformFactory::transform(TransformName name, Model *inputModel,
374 QString configurationXml) 436 int channel, QString configurationXml)
375 { 437 {
376 Transform *t = createTransform(name, inputModel, configurationXml, false); 438 Transform *t = createTransform(name, inputModel, channel,
439 configurationXml, false);
377 440
378 if (!t) return 0; 441 if (!t) return 0;
379 442
380 connect(t, SIGNAL(finished()), this, SLOT(transformFinished())); 443 connect(t, SIGNAL(finished()), this, SLOT(transformFinished()));
381 444