annotate widgets/PluginParameterBox.cpp @ 62:50429a56680f

* Add plugin parameter dialog, and use it to set up parameters for feature extraction plugins via a semi-opaque (translucent?) configurationXml string which is associated with a given transform instance. This is not yet saved to and restored from the SV file properly. * Remove no-longer-relevant BeatDetect and BeatDetectionFunction transforms (replaced a long time ago with the beat detector plugin).
author Chris Cannam
date Wed, 22 Mar 2006 17:38:29 +0000
parents 4df1a479bf10
children fb02fe13ff47
rev   line source
Chris@60 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@60 2
Chris@60 3 /*
Chris@60 4 Sonic Visualiser
Chris@60 5 An audio file viewer and annotation editor.
Chris@60 6 Centre for Digital Music, Queen Mary, University of London.
Chris@60 7 This file copyright 2006 Chris Cannam.
Chris@60 8
Chris@60 9 This program is free software; you can redistribute it and/or
Chris@60 10 modify it under the terms of the GNU General Public License as
Chris@60 11 published by the Free Software Foundation; either version 2 of the
Chris@60 12 License, or (at your option) any later version. See the file
Chris@60 13 COPYING included with this distribution for more information.
Chris@60 14 */
Chris@60 15
Chris@60 16 #include "PluginParameterBox.h"
Chris@60 17
Chris@60 18 #include "AudioDial.h"
Chris@60 19
Chris@60 20 #include <QDoubleSpinBox>
Chris@60 21 #include <QGridLayout>
Chris@60 22 #include <QLayout>
Chris@60 23 #include <QLabel>
Chris@60 24
Chris@60 25 #include <iostream>
Chris@60 26 #include <string>
Chris@60 27
Chris@62 28 PluginParameterBox::PluginParameterBox(PluginInstance *plugin, QWidget *parent) :
Chris@62 29 QFrame(parent),
Chris@60 30 m_plugin(plugin)
Chris@60 31 {
Chris@60 32 m_layout = new QGridLayout;
Chris@60 33 setLayout(m_layout);
Chris@60 34 populate();
Chris@60 35 }
Chris@60 36
Chris@60 37 PluginParameterBox::~PluginParameterBox()
Chris@60 38 {
Chris@60 39 }
Chris@60 40
Chris@60 41 void
Chris@60 42 PluginParameterBox::populate()
Chris@60 43 {
Chris@60 44 PluginInstance::ParameterList params = m_plugin->getParameterDescriptors();
Chris@60 45
Chris@60 46 m_params.clear();
Chris@60 47
Chris@62 48 if (params.empty()) {
Chris@62 49 m_layout->addWidget
Chris@62 50 (new QLabel(tr("This plugin has no adjustable parameters.")),
Chris@62 51 0, 0);
Chris@62 52 }
Chris@62 53
Chris@60 54 for (size_t i = 0; i < params.size(); ++i) {
Chris@60 55
Chris@60 56 QString name = params[i].name.c_str();
Chris@60 57 QString description = params[i].description.c_str();
Chris@60 58 QString unit = params[i].unit.c_str();
Chris@60 59
Chris@60 60 float min = params[i].minValue;
Chris@60 61 float max = params[i].maxValue;
Chris@60 62 float deft = params[i].defaultValue;
Chris@62 63 float value = m_plugin->getParameter(params[i].name);
Chris@60 64
Chris@60 65 float qtz = 0.0;
Chris@60 66 if (params[i].isQuantized) qtz = params[i].quantizeStep;
Chris@60 67
Chris@60 68 // construct an integer range
Chris@60 69
Chris@60 70 int imin = 0, imax = 100;
Chris@60 71
Chris@60 72 if (qtz > 0.0) {
Chris@60 73 imax = int((max - min) / qtz);
Chris@60 74 } else {
Chris@60 75 qtz = (max - min) / 100.0;
Chris@60 76 }
Chris@60 77
Chris@60 78 //!!! would be nice to ensure the default value corresponds to
Chris@60 79 // an integer!
Chris@60 80
Chris@60 81 QLabel *label = new QLabel(description);
Chris@60 82 m_layout->addWidget(label, i, 0);
Chris@60 83
Chris@60 84 AudioDial *dial = new AudioDial;
Chris@60 85 dial->setObjectName(name);
Chris@60 86 dial->setMinimum(imin);
Chris@60 87 dial->setMaximum(imax);
Chris@60 88 dial->setPageStep(1);
Chris@60 89 dial->setNotchesVisible((imax - imin) <= 12);
Chris@60 90 dial->setDefaultValue(int((deft - min) / qtz));
Chris@62 91 dial->setValue(int((value - min) / qtz));
Chris@62 92 dial->setFixedWidth(32);
Chris@62 93 dial->setFixedHeight(32);
Chris@60 94 connect(dial, SIGNAL(valueChanged(int)),
Chris@60 95 this, SLOT(dialChanged(int)));
Chris@60 96 m_layout->addWidget(dial, i, 1);
Chris@60 97
Chris@60 98 QDoubleSpinBox *spinbox = new QDoubleSpinBox;
Chris@60 99 spinbox->setObjectName(name);
Chris@60 100 spinbox->setMinimum(min);
Chris@60 101 spinbox->setMaximum(max);
Chris@62 102 spinbox->setSuffix(QString(" %1").arg(unit));
Chris@60 103 spinbox->setSingleStep(qtz);
Chris@62 104 spinbox->setValue(value);
Chris@60 105 connect(spinbox, SIGNAL(valueChanged(double)),
Chris@60 106 this, SLOT(spinBoxChanged(double)));
Chris@60 107 m_layout->addWidget(spinbox, i, 2);
Chris@60 108
Chris@60 109 ParamRec rec;
Chris@60 110 rec.dial = dial;
Chris@60 111 rec.spin = spinbox;
Chris@60 112 rec.param = params[i];
Chris@60 113 m_params[name] = rec;
Chris@60 114 }
Chris@60 115 }
Chris@60 116
Chris@60 117 void
Chris@60 118 PluginParameterBox::dialChanged(int ival)
Chris@60 119 {
Chris@60 120 QObject *obj = sender();
Chris@60 121 QString name = obj->objectName();
Chris@60 122
Chris@60 123 if (m_params.find(name) == m_params.end()) {
Chris@60 124 std::cerr << "WARNING: PluginParameterBox::dialChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
Chris@60 125 return;
Chris@60 126 }
Chris@60 127
Chris@60 128 PluginInstance::ParameterDescriptor params = m_params[name].param;
Chris@60 129
Chris@60 130 float min = params.minValue;
Chris@60 131 float max = params.maxValue;
Chris@60 132
Chris@60 133 float qtz = 0.0;
Chris@60 134 if (params.isQuantized) qtz = params.quantizeStep;
Chris@60 135
Chris@60 136 if (qtz == 0.0) {
Chris@60 137 qtz = (max - min) / 100.0;
Chris@60 138 }
Chris@60 139
Chris@60 140 float newValue = min + ival * qtz;
Chris@60 141
Chris@60 142 QDoubleSpinBox *spin = m_params[name].spin;
Chris@60 143 spin->blockSignals(true);
Chris@60 144 spin->setValue(newValue);
Chris@60 145 spin->blockSignals(false);
Chris@60 146
Chris@60 147 m_plugin->setParameter(name.toStdString(), newValue);
Chris@60 148 }
Chris@60 149
Chris@60 150 void
Chris@60 151 PluginParameterBox::spinBoxChanged(double value)
Chris@60 152 {
Chris@60 153 QObject *obj = sender();
Chris@60 154 QString name = obj->objectName();
Chris@60 155
Chris@60 156 if (m_params.find(name) == m_params.end()) {
Chris@60 157 std::cerr << "WARNING: PluginParameterBox::spinBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
Chris@60 158 return;
Chris@60 159 }
Chris@60 160
Chris@60 161 PluginInstance::ParameterDescriptor params = m_params[name].param;
Chris@60 162
Chris@60 163 float min = params.minValue;
Chris@60 164 float max = params.maxValue;
Chris@60 165
Chris@60 166 float qtz = 0.0;
Chris@60 167 if (params.isQuantized) qtz = params.quantizeStep;
Chris@60 168
Chris@60 169 if (qtz > 0.0) {
Chris@60 170 int step = int((value - min) / qtz);
Chris@60 171 value = min + step * qtz;
Chris@60 172 }
Chris@60 173
Chris@60 174 int imin = 0, imax = 100;
Chris@60 175
Chris@60 176 if (qtz > 0.0) {
Chris@60 177 imax = int((max - min) / qtz);
Chris@60 178 } else {
Chris@60 179 qtz = (max - min) / 100.0;
Chris@60 180 }
Chris@60 181
Chris@60 182 int ival = (value - min) / qtz;
Chris@60 183
Chris@60 184 AudioDial *dial = m_params[name].dial;
Chris@60 185 dial->blockSignals(true);
Chris@60 186 dial->setValue(ival);
Chris@60 187 dial->blockSignals(false);
Chris@60 188
Chris@60 189 m_plugin->setParameter(name.toStdString(), value);
Chris@60 190 }
Chris@60 191
Chris@60 192