annotate widgets/PluginParameterDialog.cpp @ 143:bcb6d71be63c

* Put channel and windowing parameters on an "advanced" bit of the plugin parameter window
author Chris Cannam
date Fri, 15 Sep 2006 13:50:22 +0000
parents b9235b62fe31
children 4d132a06db9b
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@62 44 m_parameterBox(0)
Chris@62 45 {
Chris@122 46 setWindowTitle(tr("Plugin Parameters"));
Chris@122 47
Chris@62 48 QGridLayout *grid = new QGridLayout;
Chris@62 49 setLayout(grid);
Chris@62 50
Chris@62 51 QGroupBox *pluginBox = new QGroupBox;
Chris@62 52 pluginBox->setTitle(tr("Plugin"));
Chris@62 53 grid->addWidget(pluginBox, 0, 0);
Chris@62 54
Chris@62 55 QGridLayout *subgrid = new QGridLayout;
Chris@62 56 pluginBox->setLayout(subgrid);
Chris@62 57
Chris@63 58 subgrid->setSpacing(0);
Chris@63 59 subgrid->setMargin(10);
Chris@63 60
Chris@62 61 QFont font(pluginBox->font());
Chris@62 62 font.setBold(true);
Chris@62 63
Chris@62 64 QLabel *nameLabel = new QLabel(plugin->getDescription().c_str());
Chris@62 65 nameLabel->setFont(font);
Chris@62 66
Chris@62 67 QLabel *makerLabel = new QLabel(plugin->getMaker().c_str());
Chris@62 68
Chris@106 69 QLabel *outputLabel = 0;
Chris@106 70
Chris@106 71 if (output != "") {
Chris@106 72
Chris@106 73 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(plugin);
Chris@106 74
Chris@106 75 if (fePlugin) {
Chris@106 76
Chris@106 77 std::vector<Vamp::Plugin::OutputDescriptor> od =
Chris@106 78 fePlugin->getOutputDescriptors();
Chris@106 79
Chris@106 80 if (od.size() > 1) {
Chris@106 81
Chris@106 82 for (size_t i = 0; i < od.size(); ++i) {
Chris@106 83 if (od[i].name == output.toStdString()) {
Chris@106 84 outputLabel = new QLabel(od[i].description.c_str());
Chris@106 85 break;
Chris@106 86 }
Chris@106 87 }
Chris@106 88 }
Chris@106 89 }
Chris@106 90 }
Chris@106 91
Chris@62 92 QLabel *versionLabel = new QLabel(QString("%1")
Chris@62 93 .arg(plugin->getPluginVersion()));
Chris@62 94
Chris@62 95 QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str());
Chris@62 96
Chris@63 97 QLabel *typeLabel = new QLabel(plugin->getType().c_str());
Chris@63 98 typeLabel->setFont(font);
Chris@63 99
Chris@62 100 subgrid->addWidget(new QLabel(tr("Name:")), 0, 0);
Chris@62 101 subgrid->addWidget(nameLabel, 0, 1);
Chris@62 102
Chris@63 103 subgrid->addWidget(new QLabel(tr("Type:")), 1, 0);
Chris@63 104 subgrid->addWidget(typeLabel, 1, 1);
Chris@62 105
Chris@106 106 int outputOffset = 0;
Chris@106 107 if (outputLabel) {
Chris@106 108 subgrid->addWidget(new QLabel(tr("Output:")), 2, 0);
Chris@106 109 subgrid->addWidget(outputLabel, 2, 1);
Chris@106 110 outputOffset = 1;
Chris@106 111 }
Chris@62 112
Chris@106 113 subgrid->addWidget(new QLabel(tr("Maker:")), 2 + outputOffset, 0);
Chris@106 114 subgrid->addWidget(makerLabel, 2 + outputOffset, 1);
Chris@63 115
Chris@106 116 subgrid->addWidget(new QLabel(tr("Copyright: ")), 3 + outputOffset, 0);
Chris@106 117 subgrid->addWidget(copyrightLabel, 3 + outputOffset, 1);
Chris@106 118
Chris@106 119 subgrid->addWidget(new QLabel(tr("Version:")), 4 + outputOffset, 0);
Chris@106 120 subgrid->addWidget(versionLabel, 4 + outputOffset, 1);
Chris@62 121
Chris@62 122 subgrid->setColumnStretch(1, 2);
Chris@62 123
Chris@62 124 QGroupBox *paramBox = new QGroupBox;
Chris@62 125 paramBox->setTitle(tr("Plugin Parameters"));
Chris@62 126 grid->addWidget(paramBox, 1, 0);
Chris@62 127 grid->setRowStretch(1, 10);
Chris@62 128
Chris@62 129 QHBoxLayout *paramLayout = new QHBoxLayout;
Chris@63 130 paramLayout->setMargin(0);
Chris@62 131 paramBox->setLayout(paramLayout);
Chris@62 132
Chris@62 133 m_parameterBox = new PluginParameterBox(m_plugin);
Chris@64 134 connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)),
Chris@64 135 this, SIGNAL(pluginConfigurationChanged(QString)));
Chris@62 136 paramLayout->addWidget(m_parameterBox);
Chris@62 137
Chris@143 138 m_advanced = new QFrame;
Chris@143 139 QVBoxLayout *advancedLayout = new QVBoxLayout;
Chris@143 140 advancedLayout->setMargin(0);
Chris@143 141 m_advanced->setLayout(advancedLayout);
Chris@143 142 grid->addWidget(m_advanced, 2, 0);
Chris@143 143
Chris@143 144 bool haveAdvanced = false;
Chris@143 145
Chris@69 146 if (sourceChannels != targetChannels) {
Chris@69 147
Chris@69 148 // At the moment we can only cope with the case where
Chris@69 149 // sourceChannels > targetChannels and targetChannels == 1
Chris@69 150
Chris@69 151 if (sourceChannels < targetChannels) {
Chris@69 152
Chris@69 153 QMessageBox::warning
Chris@69 154 (parent,
Chris@69 155 tr("Channel mismatch"),
Chris@69 156 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 157 QMessageBox::Ok,
Chris@69 158 QMessageBox::NoButton);
Chris@69 159
Chris@69 160 } else {
Chris@69 161
Chris@69 162 QGroupBox *channelBox = new QGroupBox;
Chris@69 163 channelBox->setTitle(tr("Channels"));
Chris@143 164 advancedLayout->addWidget(channelBox);
Chris@143 165 haveAdvanced = true;
Chris@69 166
Chris@69 167 QVBoxLayout *channelLayout = new QVBoxLayout;
Chris@69 168 channelBox->setLayout(channelLayout);
Chris@69 169
Chris@69 170 if (targetChannels != 1) {
Chris@69 171
Chris@69 172 channelLayout->addWidget
Chris@69 173 (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 174 .arg(targetChannels)
Chris@69 175 .arg(sourceChannels)
Chris@69 176 .arg(targetChannels)));
Chris@69 177
Chris@69 178 } else {
Chris@69 179
Chris@69 180 channelLayout->addWidget(new QLabel(tr("This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels)));
Chris@69 181
Chris@69 182 QComboBox *channelCombo = new QComboBox;
Chris@76 183 channelCombo->addItem(tr("Use mean of source channels"));
Chris@69 184 for (int i = 0; i < sourceChannels; ++i) {
Chris@69 185 channelCombo->addItem(tr("Use channel %1 only").arg(i + 1));
Chris@69 186 }
Chris@69 187
Chris@69 188 connect(channelCombo, SIGNAL(activated(int)),
Chris@69 189 this, SLOT(channelComboChanged(int)));
Chris@69 190
Chris@69 191 channelLayout->addWidget(channelCombo);
Chris@69 192 }
Chris@69 193 }
Chris@69 194 }
Chris@69 195
Chris@140 196 if (showWindowSize) {
Chris@140 197
Chris@140 198 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(plugin);
Chris@140 199 int size = 1024;
Chris@140 200 int increment = 1024;
Chris@140 201 if (fePlugin) {
Chris@140 202 size = fePlugin->getPreferredBlockSize();
Chris@140 203 if (size == 0) size = 1024;
Chris@140 204 increment = fePlugin->getPreferredStepSize();
Chris@140 205 if (increment == 0) increment = size;
Chris@140 206 }
Chris@140 207
Chris@140 208 QGroupBox *windowBox = new QGroupBox;
Chris@140 209 windowBox->setTitle(tr("Processing"));
Chris@143 210 advancedLayout->addWidget(windowBox);
Chris@143 211 haveAdvanced = true;
Chris@140 212
Chris@140 213 QGridLayout *windowLayout = new QGridLayout;
Chris@140 214 windowBox->setLayout(windowLayout);
Chris@140 215
Chris@140 216 if (showFrequencyDomainOptions) {
Chris@140 217 windowLayout->addWidget(new QLabel(tr("Window size:")), 0, 0);
Chris@140 218 } else {
Chris@140 219 windowLayout->addWidget(new QLabel(tr("Audio frames per block:")), 0, 0);
Chris@140 220 }
Chris@140 221
Chris@143 222 std::cerr << "size: " << size << ", increment: " << increment << std::endl;
Chris@143 223
Chris@140 224 QComboBox *blockSizeCombo = new QComboBox;
Chris@140 225 blockSizeCombo->setEditable(true);
Chris@143 226 for (int i = 0; i < 14; ++i) {
Chris@140 227 int val = pow(2, i + 3);
Chris@140 228 blockSizeCombo->addItem(QString("%1").arg(val));
Chris@140 229 if (val == size) blockSizeCombo->setCurrentIndex(i);
Chris@140 230 }
Chris@143 231 blockSizeCombo->setValidator(new QIntValidator(1, pow(2, 18), this));
Chris@140 232 windowLayout->addWidget(blockSizeCombo, 0, 1);
Chris@140 233
Chris@140 234 if (showFrequencyDomainOptions) {
Chris@140 235
Chris@140 236 windowLayout->addWidget(new QLabel(tr("Window increment:")), 1, 0);
Chris@140 237
Chris@140 238 QComboBox *incrementCombo = new QComboBox;
Chris@140 239 incrementCombo->setEditable(true);
Chris@143 240 for (int i = 0; i < 14; ++i) {
Chris@140 241 int val = pow(2, i + 3);
Chris@140 242 incrementCombo->addItem(QString("%1").arg(val));
Chris@143 243 if (val == increment) incrementCombo->setCurrentIndex(i);
Chris@140 244 }
Chris@143 245 incrementCombo->setValidator(new QIntValidator(1, pow(2, 18), this));
Chris@140 246 windowLayout->addWidget(incrementCombo, 1, 1);
Chris@140 247
Chris@140 248 windowLayout->addWidget(new QLabel(tr("Window shape:")), 2, 0);
Chris@140 249 WindowTypeSelector *windowTypeSelector = new WindowTypeSelector;
Chris@140 250 windowLayout->addWidget(windowTypeSelector, 2, 1);
Chris@140 251 }
Chris@140 252 }
Chris@140 253
Chris@140 254 //!!! We lack a comfortable way of passing around the channel and
Chris@140 255 //blocksize data
Chris@140 256
Chris@62 257 QHBoxLayout *hbox = new QHBoxLayout;
Chris@140 258 grid->addLayout(hbox, 4, 0);
Chris@143 259
Chris@143 260 bool advancedVisible = false;
Chris@143 261
Chris@143 262 if (haveAdvanced) {
Chris@143 263
Chris@143 264 m_advancedButton = new QPushButton(tr("Advanced >>"));
Chris@143 265 m_advancedButton->setCheckable(true);
Chris@143 266 connect(m_advancedButton, SIGNAL(clicked()), this, SLOT(advancedToggled()));
Chris@143 267
Chris@143 268 QSettings settings;
Chris@143 269 settings.beginGroup("PluginParameterDialog");
Chris@143 270 advancedVisible = settings.value("advancedvisible", false).toBool();
Chris@143 271 settings.endGroup();
Chris@143 272
Chris@143 273 m_advanced->setVisible(false);
Chris@143 274
Chris@143 275 hbox->addWidget(m_advancedButton);
Chris@143 276 }
Chris@143 277
Chris@62 278 QPushButton *ok = new QPushButton(tr("OK"));
Chris@62 279 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@62 280 hbox->addStretch(10);
Chris@62 281 hbox->addWidget(ok);
Chris@62 282 hbox->addWidget(cancel);
Chris@62 283 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@62 284 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@143 285
Chris@143 286 if (advancedVisible) {
Chris@143 287 m_advancedButton->setChecked(true);
Chris@143 288 advancedToggled();
Chris@143 289 }
Chris@62 290 }
Chris@62 291
Chris@62 292 PluginParameterDialog::~PluginParameterDialog()
Chris@62 293 {
Chris@62 294 }
Chris@62 295
Chris@69 296 void
Chris@143 297 PluginParameterDialog::advancedToggled()
Chris@143 298 {
Chris@143 299 bool visible = !m_advanced->isVisible();
Chris@143 300
Chris@143 301 m_advanced->setVisible(visible);
Chris@143 302
Chris@143 303 if (visible) m_advancedButton->setText(tr("Advanced <<"));
Chris@143 304 else m_advancedButton->setText(tr("Advanced >>"));
Chris@143 305
Chris@143 306 QSettings settings;
Chris@143 307 settings.beginGroup("PluginParameterDialog");
Chris@143 308 settings.setValue("advancedvisible", visible);
Chris@143 309 settings.endGroup();
Chris@143 310
Chris@143 311 std::cerr << "resize to " << sizeHint().width() << " x " << sizeHint().height() << std::endl;
Chris@143 312
Chris@143 313 setMaximumSize(sizeHint());
Chris@143 314 }
Chris@143 315
Chris@143 316 void
Chris@69 317 PluginParameterDialog::channelComboChanged(int index)
Chris@69 318 {
Chris@69 319 m_channel = index - 1;
Chris@69 320 }
Chris@69 321