annotate widgets/PluginParameterDialog.cpp @ 122:71992cee2ece

* Finish preferences dialog (as far as it's going at the moment) and connect it up * Fix Parzen window shape (was triangular!) * Various fixes to spectrogram draw coordinates in smoothing mode etc * Draw C keys in grey on the piano
author Chris Cannam
date Fri, 21 Jul 2006 16:03:42 +0000
parents 551d7ae05526
children b9235b62fe31
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@62 19
Chris@106 20 #include "vamp-sdk/Plugin.h"
Chris@106 21
Chris@62 22 #include <QGridLayout>
Chris@62 23 #include <QLabel>
Chris@62 24 #include <QGroupBox>
Chris@62 25 #include <QHBoxLayout>
Chris@62 26 #include <QPushButton>
Chris@69 27 #include <QMessageBox>
Chris@69 28 #include <QComboBox>
Chris@62 29
Chris@71 30 PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin,
Chris@69 31 int sourceChannels,
Chris@69 32 int targetChannels,
Chris@69 33 int defaultChannel,
Chris@106 34 QString output,
Chris@62 35 QWidget *parent) :
Chris@62 36 QDialog(parent),
Chris@62 37 m_plugin(plugin),
Chris@69 38 m_channel(defaultChannel),
Chris@62 39 m_parameterBox(0)
Chris@62 40 {
Chris@122 41 setWindowTitle(tr("Plugin Parameters"));
Chris@122 42
Chris@62 43 QGridLayout *grid = new QGridLayout;
Chris@62 44 setLayout(grid);
Chris@62 45
Chris@62 46 QGroupBox *pluginBox = new QGroupBox;
Chris@62 47 pluginBox->setTitle(tr("Plugin"));
Chris@62 48 grid->addWidget(pluginBox, 0, 0);
Chris@62 49
Chris@62 50 QGridLayout *subgrid = new QGridLayout;
Chris@62 51 pluginBox->setLayout(subgrid);
Chris@62 52
Chris@63 53 subgrid->setSpacing(0);
Chris@63 54 subgrid->setMargin(10);
Chris@63 55
Chris@62 56 QFont font(pluginBox->font());
Chris@62 57 font.setBold(true);
Chris@62 58
Chris@62 59 QLabel *nameLabel = new QLabel(plugin->getDescription().c_str());
Chris@62 60 nameLabel->setFont(font);
Chris@62 61
Chris@62 62 QLabel *makerLabel = new QLabel(plugin->getMaker().c_str());
Chris@62 63
Chris@106 64 QLabel *outputLabel = 0;
Chris@106 65
Chris@106 66 if (output != "") {
Chris@106 67
Chris@106 68 Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(plugin);
Chris@106 69
Chris@106 70 if (fePlugin) {
Chris@106 71
Chris@106 72 std::vector<Vamp::Plugin::OutputDescriptor> od =
Chris@106 73 fePlugin->getOutputDescriptors();
Chris@106 74
Chris@106 75 if (od.size() > 1) {
Chris@106 76
Chris@106 77 for (size_t i = 0; i < od.size(); ++i) {
Chris@106 78 if (od[i].name == output.toStdString()) {
Chris@106 79 outputLabel = new QLabel(od[i].description.c_str());
Chris@106 80 break;
Chris@106 81 }
Chris@106 82 }
Chris@106 83 }
Chris@106 84 }
Chris@106 85 }
Chris@106 86
Chris@62 87 QLabel *versionLabel = new QLabel(QString("%1")
Chris@62 88 .arg(plugin->getPluginVersion()));
Chris@62 89
Chris@62 90 QLabel *copyrightLabel = new QLabel(plugin->getCopyright().c_str());
Chris@62 91
Chris@63 92 QLabel *typeLabel = new QLabel(plugin->getType().c_str());
Chris@63 93 typeLabel->setFont(font);
Chris@63 94
Chris@62 95 subgrid->addWidget(new QLabel(tr("Name:")), 0, 0);
Chris@62 96 subgrid->addWidget(nameLabel, 0, 1);
Chris@62 97
Chris@63 98 subgrid->addWidget(new QLabel(tr("Type:")), 1, 0);
Chris@63 99 subgrid->addWidget(typeLabel, 1, 1);
Chris@62 100
Chris@106 101 int outputOffset = 0;
Chris@106 102 if (outputLabel) {
Chris@106 103 subgrid->addWidget(new QLabel(tr("Output:")), 2, 0);
Chris@106 104 subgrid->addWidget(outputLabel, 2, 1);
Chris@106 105 outputOffset = 1;
Chris@106 106 }
Chris@62 107
Chris@106 108 subgrid->addWidget(new QLabel(tr("Maker:")), 2 + outputOffset, 0);
Chris@106 109 subgrid->addWidget(makerLabel, 2 + outputOffset, 1);
Chris@63 110
Chris@106 111 subgrid->addWidget(new QLabel(tr("Copyright: ")), 3 + outputOffset, 0);
Chris@106 112 subgrid->addWidget(copyrightLabel, 3 + outputOffset, 1);
Chris@106 113
Chris@106 114 subgrid->addWidget(new QLabel(tr("Version:")), 4 + outputOffset, 0);
Chris@106 115 subgrid->addWidget(versionLabel, 4 + outputOffset, 1);
Chris@62 116
Chris@62 117 subgrid->setColumnStretch(1, 2);
Chris@62 118
Chris@62 119 QGroupBox *paramBox = new QGroupBox;
Chris@62 120 paramBox->setTitle(tr("Plugin Parameters"));
Chris@62 121 grid->addWidget(paramBox, 1, 0);
Chris@62 122 grid->setRowStretch(1, 10);
Chris@62 123
Chris@62 124 QHBoxLayout *paramLayout = new QHBoxLayout;
Chris@63 125 paramLayout->setMargin(0);
Chris@62 126 paramBox->setLayout(paramLayout);
Chris@62 127
Chris@62 128 m_parameterBox = new PluginParameterBox(m_plugin);
Chris@64 129 connect(m_parameterBox, SIGNAL(pluginConfigurationChanged(QString)),
Chris@64 130 this, SIGNAL(pluginConfigurationChanged(QString)));
Chris@62 131 paramLayout->addWidget(m_parameterBox);
Chris@62 132
Chris@69 133 if (sourceChannels != targetChannels) {
Chris@69 134
Chris@69 135 // At the moment we can only cope with the case where
Chris@69 136 // sourceChannels > targetChannels and targetChannels == 1
Chris@69 137
Chris@69 138 if (sourceChannels < targetChannels) {
Chris@69 139
Chris@69 140 QMessageBox::warning
Chris@69 141 (parent,
Chris@69 142 tr("Channel mismatch"),
Chris@69 143 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 144 QMessageBox::Ok,
Chris@69 145 QMessageBox::NoButton);
Chris@69 146
Chris@69 147 } else {
Chris@69 148
Chris@69 149 QGroupBox *channelBox = new QGroupBox;
Chris@69 150 channelBox->setTitle(tr("Channels"));
Chris@69 151 grid->addWidget(channelBox, 2, 0);
Chris@69 152
Chris@69 153 QVBoxLayout *channelLayout = new QVBoxLayout;
Chris@69 154 channelBox->setLayout(channelLayout);
Chris@69 155
Chris@69 156 if (targetChannels != 1) {
Chris@69 157
Chris@69 158 channelLayout->addWidget
Chris@69 159 (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 160 .arg(targetChannels)
Chris@69 161 .arg(sourceChannels)
Chris@69 162 .arg(targetChannels)));
Chris@69 163
Chris@69 164 } else {
Chris@69 165
Chris@69 166 channelLayout->addWidget(new QLabel(tr("This plugin only has a single channel input,\nbut the source has %1 channels.").arg(sourceChannels)));
Chris@69 167
Chris@69 168 QComboBox *channelCombo = new QComboBox;
Chris@76 169 channelCombo->addItem(tr("Use mean of source channels"));
Chris@69 170 for (int i = 0; i < sourceChannels; ++i) {
Chris@69 171 channelCombo->addItem(tr("Use channel %1 only").arg(i + 1));
Chris@69 172 }
Chris@69 173
Chris@69 174 connect(channelCombo, SIGNAL(activated(int)),
Chris@69 175 this, SLOT(channelComboChanged(int)));
Chris@69 176
Chris@69 177 channelLayout->addWidget(channelCombo);
Chris@69 178 }
Chris@69 179 }
Chris@69 180 }
Chris@69 181
Chris@62 182 QHBoxLayout *hbox = new QHBoxLayout;
Chris@69 183 grid->addLayout(hbox, 3, 0);
Chris@62 184
Chris@62 185 QPushButton *ok = new QPushButton(tr("OK"));
Chris@62 186 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@62 187 hbox->addStretch(10);
Chris@62 188 hbox->addWidget(ok);
Chris@62 189 hbox->addWidget(cancel);
Chris@62 190 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@62 191 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@62 192 }
Chris@62 193
Chris@62 194 PluginParameterDialog::~PluginParameterDialog()
Chris@62 195 {
Chris@62 196 }
Chris@62 197
Chris@69 198 void
Chris@69 199 PluginParameterDialog::channelComboChanged(int index)
Chris@69 200 {
Chris@69 201 m_channel = index - 1;
Chris@69 202 }
Chris@69 203