25 #include <vamp-hostsdk/Plugin.h> 26 #include <vamp-hostsdk/PluginHostAdapter.h> 27 #include <vamp-hostsdk/PluginWrapper.h> 29 #include <QGridLayout> 32 #include <QHBoxLayout> 33 #include <QVBoxLayout> 34 #include <QScrollArea> 35 #include <QPushButton> 36 #include <QMessageBox> 40 #include <QDialogButtonBox> 41 #include <QDesktopServices> 44 #include "base/Debug.h" 53 m_windowType(HanningWindow),
54 m_parameterBox(nullptr),
55 m_currentSelectionOnly(false)
57 setWindowTitle(tr(
"Plugin Parameters"));
59 QGridLayout *grid =
new QGridLayout;
62 QGroupBox *pluginBox =
new QGroupBox;
63 pluginBox->setTitle(plugin->getType().c_str());
64 grid->addWidget(pluginBox, 0, 0);
66 QGridLayout *subgrid =
new QGridLayout;
67 pluginBox->setLayout(subgrid);
69 subgrid->setSpacing(0);
70 subgrid->setMargin(10);
72 QFont boldFont(pluginBox->font());
73 boldFont.setBold(
true);
75 QFont italicFont(pluginBox->font());
76 italicFont.setItalic(
true);
78 QLabel *nameLabel =
new QLabel(plugin->getName().c_str());
79 nameLabel->setWordWrap(
true);
80 nameLabel->setFont(boldFont);
82 QLabel *makerLabel =
new QLabel(plugin->getMaker().c_str());
83 makerLabel->setWordWrap(
true);
85 int version = plugin->getPluginVersion();
86 QLabel *versionLabel =
new QLabel(QString(
"%1").arg(version));
87 versionLabel->setWordWrap(
true);
89 QLabel *copyrightLabel =
new QLabel(plugin->getCopyright().c_str());
90 copyrightLabel->setWordWrap(
true);
92 QLabel *descriptionLabel =
nullptr;
93 if (plugin->getDescription() !=
"") {
94 descriptionLabel =
new QLabel(plugin->getDescription().c_str());
95 descriptionLabel->setWordWrap(
true);
96 descriptionLabel->setFont(italicFont);
101 QLabel *label =
new QLabel(tr(
"Name:"));
102 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
103 subgrid->addWidget(label, row, 0);
104 subgrid->addWidget(nameLabel, row, 1);
110 subgrid->addWidget(
m_moreInfo, row, 2, Qt::AlignTop | Qt::AlignRight);
115 if (descriptionLabel) {
116 subgrid->addWidget(descriptionLabel, row, 1, 1, 2);
121 label =
new QLabel(tr(
"Version:"));
122 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
123 subgrid->addWidget(label, row, 0);
124 subgrid->addWidget(versionLabel, row, 1);
128 label =
new QLabel(tr(
"Maker:"));
129 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
130 subgrid->addWidget(label, row, 0);
131 subgrid->addWidget(makerLabel, row, 1);
134 label =
new QLabel(tr(
"Copyright: "));
135 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
136 subgrid->addWidget(label, row, 0);
137 subgrid->addWidget(copyrightLabel, row, 1);
162 subgrid->setColumnStretch(1, 2);
169 QVBoxLayout *inputLayout =
new QVBoxLayout;
180 QGroupBox *paramBox =
new QGroupBox;
181 paramBox->setTitle(tr(
"Plugin Parameters"));
182 grid->addWidget(paramBox, 2, 0);
183 grid->setRowStretch(2, 10);
185 QHBoxLayout *paramLayout =
new QHBoxLayout;
186 paramLayout->setMargin(0);
187 paramBox->setLayout(paramLayout);
189 QScrollArea *scroll =
new QScrollArea;
190 scroll->setWidgetResizable(
true);
191 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
192 scroll->setFrameShape(QFrame::NoFrame);
193 paramLayout->addWidget(scroll);
201 QVBoxLayout *advancedLayout =
new QVBoxLayout;
202 advancedLayout->setMargin(0);
218 QHBoxLayout *hbox =
new QHBoxLayout;
219 grid->addLayout(hbox, 4, 0);
228 settings.beginGroup(
"PluginParameterDialog");
237 QDialogButtonBox *bb =
new QDialogButtonBox(QDialogButtonBox::Ok |
238 QDialogButtonBox::Cancel);
241 connect(bb, SIGNAL(rejected()),
this, SLOT(reject()));
242 bb->button(QDialogButtonBox::Ok)->setDefault(
true);
256 return QDialog::exec();
277 if (description !=
"") {
303 if (sourceChannels != targetChannels) {
308 if (sourceChannels < targetChannels) {
312 tr(
"Channel mismatch"),
313 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")),
315 QMessageBox::NoButton);
320 cerr <<
"WARNING: PluginParameterDialog::setChannelArrangement: Calling more than once on same dialog is not currently implemented" << endl;
324 QVBoxLayout *channelLayout =
new QVBoxLayout;
327 if (targetChannels != 1) {
329 channelLayout->addWidget
330 (
new QLabel(tr(
"This plugin accepts no more than %1 input channels,\nbut %2 are available. Only the first %3 will be used.\n")
333 .arg(targetChannels)));
337 channelLayout->addWidget(
new QLabel(tr(
"This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels)));
339 QComboBox *channelCombo =
new QComboBox;
340 channelCombo->addItem(tr(
"Use mean of source channels"));
341 for (
int i = 0; i < sourceChannels; ++i) {
342 channelCombo->addItem(tr(
"Use channel %1 only").arg(i + 1));
345 connect(channelCombo, SIGNAL(activated(
int)),
348 channelLayout->addWidget(channelCombo);
362 bool showFrequencyDomainOptions)
365 cerr <<
"WARNING: PluginParameterDialog::setShowProcessingOptions: Calling more than once on same dialog is not currently implemented" << endl;
369 if (showWindowSize) {
371 auto fePlugin = std::dynamic_pointer_cast<Vamp::Plugin>(
m_plugin);
373 int increment = 1024;
375 size = int(fePlugin->getPreferredBlockSize());
376 cerr <<
"Feature extraction plugin \"" << fePlugin->getName() <<
"\" reports preferred block size as " << size << endl;
377 if (size == 0) size = 1024;
378 increment = int(fePlugin->getPreferredStepSize());
379 if (increment == 0) {
380 if (fePlugin->getInputDomain() == Vamp::Plugin::TimeDomain) {
388 QGridLayout *windowLayout =
new QGridLayout;
391 if (showFrequencyDomainOptions) {
392 windowLayout->addWidget(
new QLabel(tr(
"Window size:")), 0, 0);
394 windowLayout->addWidget(
new QLabel(tr(
"Audio frames per block:")), 0, 0);
397 cerr <<
"size: " << size <<
", increment: " << increment << endl;
399 QComboBox *blockSizeCombo =
new QComboBox;
400 blockSizeCombo->setEditable(
true);
402 for (
int i = 0; i < 14; ++i) {
403 int val = 1 << (i + 3);
404 blockSizeCombo->addItem(QString(
"%1").arg(val));
406 blockSizeCombo->setCurrentIndex(i);
411 blockSizeCombo->addItem(QString(
"%1").arg(size));
412 blockSizeCombo->setCurrentIndex(blockSizeCombo->count() - 1);
414 blockSizeCombo->setValidator(
new QIntValidator(1,
int(pow(2., 18)),
this));
415 connect(blockSizeCombo, SIGNAL(editTextChanged(
const QString &)),
417 windowLayout->addWidget(blockSizeCombo, 0, 1);
419 windowLayout->addWidget(
new QLabel(tr(
"Window increment:")), 1, 0);
421 QComboBox *incrementCombo =
new QComboBox;
422 incrementCombo->setEditable(
true);
424 for (
int i = 0; i < 14; ++i) {
425 int val = 1 << (i + 3);
426 incrementCombo->addItem(QString(
"%1").arg(val));
427 if (val == increment) {
428 incrementCombo->setCurrentIndex(i);
433 incrementCombo->addItem(QString(
"%1").arg(increment));
434 incrementCombo->setCurrentIndex(incrementCombo->count() - 1);
436 incrementCombo->setValidator(
new QIntValidator(1,
int(pow(2., 18)),
this));
437 connect(incrementCombo, SIGNAL(editTextChanged(
const QString &)),
439 windowLayout->addWidget(incrementCombo, 1, 1);
441 if (showFrequencyDomainOptions) {
443 windowLayout->addWidget(
new QLabel(tr(
"Window shape:")), 2, 0);
447 windowLayout->addWidget(windowTypeSelector, 2, 1);
460 QString defaultModel)
465 settings.beginGroup(
"PluginParameterDialog");
466 QString lastModel = settings.value(
"lastinputmodel").toString();
469 if (defaultModel ==
"") defaultModel = lastModel;
477 if (defaultModel !=
"") {
478 for (
int i = 0; i < models.size(); ++i) {
479 if (defaultModel == models[i]) {
502 settings.beginGroup(
"PluginParameterDialog");
503 bool lastSelectionOnly = settings.value(
"lastselectiononly",
false).toBool();
538 WindowType &windowType)
const 550 cerr <<
"Block size changed to " <<
m_blockSize << endl;
558 cerr <<
"Increment changed to " <<
m_stepSize << endl;
599 settings.beginGroup(
"PluginParameterDialog");
600 settings.setValue(
"advancedvisible", visible);
621 if (state == Qt::Checked) {
632 settings.beginGroup(
"PluginParameterDialog");
void setChannelArrangement(int sourceChannels, int targetChannels, int defaultChannel)
QString getInputModel() const
PluginParameterDialog(std::shared_ptr< Vamp::PluginBase > plugin, QWidget *parent=0)
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 getProcessingParameters(int &blockSize) const
!! merge with PluginTransform::ExecutionContext
void inputModelChanged(QString)
void channelComboChanged(int)
void windowTypeChanged(WindowType type)
QGroupBox * m_inputModelBox
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)
QString m_currentInputModel
QLabel * m_outputDescription
void blockSizeComboChanged(const QString &)
bool m_haveChannelBoxData
void setMoreInfoUrl(QString url)
void selectionOnlyChanged(int)
QPushButton * m_advancedButton
void incrementComboChanged(const QString &)
bool getSelectionOnly() const
std::shared_ptr< Vamp::PluginBase > m_plugin
QStringList m_inputModelList
QCheckBox * m_selectionOnly