annotate widgets/PluginParameterDialog.cpp @ 140:b9235b62fe31

* add window size/increment/shape settings to plugin parameter dialog, though they aren't yet connected up
author Chris Cannam
date Mon, 11 Sep 2006 16:40:18 +0000
parents 71992cee2ece
children bcb6d71be63c
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@62 27 #include <QPushButton>
Chris@69 28 #include <QMessageBox>
Chris@69 29 #include <QComboBox>
Chris@62 30
Chris@71 31 PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin,
Chris@69 32 int sourceChannels,
Chris@69 33 int targetChannels,
Chris@69 34 int defaultChannel,
Chris@106 35 QString output,
Chris@140 36 bool showWindowSize,
Chris@140 37 bool showFrequencyDomainOptions,
Chris@62 38 QWidget *parent) :
Chris@62 39 QDialog(parent),
Chris@62 40 m_plugin(plugin),
Chris@69 41 m_channel(defaultChannel),
Chris@62 42 m_parameterBox(0)
Chris@62 43 {
Chris@122 44 setWindowTitle(tr("Plugin Parameters"));
Chris@122 45
Chris@62 46 QGridLayout *grid = new QGridLayout;
Chris@62 47 setLayout(grid);
Chris@62 48
Chris@62 49 QGroupBox *pluginBox = new QGroupBox;
Chris@62 50 pluginBox->setTitle(tr("Plugin"));
Chris@62 51 grid->addWidget(pluginBox, 0, 0);
Chris@62 52
Chris@62 53 QGridLayout *subgrid = new QGridLayout;
Chris@62 54 pluginBox->setLayout(subgrid);
Chris@62 55
Chris@63 56 subgrid->setSpacing(0);
Chris@63 57 subgrid->setMargin(10);
Chris@63 58
Chris@62 59 QFont font(pluginBox->font());
Chris@62 60 font.setBold(true);
Chris@62 61
Chris@62 62 QLabel *nameLabel = new QLabel(plugin->getDescription().c_str());
Chris@62 63 nameLabel->setFont(font);
Chris@62 64
Chris@62 65 QLabel *makerLabel = new QLabel(plugin->getMaker().c_str());
Chris@62 66
Chris@106 67 QLabel *outputLabel = 0;
Chris@106 68
Chris@106 69 if (output != "") {
Chris@106 70
Chris@106 71 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(plugin);
Chris@106 72
Chris@106 73 if (fePlugin) {
Chris@106 74
Chris@106 75 std::vector<Vamp::Plugin::OutputDescriptor> od =
Chris@106 76 fePlugin->getOutputDescriptors();
Chris@106 77
Chris@106 78 if (od.size() > 1) {
Chris@106 79
Chris@106 80 for (size_t i = 0; i < od.size(); ++i) {
Chris@106 81 if (od[i].name == output.toStdString()) {
Chris@106 82 outputLabel = new QLabel(od[i].description.c_str());
Chris@106 83 break;
Chris@106 84 }
Chris@106 85 }
Chris@106 86 }
Chris@106 87 }
Chris@106 88 }
Chris@106 89
Chris@62 90 QLabel *versionLabel = new QLabel(QString("%1")
Chris@62 91 .arg(plugin->getPluginVersion()));
Chris@62 92
Chris@62 93 QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str());
Chris@62 94
Chris@63 95 QLabel *typeLabel = new QLabel(plugin->getType().c_str());
Chris@63 96 typeLabel->setFont(font);
Chris@63 97
Chris@62 98 subgrid->addWidget(new QLabel(tr("Name:")), 0, 0);
Chris@62 99 subgrid->addWidget(nameLabel, 0, 1);
Chris@62 100
Chris@63 101 subgrid->addWidget(new QLabel(tr("Type:")), 1, 0);
Chris@63 102 subgrid->addWidget(typeLabel, 1, 1);
Chris@62 103
Chris@106 104 int outputOffset = 0;
Chris@106 105 if (outputLabel) {
Chris@106 106 subgrid->addWidget(new QLabel(tr("Output:")), 2, 0);
Chris@106 107 subgrid->addWidget(outputLabel, 2, 1);
Chris@106 108 outputOffset = 1;
Chris@106 109 }
Chris@62 110
Chris@106 111 subgrid->addWidget(new QLabel(tr("Maker:")), 2 + outputOffset, 0);
Chris@106 112 subgrid->addWidget(makerLabel, 2 + outputOffset, 1);
Chris@63 113
Chris@106 114 subgrid->addWidget(new QLabel(tr("Copyright: ")), 3 + outputOffset, 0);
Chris@106 115 subgrid->addWidget(copyrightLabel, 3 + outputOffset, 1);
Chris@106 116
Chris@106 117 subgrid->addWidget(new QLabel(tr("Version:")), 4 + outputOffset, 0);
Chris@106 118 subgrid->addWidget(versionLabel, 4 + outputOffset, 1);
Chris@62 119
Chris@62 120 subgrid->setColumnStretch(1, 2);
Chris@62 121
Chris@62 122 QGroupBox *paramBox = new QGroupBox;
Chris@62 123 paramBox->setTitle(tr("Plugin Parameters"));
Chris@62 124 grid->addWidget(paramBox, 1, 0);
Chris@62 125 grid->setRowStretch(1, 10);
Chris@62 126
Chris@62 127 QHBoxLayout *paramLayout = new QHBoxLayout;
Chris@63 128 paramLayout->setMargin(0);
Chris@62 129 paramBox->setLayout(paramLayout);
Chris@62 130
Chris@62 131 m_parameterBox = new PluginParameterBox(m_plugin);
Chris@64 132 connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)),
Chris@64 133 this, SIGNAL(pluginConfigurationChanged(QString)));
Chris@62 134 paramLayout->addWidget(m_parameterBox);
Chris@62 135
Chris@69 136 if (sourceChannels != targetChannels) {
Chris@69 137
Chris@69 138 // At the moment we can only cope with the case where
Chris@69 139 // sourceChannels > targetChannels and targetChannels == 1
Chris@69 140
Chris@69 141 if (sourceChannels < targetChannels) {
Chris@69 142
Chris@69 143 QMessageBox::warning
Chris@69 144 (parent,
Chris@69 145 tr("Channel mismatch"),
Chris@69 146 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 147 QMessageBox::Ok,
Chris@69 148 QMessageBox::NoButton);
Chris@69 149
Chris@69 150 } else {
Chris@69 151
Chris@69 152 QGroupBox *channelBox = new QGroupBox;
Chris@69 153 channelBox->setTitle(tr("Channels"));
Chris@69 154 grid->addWidget(channelBox, 2, 0);
Chris@69 155
Chris@69 156 QVBoxLayout *channelLayout = new QVBoxLayout;
Chris@69 157 channelBox->setLayout(channelLayout);
Chris@69 158
Chris@69 159 if (targetChannels != 1) {
Chris@69 160
Chris@69 161 channelLayout->addWidget
Chris@69 162 (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 163 .arg(targetChannels)
Chris@69 164 .arg(sourceChannels)
Chris@69 165 .arg(targetChannels)));
Chris@69 166
Chris@69 167 } else {
Chris@69 168
Chris@69 169 channelLayout->addWidget(new QLabel(tr("This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels)));
Chris@69 170
Chris@69 171 QComboBox *channelCombo = new QComboBox;
Chris@76 172 channelCombo->addItem(tr("Use mean of source channels"));
Chris@69 173 for (int i = 0; i < sourceChannels; ++i) {
Chris@69 174 channelCombo->addItem(tr("Use channel %1 only").arg(i + 1));
Chris@69 175 }
Chris@69 176
Chris@69 177 connect(channelCombo, SIGNAL(activated(int)),
Chris@69 178 this, SLOT(channelComboChanged(int)));
Chris@69 179
Chris@69 180 channelLayout->addWidget(channelCombo);
Chris@69 181 }
Chris@69 182 }
Chris@69 183 }
Chris@69 184
Chris@140 185 if (showWindowSize) {
Chris@140 186
Chris@140 187 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(plugin);
Chris@140 188 int size = 1024;
Chris@140 189 int increment = 1024;
Chris@140 190 if (fePlugin) {
Chris@140 191 size = fePlugin->getPreferredBlockSize();
Chris@140 192 if (size == 0) size = 1024;
Chris@140 193 increment = fePlugin->getPreferredStepSize();
Chris@140 194 if (increment == 0) increment = size;
Chris@140 195 }
Chris@140 196
Chris@140 197 QGroupBox *windowBox = new QGroupBox;
Chris@140 198 windowBox->setTitle(tr("Processing"));
Chris@140 199 grid->addWidget(windowBox, 3, 0);
Chris@140 200
Chris@140 201 QGridLayout *windowLayout = new QGridLayout;
Chris@140 202 windowBox->setLayout(windowLayout);
Chris@140 203
Chris@140 204 if (showFrequencyDomainOptions) {
Chris@140 205 windowLayout->addWidget(new QLabel(tr("Window size:")), 0, 0);
Chris@140 206 } else {
Chris@140 207 windowLayout->addWidget(new QLabel(tr("Audio frames per block:")), 0, 0);
Chris@140 208 }
Chris@140 209
Chris@140 210 QComboBox *blockSizeCombo = new QComboBox;
Chris@140 211 blockSizeCombo->setEditable(true);
Chris@140 212 //!!! integer validator
Chris@140 213 for (int i = 0; i < 12; ++i) {
Chris@140 214 int val = pow(2, i + 3);
Chris@140 215 blockSizeCombo->addItem(QString("%1").arg(val));
Chris@140 216 if (val == size) blockSizeCombo->setCurrentIndex(i);
Chris@140 217 }
Chris@140 218 windowLayout->addWidget(blockSizeCombo, 0, 1);
Chris@140 219
Chris@140 220 if (showFrequencyDomainOptions) {
Chris@140 221
Chris@140 222 windowLayout->addWidget(new QLabel(tr("Window increment:")), 1, 0);
Chris@140 223
Chris@140 224 QComboBox *incrementCombo = new QComboBox;
Chris@140 225 incrementCombo->setEditable(true);
Chris@140 226 //!!! integer validator
Chris@140 227 for (int i = 0; i < 12; ++i) {
Chris@140 228 int val = pow(2, i + 3);
Chris@140 229 incrementCombo->addItem(QString("%1").arg(val));
Chris@140 230 if (val == increment) blockSizeCombo->setCurrentIndex(i);
Chris@140 231 }
Chris@140 232 windowLayout->addWidget(incrementCombo, 1, 1);
Chris@140 233
Chris@140 234 windowLayout->addWidget(new QLabel(tr("Window shape:")), 2, 0);
Chris@140 235 WindowTypeSelector *windowTypeSelector = new WindowTypeSelector;
Chris@140 236 windowLayout->addWidget(windowTypeSelector, 2, 1);
Chris@140 237 }
Chris@140 238 }
Chris@140 239
Chris@140 240 //!!! We lack a comfortable way of passing around the channel and
Chris@140 241 //blocksize data
Chris@140 242
Chris@62 243 QHBoxLayout *hbox = new QHBoxLayout;
Chris@140 244 grid->addLayout(hbox, 4, 0);
Chris@62 245
Chris@62 246 QPushButton *ok = new QPushButton(tr("OK"));
Chris@62 247 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@62 248 hbox->addStretch(10);
Chris@62 249 hbox->addWidget(ok);
Chris@62 250 hbox->addWidget(cancel);
Chris@62 251 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@62 252 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@62 253 }
Chris@62 254
Chris@62 255 PluginParameterDialog::~PluginParameterDialog()
Chris@62 256 {
Chris@62 257 }
Chris@62 258
Chris@69 259 void
Chris@69 260 PluginParameterDialog::channelComboChanged(int index)
Chris@69 261 {
Chris@69 262 m_channel = index - 1;
Chris@69 263 }
Chris@69 264