# HG changeset patch # User Chris Cannam # Date 1143724691 0 # Node ID 4d59dc469b0f4374524b60e042bbfad8c77f57a7 # Parent ba405e5e69d3f3be7e0ab9b1fef3881527f04c61 * 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) diff -r ba405e5e69d3 -r 4d59dc469b0f transform/FeatureExtractionPluginTransform.cpp --- a/transform/FeatureExtractionPluginTransform.cpp Wed Mar 29 12:35:17 2006 +0000 +++ b/transform/FeatureExtractionPluginTransform.cpp Thu Mar 30 13:18:11 2006 +0000 @@ -29,10 +29,12 @@ FeatureExtractionPluginTransform::FeatureExtractionPluginTransform(Model *inputModel, QString pluginId, + int channel, QString configurationXml, QString outputName) : Transform(inputModel), m_plugin(0), + m_channel(channel), m_descriptor(0), m_outputFeatureNo(0) { @@ -223,7 +225,7 @@ if (channelCount == 1) { got = input->getValues - (-1, blockFrame, blockFrame + blockSize, buffers[0]); + (m_channel, blockFrame, blockFrame + blockSize, buffers[0]); while (got < blockSize) { buffers[0][got++] = 0.0; } diff -r ba405e5e69d3 -r 4d59dc469b0f transform/FeatureExtractionPluginTransform.h --- a/transform/FeatureExtractionPluginTransform.h Wed Mar 29 12:35:17 2006 +0000 +++ b/transform/FeatureExtractionPluginTransform.h Thu Mar 30 13:18:11 2006 +0000 @@ -26,6 +26,7 @@ public: FeatureExtractionPluginTransform(Model *inputModel, QString plugin, + int channel, QString configurationXml = "", QString outputName = ""); virtual ~FeatureExtractionPluginTransform(); @@ -34,6 +35,7 @@ virtual void run(); FeatureExtractionPlugin *m_plugin; + int m_channel; FeatureExtractionPlugin::OutputDescriptor *m_descriptor; int m_outputFeatureNo; diff -r ba405e5e69d3 -r 4d59dc469b0f transform/RealTimePluginTransform.cpp --- a/transform/RealTimePluginTransform.cpp Wed Mar 29 12:35:17 2006 +0000 +++ b/transform/RealTimePluginTransform.cpp Thu Mar 30 13:18:11 2006 +0000 @@ -27,11 +27,13 @@ RealTimePluginTransform::RealTimePluginTransform(Model *inputModel, QString pluginId, + int channel, QString configurationXml, QString units, int output) : Transform(inputModel), m_plugin(0), + m_channel(channel), m_outputNo(output) { std::cerr << "RealTimePluginTransform::RealTimePluginTransform: plugin " << pluginId.toStdString() << ", output " << output << std::endl; @@ -105,6 +107,8 @@ size_t sampleRate = input->getSampleRate(); int channelCount = input->getChannelCount(); + if (m_channel != -1) channelCount = 1; + size_t blockSize = m_plugin->getBufferSize(); float **buffers = m_plugin->getAudioInputBuffers(); @@ -127,7 +131,7 @@ if (channelCount == 1) { got = input->getValues - (-1, blockFrame, blockFrame + blockSize, buffers[0]); + (m_channel, blockFrame, blockFrame + blockSize, buffers[0]); while (got < blockSize) { buffers[0][got++] = 0.0; } diff -r ba405e5e69d3 -r 4d59dc469b0f transform/RealTimePluginTransform.h --- a/transform/RealTimePluginTransform.h Wed Mar 29 12:35:17 2006 +0000 +++ b/transform/RealTimePluginTransform.h Thu Mar 30 13:18:11 2006 +0000 @@ -26,6 +26,7 @@ public: RealTimePluginTransform(Model *inputModel, QString plugin, + int channel, QString configurationXml = "", QString units = "", int output = 0); @@ -35,6 +36,7 @@ virtual void run(); RealTimePluginInstance *m_plugin; + int m_channel; int m_outputNo; // just casts diff -r ba405e5e69d3 -r 4d59dc469b0f transform/TransformFactory.cpp --- a/transform/TransformFactory.cpp Wed Mar 29 12:35:17 2006 +0000 +++ b/transform/TransformFactory.cpp Thu Mar 30 13:18:11 2006 +0000 @@ -23,6 +23,8 @@ #include "widgets/PluginParameterDialog.h" +#include "model/DenseTimeValueModel.h" + #include #include @@ -296,8 +298,44 @@ } bool +TransformFactory::getTransformChannelRange(TransformName name, + int &min, int &max) +{ + QString id = name.section(':', 0, 2); + + if (FeatureExtractionPluginFactory::instanceFor(id)) { + + FeatureExtractionPlugin *plugin = + FeatureExtractionPluginFactory::instanceFor(id)-> + instantiatePlugin(id, 48000); + if (!plugin) return false; + + min = plugin->getMinChannelCount(); + max = plugin->getMaxChannelCount(); + delete plugin; + + return true; + + } else if (RealTimePluginFactory::instanceFor(id)) { + + const RealTimePluginDescriptor *descriptor = + RealTimePluginFactory::instanceFor(id)-> + getPluginDescriptor(id); + if (!descriptor) return false; + + min = descriptor->audioInputPortCount; + max = descriptor->audioInputPortCount; + + return true; + } + + return false; +} + +bool TransformFactory::getConfigurationForTransform(TransformName name, Model *inputModel, + int &channel, QString &configurationXml) { QString id = name.section(':', 0, 2); @@ -325,11 +363,31 @@ if (configurationXml != "") { plugin->setParametersFromXml(configurationXml); } - PluginParameterDialog *dialog = new PluginParameterDialog(plugin); + + int sourceChannels = 1; + if (dynamic_cast(inputModel)) { + sourceChannels = dynamic_cast(inputModel) + ->getChannelCount(); + } + + int minChannels = 1, maxChannels = sourceChannels; + getTransformChannelRange(name, minChannels, maxChannels); + + int targetChannels = sourceChannels; + if (sourceChannels < minChannels) targetChannels = minChannels; + if (sourceChannels > maxChannels) targetChannels = maxChannels; + + int defaultChannel = channel; + + PluginParameterDialog *dialog = new PluginParameterDialog(plugin, + sourceChannels, + targetChannels, + defaultChannel); if (dialog->exec() == QDialog::Accepted) { ok = true; } configurationXml = plugin->toXmlString(); + channel = dialog->getChannel(); delete dialog; delete plugin; } @@ -341,21 +399,25 @@ Transform * TransformFactory::createTransform(TransformName name, Model *inputModel, - QString configurationXml, bool start) + int channel, QString configurationXml, bool start) { Transform *transform = 0; + //!!! use channel + QString id = name.section(':', 0, 2); QString output = name.section(':', 3); if (FeatureExtractionPluginFactory::instanceFor(id)) { transform = new FeatureExtractionPluginTransform(inputModel, id, + channel, configurationXml, output); } else if (RealTimePluginFactory::instanceFor(id)) { transform = new RealTimePluginTransform(inputModel, id, + channel, configurationXml, getTransformUnits(name), output.toInt()); @@ -371,9 +433,10 @@ Model * TransformFactory::transform(TransformName name, Model *inputModel, - QString configurationXml) + int channel, QString configurationXml) { - Transform *t = createTransform(name, inputModel, configurationXml, false); + Transform *t = createTransform(name, inputModel, channel, + configurationXml, false); if (!t) return 0; diff -r ba405e5e69d3 -r 4d59dc469b0f transform/TransformFactory.h --- a/transform/TransformFactory.h Wed Mar 29 12:35:17 2006 +0000 +++ b/transform/TransformFactory.h Thu Mar 30 13:18:11 2006 +0000 @@ -65,6 +65,7 @@ * is acceptable, false if the operation should be cancelled. */ bool getConfigurationForTransform(TransformName name, Model *inputModel, + int &channel, QString &configurationXml); /** @@ -81,7 +82,7 @@ * when no longer needed. */ Model *transform(TransformName name, Model *inputModel, - QString configurationXml = ""); + int channel, QString configurationXml = ""); /** * Full description of a transform, suitable for putting on a menu. @@ -103,6 +104,15 @@ */ bool isTransformConfigurable(TransformName name); + /** + * If the transform has a prescribed number or range of channel + * inputs, return true and set minChannels and maxChannels to the + * minimum and maximum number of channel inputs the transform can + * accept. + */ + bool getTransformChannelRange(TransformName name, + int &minChannels, int &maxChannels); + //!!! Need some way to indicate that the input model has changed / //been deleted so as not to blow up backgrounded transform! -- Or //indeed, if the output model has been deleted -- could equally @@ -115,7 +125,7 @@ protected: Transform *createTransform(TransformName name, Model *inputModel, - QString configurationXml, bool start); + int channel, QString configurationXml, bool start); struct TransformIdent {