annotate widgets/PluginParameterDialog.cpp @ 121:7363cacf7de0

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