annotate widgets/PluginParameterDialog.cpp @ 145:4d132a06db9b

* Add mono timestretch toggle button; some more work on getting blocksize etc parameters through to plugins
author Chris Cannam
date Mon, 18 Sep 2006 16:43:17 +0000
parents bcb6d71be63c
children a1f7d265ac79
rev   line source
Chris@62 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@62 2
Chris@62 3 /*
Chris@62 4 Sonic Visualiser
Chris@62 5 An audio file viewer and annotation editor.
Chris@62 6 Centre for Digital Music, Queen Mary, University of London.
Chris@62 7 This file copyright 2006 Chris Cannam.
Chris@62 8
Chris@62 9 This program is free software; you can redistribute it and/or
Chris@62 10 modify it under the terms of the GNU General Public License as
Chris@62 11 published by the Free Software Foundation; either version 2 of the
Chris@62 12 License, or (at your option) any later version. See the file
Chris@62 13 COPYING included with this distribution for more information.
Chris@62 14 */
Chris@62 15
Chris@62 16 #include "PluginParameterDialog.h"
Chris@62 17
Chris@62 18 #include "PluginParameterBox.h"
Chris@140 19 #include "WindowTypeSelector.h"
Chris@62 20
Chris@106 21 #include "vamp-sdk/Plugin.h"
Chris@106 22
Chris@62 23 #include <QGridLayout>
Chris@62 24 #include <QLabel>
Chris@62 25 #include <QGroupBox>
Chris@62 26 #include <QHBoxLayout>
Chris@143 27 #include <QVBoxLayout>
Chris@62 28 #include <QPushButton>
Chris@69 29 #include <QMessageBox>
Chris@69 30 #include <QComboBox>
Chris@143 31 #include <QSettings>
Chris@62 32
Chris@71 33 PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin,
Chris@69 34 int sourceChannels,
Chris@69 35 int targetChannels,
Chris@69 36 int defaultChannel,
Chris@106 37 QString output,
Chris@140 38 bool showWindowSize,
Chris@140 39 bool showFrequencyDomainOptions,
Chris@62 40 QWidget *parent) :
Chris@62 41 QDialog(parent),
Chris@62 42 m_plugin(plugin),
Chris@69 43 m_channel(defaultChannel),
Chris@145 44 m_stepSize(0),
Chris@145 45 m_blockSize(0),
Chris@145 46 m_windowType(HanningWindow),
Chris@62 47 m_parameterBox(0)
Chris@62 48 {
Chris@122 49 setWindowTitle(tr("Plugin Parameters"));
Chris@122 50
Chris@62 51 QGridLayout *grid = new QGridLayout;
Chris@62 52 setLayout(grid);
Chris@62 53
Chris@62 54 QGroupBox *pluginBox = new QGroupBox;
Chris@62 55 pluginBox->setTitle(tr("Plugin"));
Chris@62 56 grid->addWidget(pluginBox, 0, 0);
Chris@62 57
Chris@62 58 QGridLayout *subgrid = new QGridLayout;
Chris@62 59 pluginBox->setLayout(subgrid);
Chris@62 60
Chris@63 61 subgrid->setSpacing(0);
Chris@63 62 subgrid->setMargin(10);
Chris@63 63
Chris@62 64 QFont font(pluginBox->font());
Chris@62 65 font.setBold(true);
Chris@62 66
Chris@62 67 QLabel *nameLabel = new QLabel(plugin->getDescription().c_str());
Chris@62 68 nameLabel->setFont(font);
Chris@62 69
Chris@62 70 QLabel *makerLabel = new QLabel(plugin->getMaker().c_str());
Chris@62 71
Chris@106 72 QLabel *outputLabel = 0;
Chris@106 73
Chris@106 74 if (output != "") {
Chris@106 75
Chris@106 76 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(plugin);
Chris@106 77
Chris@106 78 if (fePlugin) {
Chris@106 79
Chris@106 80 std::vector<Vamp::Plugin::OutputDescriptor> od =
Chris@106 81 fePlugin->getOutputDescriptors();
Chris@106 82
Chris@106 83 if (od.size() > 1) {
Chris@106 84
Chris@106 85 for (size_t i = 0; i < od.size(); ++i) {
Chris@106 86 if (od[i].name == output.toStdString()) {
Chris@106 87 outputLabel = new QLabel(od[i].description.c_str());
Chris@106 88 break;
Chris@106 89 }
Chris@106 90 }
Chris@106 91 }
Chris@106 92 }
Chris@106 93 }
Chris@106 94
Chris@62 95 QLabel *versionLabel = new QLabel(QString("%1")
Chris@62 96 .arg(plugin->getPluginVersion()));
Chris@62 97
Chris@62 98 QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str());
Chris@62 99
Chris@63 100 QLabel *typeLabel = new QLabel(plugin->getType().c_str());
Chris@63 101 typeLabel->setFont(font);
Chris@63 102
Chris@62 103 subgrid->addWidget(new QLabel(tr("Name:")), 0, 0);
Chris@62 104 subgrid->addWidget(nameLabel, 0, 1);
Chris@62 105
Chris@63 106 subgrid->addWidget(new QLabel(tr("Type:")), 1, 0);
Chris@63 107 subgrid->addWidget(typeLabel, 1, 1);
Chris@62 108
Chris@106 109 int outputOffset = 0;
Chris@106 110 if (outputLabel) {
Chris@106 111 subgrid->addWidget(new QLabel(tr("Output:")), 2, 0);
Chris@106 112 subgrid->addWidget(outputLabel, 2, 1);
Chris@106 113 outputOffset = 1;
Chris@106 114 }
Chris@62 115
Chris@106 116 subgrid->addWidget(new QLabel(tr("Maker:")), 2 + outputOffset, 0);
Chris@106 117 subgrid->addWidget(makerLabel, 2 + outputOffset, 1);
Chris@63 118
Chris@106 119 subgrid->addWidget(new QLabel(tr("Copyright: ")), 3 + outputOffset, 0);
Chris@106 120 subgrid->addWidget(copyrightLabel, 3 + outputOffset, 1);
Chris@106 121
Chris@106 122 subgrid->addWidget(new QLabel(tr("Version:")), 4 + outputOffset, 0);
Chris@106 123 subgrid->addWidget(versionLabel, 4 + outputOffset, 1);
Chris@62 124
Chris@62 125 subgrid->setColumnStretch(1, 2);
Chris@62 126
Chris@62 127 QGroupBox *paramBox = new QGroupBox;
Chris@62 128 paramBox->setTitle(tr("Plugin Parameters"));
Chris@62 129 grid->addWidget(paramBox, 1, 0);
Chris@62 130 grid->setRowStretch(1, 10);
Chris@62 131
Chris@62 132 QHBoxLayout *paramLayout = new QHBoxLayout;
Chris@63 133 paramLayout->setMargin(0);
Chris@62 134 paramBox->setLayout(paramLayout);
Chris@62 135
Chris@62 136 m_parameterBox = new PluginParameterBox(m_plugin);
Chris@64 137 connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)),
Chris@64 138 this, SIGNAL(pluginConfigurationChanged(QString)));
Chris@62 139 paramLayout->addWidget(m_parameterBox);
Chris@62 140
Chris@143 141 m_advanced = new QFrame;
Chris@143 142 QVBoxLayout *advancedLayout = new QVBoxLayout;
Chris@143 143 advancedLayout->setMargin(0);
Chris@143 144 m_advanced->setLayout(advancedLayout);
Chris@143 145 grid->addWidget(m_advanced, 2, 0);
Chris@143 146
Chris@143 147 bool haveAdvanced = false;
Chris@143 148
Chris@69 149 if (sourceChannels != targetChannels) {
Chris@69 150
Chris@69 151 // At the moment we can only cope with the case where
Chris@69 152 // sourceChannels > targetChannels and targetChannels == 1
Chris@69 153
Chris@69 154 if (sourceChannels < targetChannels) {
Chris@69 155
Chris@69 156 QMessageBox::warning
Chris@69 157 (parent,
Chris@69 158 tr("Channel mismatch"),
Chris@69 159 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")),
Chris@69 160 QMessageBox::Ok,
Chris@69 161 QMessageBox::NoButton);
Chris@69 162
Chris@69 163 } else {
Chris@69 164
Chris@69 165 QGroupBox *channelBox = new QGroupBox;
Chris@69 166 channelBox->setTitle(tr("Channels"));
Chris@143 167 advancedLayout->addWidget(channelBox);
Chris@143 168 haveAdvanced = true;
Chris@69 169
Chris@69 170 QVBoxLayout *channelLayout = new QVBoxLayout;
Chris@69 171 channelBox->setLayout(channelLayout);
Chris@69 172
Chris@69 173 if (targetChannels != 1) {
Chris@69 174
Chris@69 175 channelLayout->addWidget
Chris@69 176 (new QLabel(tr("This plugin accepts no more than %1 input channels,\nbut %2 are available. Only the first %3 will be used.\n")
Chris@69 177 .arg(targetChannels)
Chris@69 178 .arg(sourceChannels)
Chris@69 179 .arg(targetChannels)));
Chris@69 180
Chris@69 181 } else {
Chris@69 182
Chris@69 183 channelLayout->addWidget(new QLabel(tr("This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels)));
Chris@69 184
Chris@69 185 QComboBox *channelCombo = new QComboBox;
Chris@76 186 channelCombo->addItem(tr("Use mean of source channels"));
Chris@69 187 for (int i = 0; i < sourceChannels; ++i) {
Chris@69 188 channelCombo->addItem(tr("Use channel %1 only").arg(i + 1));
Chris@69 189 }
Chris@69 190
Chris@69 191 connect(channelCombo, SIGNAL(activated(int)),
Chris@69 192 this, SLOT(channelComboChanged(int)));
Chris@69 193
Chris@69 194 channelLayout->addWidget(channelCombo);
Chris@69 195 }
Chris@69 196 }
Chris@69 197 }
Chris@69 198
Chris@140 199 if (showWindowSize) {
Chris@140 200
Chris@140 201 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(plugin);
Chris@140 202 int size = 1024;
Chris@140 203 int increment = 1024;
Chris@140 204 if (fePlugin) {
Chris@140 205 size = fePlugin->getPreferredBlockSize();
Chris@140 206 if (size == 0) size = 1024;
Chris@140 207 increment = fePlugin->getPreferredStepSize();
Chris@140 208 if (increment == 0) increment = size;
Chris@140 209 }
Chris@140 210
Chris@140 211 QGroupBox *windowBox = new QGroupBox;
Chris@140 212 windowBox->setTitle(tr("Processing"));
Chris@143 213 advancedLayout->addWidget(windowBox);
Chris@143 214 haveAdvanced = true;
Chris@140 215
Chris@140 216 QGridLayout *windowLayout = new QGridLayout;
Chris@140 217 windowBox->setLayout(windowLayout);
Chris@140 218
Chris@140 219 if (showFrequencyDomainOptions) {
Chris@140 220 windowLayout->addWidget(new QLabel(tr("Window size:")), 0, 0);
Chris@140 221 } else {
Chris@140 222 windowLayout->addWidget(new QLabel(tr("Audio frames per block:")), 0, 0);
Chris@140 223 }
Chris@140 224
Chris@143 225 std::cerr << "size: " << size << ", increment: " << increment << std::endl;
Chris@143 226
Chris@145 227 //!!! deal with block and step sizes (coming from the plugin's
Chris@145 228 // preferences) that don't fit into the default list
Chris@145 229
Chris@140 230 QComboBox *blockSizeCombo = new QComboBox;
Chris@140 231 blockSizeCombo->setEditable(true);
Chris@143 232 for (int i = 0; i < 14; ++i) {
Chris@140 233 int val = pow(2, i + 3);
Chris@140 234 blockSizeCombo->addItem(QString("%1").arg(val));
Chris@140 235 if (val == size) blockSizeCombo->setCurrentIndex(i);
Chris@140 236 }
Chris@143 237 blockSizeCombo->setValidator(new QIntValidator(1, pow(2, 18), this));
Chris@145 238 connect(blockSizeCombo, SIGNAL(valueChanged(QString)),
Chris@145 239 this, SLOT(blockSizeComboChanged(QString)));
Chris@140 240 windowLayout->addWidget(blockSizeCombo, 0, 1);
Chris@140 241
Chris@140 242 if (showFrequencyDomainOptions) {
Chris@140 243
Chris@140 244 windowLayout->addWidget(new QLabel(tr("Window increment:")), 1, 0);
Chris@140 245
Chris@140 246 QComboBox *incrementCombo = new QComboBox;
Chris@140 247 incrementCombo->setEditable(true);
Chris@143 248 for (int i = 0; i < 14; ++i) {
Chris@140 249 int val = pow(2, i + 3);
Chris@140 250 incrementCombo->addItem(QString("%1").arg(val));
Chris@143 251 if (val == increment) incrementCombo->setCurrentIndex(i);
Chris@140 252 }
Chris@143 253 incrementCombo->setValidator(new QIntValidator(1, pow(2, 18), this));
Chris@145 254 connect(incrementCombo, SIGNAL(valueChanged(QString)),
Chris@145 255 this, SLOT(incrementComboChanged(QString)));
Chris@140 256 windowLayout->addWidget(incrementCombo, 1, 1);
Chris@140 257
Chris@140 258 windowLayout->addWidget(new QLabel(tr("Window shape:")), 2, 0);
Chris@140 259 WindowTypeSelector *windowTypeSelector = new WindowTypeSelector;
Chris@145 260 connect(windowTypeSelector, SIGNAL(windowTypeChanged(WindowType type)),
Chris@145 261 this, SLOT(windowTypeChanged(type)));
Chris@140 262 windowLayout->addWidget(windowTypeSelector, 2, 1);
Chris@140 263 }
Chris@140 264 }
Chris@140 265
Chris@62 266 QHBoxLayout *hbox = new QHBoxLayout;
Chris@140 267 grid->addLayout(hbox, 4, 0);
Chris@143 268
Chris@143 269 bool advancedVisible = false;
Chris@143 270
Chris@143 271 if (haveAdvanced) {
Chris@143 272
Chris@143 273 m_advancedButton = new QPushButton(tr("Advanced >>"));
Chris@143 274 m_advancedButton->setCheckable(true);
Chris@143 275 connect(m_advancedButton, SIGNAL(clicked()), this, SLOT(advancedToggled()));
Chris@143 276
Chris@143 277 QSettings settings;
Chris@143 278 settings.beginGroup("PluginParameterDialog");
Chris@143 279 advancedVisible = settings.value("advancedvisible", false).toBool();
Chris@143 280 settings.endGroup();
Chris@143 281
Chris@143 282 m_advanced->setVisible(false);
Chris@143 283
Chris@143 284 hbox->addWidget(m_advancedButton);
Chris@143 285 }
Chris@143 286
Chris@62 287 QPushButton *ok = new QPushButton(tr("OK"));
Chris@62 288 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@62 289 hbox->addStretch(10);
Chris@62 290 hbox->addWidget(ok);
Chris@62 291 hbox->addWidget(cancel);
Chris@62 292 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@62 293 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@143 294
Chris@143 295 if (advancedVisible) {
Chris@143 296 m_advancedButton->setChecked(true);
Chris@143 297 advancedToggled();
Chris@143 298 }
Chris@62 299 }
Chris@62 300
Chris@62 301 PluginParameterDialog::~PluginParameterDialog()
Chris@62 302 {
Chris@62 303 }
Chris@62 304
Chris@69 305 void
Chris@145 306 PluginParameterDialog::getProcessingParameters(size_t &blockSize) const
Chris@145 307 {
Chris@145 308 blockSize = m_blockSize;
Chris@145 309 return;
Chris@145 310 }
Chris@145 311
Chris@145 312 void
Chris@145 313 PluginParameterDialog::getProcessingParameters(size_t &stepSize,
Chris@145 314 size_t &blockSize,
Chris@145 315 WindowType &windowType) const
Chris@145 316 {
Chris@145 317 stepSize = m_stepSize;
Chris@145 318 blockSize = m_blockSize;
Chris@145 319 windowType = m_windowType;
Chris@145 320 }
Chris@145 321
Chris@145 322 void
Chris@145 323 PluginParameterDialog::blockSizeComboChanged(QString text)
Chris@145 324 {
Chris@145 325 m_blockSize = text.toInt();
Chris@145 326 }
Chris@145 327
Chris@145 328 void
Chris@145 329 PluginParameterDialog::incrementComboChanged(QString text)
Chris@145 330 {
Chris@145 331 m_stepSize = text.toInt();
Chris@145 332 }
Chris@145 333
Chris@145 334 void
Chris@145 335 PluginParameterDialog::windowTypeChanged(WindowType type)
Chris@145 336 {
Chris@145 337 m_windowType = type;
Chris@145 338 }
Chris@145 339
Chris@145 340 void
Chris@143 341 PluginParameterDialog::advancedToggled()
Chris@143 342 {
Chris@143 343 bool visible = !m_advanced->isVisible();
Chris@143 344
Chris@143 345 m_advanced->setVisible(visible);
Chris@143 346
Chris@143 347 if (visible) m_advancedButton->setText(tr("Advanced <<"));
Chris@143 348 else m_advancedButton->setText(tr("Advanced >>"));
Chris@143 349
Chris@143 350 QSettings settings;
Chris@143 351 settings.beginGroup("PluginParameterDialog");
Chris@143 352 settings.setValue("advancedvisible", visible);
Chris@143 353 settings.endGroup();
Chris@143 354
Chris@143 355 std::cerr << "resize to " << sizeHint().width() << " x " << sizeHint().height() << std::endl;
Chris@143 356
Chris@143 357 setMaximumSize(sizeHint());
Chris@143 358 }
Chris@143 359
Chris@143 360 void
Chris@69 361 PluginParameterDialog::channelComboChanged(int index)
Chris@69 362 {
Chris@69 363 m_channel = index - 1;
Chris@69 364 }
Chris@69 365