24 #include <vamp-hostsdk/Plugin.h> 25 #include <vamp-hostsdk/PluginHostAdapter.h> 26 #include <vamp-hostsdk/PluginWrapper.h> 28 #include <QGridLayout> 31 #include <QHBoxLayout> 32 #include <QVBoxLayout> 33 #include <QScrollArea> 34 #include <QPushButton> 35 #include <QMessageBox> 39 #include <QDialogButtonBox> 40 #include <QDesktopServices> 43 #include "base/Debug.h" 52 m_windowType(HanningWindow),
54 m_currentSelectionOnly(false)
56 setWindowTitle(tr(
"Plugin Parameters"));
58 QGridLayout *grid =
new QGridLayout;
61 QGroupBox *pluginBox =
new QGroupBox;
62 pluginBox->setTitle(plugin->getType().c_str());
63 grid->addWidget(pluginBox, 0, 0);
65 QGridLayout *subgrid =
new QGridLayout;
66 pluginBox->setLayout(subgrid);
68 subgrid->setSpacing(0);
69 subgrid->setMargin(10);
71 QFont boldFont(pluginBox->font());
72 boldFont.setBold(
true);
74 QFont italicFont(pluginBox->font());
75 italicFont.setItalic(
true);
77 QLabel *nameLabel =
new QLabel(plugin->getName().c_str());
78 nameLabel->setWordWrap(
true);
79 nameLabel->setFont(boldFont);
81 QLabel *makerLabel =
new QLabel(plugin->getMaker().c_str());
82 makerLabel->setWordWrap(
true);
84 int version = plugin->getPluginVersion();
85 QLabel *versionLabel =
new QLabel(QString(
"%1").arg(version));
86 versionLabel->setWordWrap(
true);
88 QLabel *copyrightLabel =
new QLabel(plugin->getCopyright().c_str());
89 copyrightLabel->setWordWrap(
true);
95 QLabel *descriptionLabel = 0;
96 if (plugin->getDescription() !=
"") {
97 descriptionLabel =
new QLabel(plugin->getDescription().c_str());
98 descriptionLabel->setWordWrap(
true);
99 descriptionLabel->setFont(italicFont);
104 QLabel *label =
new QLabel(tr(
"Name:"));
105 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
106 subgrid->addWidget(label, row, 0);
107 subgrid->addWidget(nameLabel, row, 1);
113 subgrid->addWidget(
m_moreInfo, row, 2, Qt::AlignTop | Qt::AlignRight);
118 if (descriptionLabel) {
122 subgrid->addWidget(descriptionLabel, row, 1, 1, 2);
127 label =
new QLabel(tr(
"Version:"));
128 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
129 subgrid->addWidget(label, row, 0);
130 subgrid->addWidget(versionLabel, row, 1);
140 label =
new QLabel(tr(
"Maker:"));
141 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
142 subgrid->addWidget(label, row, 0);
143 subgrid->addWidget(makerLabel, row, 1);
146 label =
new QLabel(tr(
"Copyright: "));
147 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
148 subgrid->addWidget(label, row, 0);
149 subgrid->addWidget(copyrightLabel, row, 1);
174 subgrid->setColumnStretch(1, 2);
181 QVBoxLayout *inputLayout =
new QVBoxLayout;
192 QGroupBox *paramBox =
new QGroupBox;
193 paramBox->setTitle(tr(
"Plugin Parameters"));
194 grid->addWidget(paramBox, 2, 0);
195 grid->setRowStretch(2, 10);
197 QHBoxLayout *paramLayout =
new QHBoxLayout;
198 paramLayout->setMargin(0);
199 paramBox->setLayout(paramLayout);
201 QScrollArea *scroll =
new QScrollArea;
202 scroll->setWidgetResizable(
true);
203 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
204 scroll->setFrameShape(QFrame::NoFrame);
205 paramLayout->addWidget(scroll);
213 QVBoxLayout *advancedLayout =
new QVBoxLayout;
214 advancedLayout->setMargin(0);
230 QHBoxLayout *hbox =
new QHBoxLayout;
231 grid->addLayout(hbox, 4, 0);
240 settings.beginGroup(
"PluginParameterDialog");
249 QDialogButtonBox *bb =
new QDialogButtonBox(QDialogButtonBox::Ok |
250 QDialogButtonBox::Cancel);
253 connect(bb, SIGNAL(rejected()),
this, SLOT(reject()));
254 bb->button(QDialogButtonBox::Ok)->setDefault(
true);
268 return QDialog::exec();
289 if (description !=
"") {
315 if (sourceChannels != targetChannels) {
320 if (sourceChannels < targetChannels) {
324 tr(
"Channel mismatch"),
325 tr(
"This plugin requires at least %1 input channels, but only %2 %3 available. The plugin probably will not work correctly.").arg(targetChannels).arg(sourceChannels).arg(sourceChannels != 1 ? tr(
"are") : tr(
"is")),
327 QMessageBox::NoButton);
332 cerr <<
"WARNING: PluginParameterDialog::setChannelArrangement: Calling more than once on same dialog is not currently implemented" << endl;
336 QVBoxLayout *channelLayout =
new QVBoxLayout;
339 if (targetChannels != 1) {
341 channelLayout->addWidget
342 (
new QLabel(tr(
"This plugin accepts no more than %1 input channels,\nbut %2 are available. Only the first %3 will be used.\n")
345 .arg(targetChannels)));
349 channelLayout->addWidget(
new QLabel(tr(
"This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels)));
351 QComboBox *channelCombo =
new QComboBox;
352 channelCombo->addItem(tr(
"Use mean of source channels"));
353 for (
int i = 0; i < sourceChannels; ++i) {
354 channelCombo->addItem(tr(
"Use channel %1 only").arg(i + 1));
357 connect(channelCombo, SIGNAL(activated(
int)),
360 channelLayout->addWidget(channelCombo);
374 bool showFrequencyDomainOptions)
377 cerr <<
"WARNING: PluginParameterDialog::setShowProcessingOptions: Calling more than once on same dialog is not currently implemented" << endl;
381 if (showWindowSize) {
383 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(
m_plugin);
384 if (!fePlugin) fePlugin = dynamic_cast<Vamp::PluginHostAdapter *>(
m_plugin);
385 if (!fePlugin) fePlugin = dynamic_cast<Vamp::HostExt::PluginWrapper *>(
m_plugin);
387 int increment = 1024;
389 size = fePlugin->getPreferredBlockSize();
390 cerr <<
"Feature extraction plugin \"" << fePlugin->getName() <<
"\" reports preferred block size as " << size << endl;
391 if (size == 0) size = 1024;
392 increment = fePlugin->getPreferredStepSize();
393 if (increment == 0) {
394 if (fePlugin->getInputDomain() == Vamp::Plugin::TimeDomain) {
402 QGridLayout *windowLayout =
new QGridLayout;
405 if (showFrequencyDomainOptions) {
406 windowLayout->addWidget(
new QLabel(tr(
"Window size:")), 0, 0);
408 windowLayout->addWidget(
new QLabel(tr(
"Audio frames per block:")), 0, 0);
411 cerr <<
"size: " << size <<
", increment: " << increment << endl;
413 QComboBox *blockSizeCombo =
new QComboBox;
414 blockSizeCombo->setEditable(
true);
416 for (
int i = 0; i < 14; ++i) {
417 int val = 1 << (i + 3);
418 blockSizeCombo->addItem(QString(
"%1").arg(val));
420 blockSizeCombo->setCurrentIndex(i);
425 blockSizeCombo->addItem(QString(
"%1").arg(size));
426 blockSizeCombo->setCurrentIndex(blockSizeCombo->count() - 1);
428 blockSizeCombo->setValidator(
new QIntValidator(1,
int(pow(2., 18)),
this));
429 connect(blockSizeCombo, SIGNAL(editTextChanged(
const QString &)),
431 windowLayout->addWidget(blockSizeCombo, 0, 1);
433 windowLayout->addWidget(
new QLabel(tr(
"Window increment:")), 1, 0);
435 QComboBox *incrementCombo =
new QComboBox;
436 incrementCombo->setEditable(
true);
438 for (
int i = 0; i < 14; ++i) {
439 int val = 1 << (i + 3);
440 incrementCombo->addItem(QString(
"%1").arg(val));
441 if (val == increment) {
442 incrementCombo->setCurrentIndex(i);
447 incrementCombo->addItem(QString(
"%1").arg(increment));
448 incrementCombo->setCurrentIndex(incrementCombo->count() - 1);
450 incrementCombo->setValidator(
new QIntValidator(1,
int(pow(2., 18)),
this));
451 connect(incrementCombo, SIGNAL(editTextChanged(
const QString &)),
453 windowLayout->addWidget(incrementCombo, 1, 1);
455 if (showFrequencyDomainOptions) {
457 windowLayout->addWidget(
new QLabel(tr(
"Window shape:")), 2, 0);
461 windowLayout->addWidget(windowTypeSelector, 2, 1);
474 QString defaultModel)
479 settings.beginGroup(
"PluginParameterDialog");
480 QString lastModel = settings.value(
"lastinputmodel").toString();
483 if (defaultModel ==
"") defaultModel = lastModel;
491 if (defaultModel !=
"") {
492 for (
int i = 0; i < models.size(); ++i) {
493 if (defaultModel == models[i]) {
516 settings.beginGroup(
"PluginParameterDialog");
517 bool lastSelectionOnly = settings.value(
"lastselectiononly",
false).toBool();
552 WindowType &windowType)
const 564 cerr <<
"Block size changed to " <<
m_blockSize << endl;
572 cerr <<
"Increment changed to " <<
m_stepSize << endl;
620 settings.beginGroup(
"PluginParameterDialog");
621 settings.setValue(
"advancedvisible", visible);
645 if (state == Qt::Checked) {
656 settings.beginGroup(
"PluginParameterDialog");
void setChannelArrangement(int sourceChannels, int targetChannels, int defaultChannel)
static QString abbreviate(QString text, int maxLength, Policy policy=ElideEnd, bool fuzzy=true, QString ellipsis="")
Abbreviate the given text to the given maximum length (including ellipsis), using the given abbreviat...
bool m_currentSelectionOnly
void pluginConfigurationChanged(QString)
void inputModelComboChanged(int)
void setAdvancedVisible(bool)
void inputModelChanged(QString)
void channelComboChanged(int)
void windowTypeChanged(WindowType type)
QGroupBox * m_inputModelBox
QString getInputModel() const
void setCandidateInputModels(const QStringList &names, QString defaultName)
void setShowSelectionOnlyOption(bool show)
void setOutputLabel(QString output, QString description)
PluginParameterBox * m_parameterBox
QComboBox * m_inputModels
void setShowProcessingOptions(bool showWindowSize, bool showFrequencyDomainOptions)
void getProcessingParameters(int &blockSize) const
!! merge with PluginTransform::ExecutionContext
QString m_currentInputModel
Vamp::PluginBase * m_plugin
QLabel * m_outputDescription
void blockSizeComboChanged(const QString &)
bool m_haveChannelBoxData
void setMoreInfoUrl(QString url)
bool getSelectionOnly() const
void selectionOnlyChanged(int)
QPushButton * m_advancedButton
void incrementComboChanged(const QString &)
PluginParameterDialog(Vamp::PluginBase *, QWidget *parent=0)
QStringList m_inputModelList
QCheckBox * m_selectionOnly