17 #include "transform/TransformFactory.h" 19 #include "widgets/PluginParameterDialog.h" 21 #include "plugin/FeatureExtractionPluginFactory.h" 22 #include "plugin/RealTimePluginFactory.h" 23 #include "plugin/RealTimePluginInstance.h" 25 #include "data/model/DenseTimeValueModel.h" 27 #include <vamp-hostsdk/Plugin.h> 29 #include <QStringList> 43 std::shared_ptr<Vamp::PluginBase> plugin,
44 int &minChannels,
int &maxChannels)
46 if (plugin && plugin->getType() ==
"Feature Extraction Plugin") {
47 auto vp = std::dynamic_pointer_cast<Vamp::Plugin>(plugin);
49 SVDEBUG <<
"TransformUserConfigurator::getChannelRange: is a Vamp plugin" << endl;
50 minChannels = int(vp->getMinChannelCount());
51 maxChannels = int(vp->getMaxChannelCount());
54 SVCERR <<
"TransformUserConfigurator::getChannelRange: inconsistent plugin identity!" << endl;
58 SVDEBUG <<
"TransformUserConfigurator::getChannelRange: is not a Vamp plugin" << endl;
59 return TransformFactory::getInstance()->
60 getTransformChannelRange(identifier, minChannels, maxChannels);
67 std::shared_ptr<Vamp::PluginBase> plugin,
69 AudioPlaySource *source,
70 sv_frame_t startFrame,
72 const QMap<QString, ModelId> &modelMap,
73 QStringList candidateModelNames,
74 QString defaultModelName)
77 QString
id = transform.getPluginIdentifier();
78 QString output = transform.getOutput();
79 QString outputLabel =
"";
80 QString outputDescription =
"";
82 bool frequency =
false;
84 bool generator =
false;
86 if (!plugin)
return false;
88 SVDEBUG <<
"TransformUserConfigurator::configure: identifier " <<
id << endl;
90 if (RealTimePluginFactory::instanceFor(
id)) {
92 RealTimePluginFactory *factory = RealTimePluginFactory::instanceFor(
id);
93 RealTimePluginDescriptor desc = factory->getPluginDescriptor(
id);
95 if (desc.audioInputPortCount > 0 &&
96 desc.audioOutputPortCount > 0 &&
101 if (desc.audioInputPortCount == 0) {
106 int outputNo = output.toInt();
107 if (outputNo >= 0 && outputNo <
int(desc.controlOutputPortCount)) {
108 outputLabel = desc.controlOutputPortNames[outputNo].c_str();
112 auto auditionable = std::dynamic_pointer_cast<Auditionable>(plugin);
114 if (effect && source && auditionable) {
115 SVDEBUG <<
"Setting auditioning effect" << endl;
116 source->setAuditioningEffect(auditionable);
121 auto vp = std::dynamic_pointer_cast<Vamp::Plugin>(plugin);
123 frequency = (vp->getInputDomain() == Vamp::Plugin::FrequencyDomain);
125 std::vector<Vamp::Plugin::OutputDescriptor> od =
126 vp->getOutputDescriptors();
129 for (
size_t i = 0; i < od.size(); ++i) {
130 if (od[i].identifier == output.toStdString()) {
131 outputLabel = od[i].name.c_str();
132 outputDescription = od[i].description.c_str();
139 int sourceChannels = 1;
141 if (
auto dtvm = ModelById::getAs<DenseTimeValueModel>(inputModel)) {
142 sourceChannels = dtvm->getChannelCount();
145 int minChannels = 1, maxChannels = sourceChannels;
147 minChannels, maxChannels);
149 int targetChannels = sourceChannels;
151 if (sourceChannels < minChannels) targetChannels = minChannels;
152 if (sourceChannels > maxChannels) targetChannels = maxChannels;
155 int defaultChannel = -1;
157 PluginParameterDialog *dialog =
new PluginParameterDialog
160 dialog->setMoreInfoUrl(TransformFactory::getInstance()->
161 getTransformProvider(transform.getIdentifier())
164 if (candidateModelNames.size() > 1 && !generator) {
165 dialog->setCandidateInputModels(candidateModelNames,
169 if (startFrame != 0 || duration != 0) {
170 dialog->setShowSelectionOnlyOption(
true);
173 if (targetChannels > 0) {
174 dialog->setChannelArrangement(sourceChannels, targetChannels,
178 dialog->setOutputLabel(outputLabel, outputDescription);
180 dialog->setShowProcessingOptions(
true, frequency);
182 if (dialog->exec() == QDialog::Accepted) {
186 QString selectedInput = dialog->getInputModel();
187 if (selectedInput !=
"") {
188 if (modelMap.contains(selectedInput)) {
189 inputModel = modelMap.value(selectedInput);
190 SVDEBUG <<
"Found selected input \"" << selectedInput <<
"\" in model map, result is " << inputModel << endl;
192 SVDEBUG <<
"Failed to find selected input \"" << selectedInput <<
"\" in model map" << endl;
195 SVDEBUG <<
"Selected input empty: \"" << selectedInput <<
"\"" << endl;
199 TransformFactory::getInstance()->
200 setParametersFromPlugin(transform, plugin);
202 input.setChannel(dialog->getChannel());
209 sv_samplerate_t sampleRate = 0;
210 if (
auto m = ModelById::get(inputModel)) {
211 sampleRate = m->getSampleRate();
214 if (startFrame != 0 || duration != 0) {
215 if (dialog->getSelectionOnly() && sampleRate != 0) {
216 transform.setStartTime
217 (RealTime::frame2RealTime(startFrame, sampleRate));
218 transform.setDuration
219 (RealTime::frame2RealTime(duration, sampleRate));
223 int stepSize = 0, blockSize = 0;
224 WindowType windowType = HanningWindow;
226 dialog->getProcessingParameters(stepSize,
230 transform.setStepSize(stepSize);
231 transform.setBlockSize(blockSize);
232 transform.setWindowType(windowType);
236 if (effect && source) {
237 source->setAuditioningEffect({});