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@71
|
20 #include "plugin/PluginXml.h"
|
Chris@71
|
21
|
Chris@60
|
22 #include <QDoubleSpinBox>
|
Chris@60
|
23 #include <QGridLayout>
|
Chris@63
|
24 #include <QComboBox>
|
Chris@63
|
25 #include <QCheckBox>
|
Chris@60
|
26 #include <QLayout>
|
Chris@60
|
27 #include <QLabel>
|
Chris@60
|
28
|
Chris@60
|
29 #include <iostream>
|
Chris@60
|
30 #include <string>
|
Chris@60
|
31
|
Chris@71
|
32 PluginParameterBox::PluginParameterBox(Vamp::PluginBase *plugin, QWidget *parent) :
|
Chris@62
|
33 QFrame(parent),
|
Chris@60
|
34 m_plugin(plugin)
|
Chris@60
|
35 {
|
Chris@60
|
36 m_layout = new QGridLayout;
|
Chris@60
|
37 setLayout(m_layout);
|
Chris@60
|
38 populate();
|
Chris@60
|
39 }
|
Chris@60
|
40
|
Chris@60
|
41 PluginParameterBox::~PluginParameterBox()
|
Chris@60
|
42 {
|
Chris@60
|
43 }
|
Chris@60
|
44
|
Chris@60
|
45 void
|
Chris@60
|
46 PluginParameterBox::populate()
|
Chris@60
|
47 {
|
Chris@71
|
48 Vamp::PluginBase::ParameterList params = m_plugin->getParameterDescriptors();
|
Chris@71
|
49 Vamp::PluginBase::ProgramList programs = m_plugin->getPrograms();
|
Chris@60
|
50
|
Chris@60
|
51 m_params.clear();
|
Chris@60
|
52
|
Chris@63
|
53 if (params.empty() && programs.empty()) {
|
Chris@62
|
54 m_layout->addWidget
|
Chris@62
|
55 (new QLabel(tr("This plugin has no adjustable parameters.")),
|
Chris@62
|
56 0, 0);
|
Chris@62
|
57 }
|
Chris@62
|
58
|
Chris@63
|
59 int offset = 0;
|
Chris@63
|
60
|
Chris@63
|
61 if (!programs.empty()) {
|
Chris@63
|
62
|
Chris@63
|
63 std::string currentProgram = m_plugin->getCurrentProgram();
|
Chris@63
|
64
|
Chris@63
|
65 QComboBox *programCombo = new QComboBox;
|
Chris@63
|
66 programCombo->setMaxVisibleItems(20);
|
Chris@63
|
67
|
Chris@63
|
68 for (int i = 0; i < programs.size(); ++i) {
|
Chris@63
|
69 programCombo->addItem(programs[i].c_str());
|
Chris@63
|
70 if (programs[i] == currentProgram) {
|
Chris@63
|
71 programCombo->setCurrentIndex(i);
|
Chris@63
|
72 }
|
Chris@63
|
73 }
|
Chris@63
|
74
|
Chris@63
|
75 m_layout->addWidget(new QLabel(tr("Program")), 0, 0);
|
Chris@63
|
76 m_layout->addWidget(programCombo, 0, 1, 1, 2);
|
Chris@63
|
77
|
Chris@63
|
78 connect(programCombo, SIGNAL(currentIndexChanged(const QString &)),
|
Chris@63
|
79 this, SLOT(programComboChanged(const QString &)));
|
Chris@63
|
80
|
Chris@63
|
81 offset = 1;
|
Chris@63
|
82 }
|
Chris@63
|
83
|
Chris@60
|
84 for (size_t i = 0; i < params.size(); ++i) {
|
Chris@60
|
85
|
Chris@60
|
86 QString name = params[i].name.c_str();
|
Chris@60
|
87 QString description = params[i].description.c_str();
|
Chris@60
|
88 QString unit = params[i].unit.c_str();
|
Chris@60
|
89
|
Chris@60
|
90 float min = params[i].minValue;
|
Chris@60
|
91 float max = params[i].maxValue;
|
Chris@60
|
92 float deft = params[i].defaultValue;
|
Chris@62
|
93 float value = m_plugin->getParameter(params[i].name);
|
Chris@60
|
94
|
Chris@60
|
95 float qtz = 0.0;
|
Chris@60
|
96 if (params[i].isQuantized) qtz = params[i].quantizeStep;
|
Chris@60
|
97
|
Chris@60
|
98 // construct an integer range
|
Chris@60
|
99
|
Chris@60
|
100 int imin = 0, imax = 100;
|
Chris@60
|
101
|
Chris@60
|
102 if (qtz > 0.0) {
|
Chris@60
|
103 imax = int((max - min) / qtz);
|
Chris@60
|
104 } else {
|
Chris@60
|
105 qtz = (max - min) / 100.0;
|
Chris@60
|
106 }
|
Chris@60
|
107
|
Chris@60
|
108 //!!! would be nice to ensure the default value corresponds to
|
Chris@60
|
109 // an integer!
|
Chris@60
|
110
|
Chris@60
|
111 QLabel *label = new QLabel(description);
|
Chris@63
|
112 m_layout->addWidget(label, i + offset, 0);
|
Chris@60
|
113
|
Chris@60
|
114 ParamRec rec;
|
Chris@60
|
115 rec.param = params[i];
|
Chris@63
|
116 rec.dial = 0;
|
Chris@63
|
117 rec.spin = 0;
|
Chris@63
|
118 rec.check = 0;
|
Chris@63
|
119
|
Chris@63
|
120 if (min == 0.0 && max == 1.0 && qtz == 1.0) {
|
Chris@63
|
121
|
Chris@63
|
122 QCheckBox *checkbox = new QCheckBox;
|
Chris@63
|
123 checkbox->setObjectName(name);
|
Chris@63
|
124 checkbox->setCheckState(value == 0.0 ? Qt::Unchecked : Qt::Checked);
|
Chris@63
|
125 connect(checkbox, SIGNAL(stateChanged(int)),
|
Chris@63
|
126 this, SLOT(checkBoxChanged(int)));
|
Chris@63
|
127 m_layout->addWidget(checkbox, i + offset, 2);
|
Chris@63
|
128 rec.check = checkbox;
|
Chris@63
|
129
|
Chris@63
|
130 } else {
|
Chris@63
|
131
|
Chris@63
|
132 AudioDial *dial = new AudioDial;
|
Chris@63
|
133 dial->setObjectName(name);
|
Chris@63
|
134 dial->setMinimum(imin);
|
Chris@63
|
135 dial->setMaximum(imax);
|
Chris@63
|
136 dial->setPageStep(1);
|
Chris@63
|
137 dial->setNotchesVisible((imax - imin) <= 12);
|
Chris@63
|
138 dial->setDefaultValue(int((deft - min) / qtz));
|
Chris@63
|
139 dial->setValue(int((value - min) / qtz));
|
Chris@63
|
140 dial->setFixedWidth(32);
|
Chris@63
|
141 dial->setFixedHeight(32);
|
Chris@63
|
142 connect(dial, SIGNAL(valueChanged(int)),
|
Chris@63
|
143 this, SLOT(dialChanged(int)));
|
Chris@63
|
144 m_layout->addWidget(dial, i + offset, 1);
|
Chris@63
|
145
|
Chris@63
|
146 QDoubleSpinBox *spinbox = new QDoubleSpinBox;
|
Chris@63
|
147 spinbox->setObjectName(name);
|
Chris@63
|
148 spinbox->setMinimum(min);
|
Chris@63
|
149 spinbox->setMaximum(max);
|
Chris@63
|
150 spinbox->setSuffix(QString(" %1").arg(unit));
|
Chris@63
|
151 spinbox->setSingleStep(qtz);
|
Chris@63
|
152 spinbox->setValue(value);
|
Chris@63
|
153 connect(spinbox, SIGNAL(valueChanged(double)),
|
Chris@63
|
154 this, SLOT(spinBoxChanged(double)));
|
Chris@63
|
155 m_layout->addWidget(spinbox, i + offset, 2);
|
Chris@63
|
156 rec.dial = dial;
|
Chris@63
|
157 rec.spin = spinbox;
|
Chris@63
|
158 }
|
Chris@63
|
159
|
Chris@60
|
160 m_params[name] = rec;
|
Chris@60
|
161 }
|
Chris@60
|
162 }
|
Chris@60
|
163
|
Chris@60
|
164 void
|
Chris@60
|
165 PluginParameterBox::dialChanged(int ival)
|
Chris@60
|
166 {
|
Chris@60
|
167 QObject *obj = sender();
|
Chris@60
|
168 QString name = obj->objectName();
|
Chris@60
|
169
|
Chris@60
|
170 if (m_params.find(name) == m_params.end()) {
|
Chris@60
|
171 std::cerr << "WARNING: PluginParameterBox::dialChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
|
Chris@60
|
172 return;
|
Chris@60
|
173 }
|
Chris@60
|
174
|
Chris@71
|
175 Vamp::PluginBase::ParameterDescriptor params = m_params[name].param;
|
Chris@60
|
176
|
Chris@60
|
177 float min = params.minValue;
|
Chris@60
|
178 float max = params.maxValue;
|
Chris@60
|
179
|
Chris@60
|
180 float qtz = 0.0;
|
Chris@60
|
181 if (params.isQuantized) qtz = params.quantizeStep;
|
Chris@60
|
182
|
Chris@60
|
183 if (qtz == 0.0) {
|
Chris@60
|
184 qtz = (max - min) / 100.0;
|
Chris@60
|
185 }
|
Chris@60
|
186
|
Chris@60
|
187 float newValue = min + ival * qtz;
|
Chris@60
|
188
|
Chris@60
|
189 QDoubleSpinBox *spin = m_params[name].spin;
|
Chris@63
|
190 if (spin) {
|
Chris@63
|
191 spin->blockSignals(true);
|
Chris@63
|
192 spin->setValue(newValue);
|
Chris@63
|
193 spin->blockSignals(false);
|
Chris@63
|
194 }
|
Chris@60
|
195
|
Chris@60
|
196 m_plugin->setParameter(name.toStdString(), newValue);
|
Chris@64
|
197
|
Chris@71
|
198 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString());
|
Chris@60
|
199 }
|
Chris@60
|
200
|
Chris@60
|
201 void
|
Chris@63
|
202 PluginParameterBox::checkBoxChanged(int state)
|
Chris@63
|
203 {
|
Chris@63
|
204 QObject *obj = sender();
|
Chris@63
|
205 QString name = obj->objectName();
|
Chris@63
|
206
|
Chris@63
|
207 if (m_params.find(name) == m_params.end()) {
|
Chris@63
|
208 std::cerr << "WARNING: PluginParameterBox::checkBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
|
Chris@63
|
209 return;
|
Chris@63
|
210 }
|
Chris@63
|
211
|
Chris@71
|
212 Vamp::PluginBase::ParameterDescriptor params = m_params[name].param;
|
Chris@63
|
213
|
Chris@63
|
214 if (state) m_plugin->setParameter(name.toStdString(), 1.0);
|
Chris@63
|
215 else m_plugin->setParameter(name.toStdString(), 0.0);
|
Chris@64
|
216
|
Chris@71
|
217 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString());
|
Chris@63
|
218 }
|
Chris@63
|
219
|
Chris@63
|
220 void
|
Chris@60
|
221 PluginParameterBox::spinBoxChanged(double value)
|
Chris@60
|
222 {
|
Chris@60
|
223 QObject *obj = sender();
|
Chris@60
|
224 QString name = obj->objectName();
|
Chris@60
|
225
|
Chris@60
|
226 if (m_params.find(name) == m_params.end()) {
|
Chris@60
|
227 std::cerr << "WARNING: PluginParameterBox::spinBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
|
Chris@60
|
228 return;
|
Chris@60
|
229 }
|
Chris@60
|
230
|
Chris@71
|
231 Vamp::PluginBase::ParameterDescriptor params = m_params[name].param;
|
Chris@60
|
232
|
Chris@60
|
233 float min = params.minValue;
|
Chris@60
|
234 float max = params.maxValue;
|
Chris@60
|
235
|
Chris@60
|
236 float qtz = 0.0;
|
Chris@60
|
237 if (params.isQuantized) qtz = params.quantizeStep;
|
Chris@60
|
238
|
Chris@60
|
239 if (qtz > 0.0) {
|
Chris@60
|
240 int step = int((value - min) / qtz);
|
Chris@60
|
241 value = min + step * qtz;
|
Chris@60
|
242 }
|
Chris@60
|
243
|
Chris@60
|
244 int imin = 0, imax = 100;
|
Chris@60
|
245
|
Chris@60
|
246 if (qtz > 0.0) {
|
Chris@60
|
247 imax = int((max - min) / qtz);
|
Chris@60
|
248 } else {
|
Chris@60
|
249 qtz = (max - min) / 100.0;
|
Chris@60
|
250 }
|
Chris@60
|
251
|
Chris@60
|
252 int ival = (value - min) / qtz;
|
Chris@60
|
253
|
Chris@60
|
254 AudioDial *dial = m_params[name].dial;
|
Chris@63
|
255 if (dial) {
|
Chris@63
|
256 dial->blockSignals(true);
|
Chris@63
|
257 dial->setValue(ival);
|
Chris@63
|
258 dial->blockSignals(false);
|
Chris@63
|
259 }
|
Chris@60
|
260
|
Chris@60
|
261 m_plugin->setParameter(name.toStdString(), value);
|
Chris@64
|
262
|
Chris@71
|
263 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString());
|
Chris@60
|
264 }
|
Chris@60
|
265
|
Chris@63
|
266 void
|
Chris@63
|
267 PluginParameterBox::programComboChanged(const QString &newProgram)
|
Chris@63
|
268 {
|
Chris@63
|
269 m_plugin->selectProgram(newProgram.toStdString());
|
Chris@60
|
270
|
Chris@63
|
271 for (std::map<QString, ParamRec>::iterator i = m_params.begin();
|
Chris@63
|
272 i != m_params.end(); ++i) {
|
Chris@63
|
273
|
Chris@71
|
274 Vamp::PluginBase::ParameterDescriptor ¶m = i->second.param;
|
Chris@63
|
275 float value = m_plugin->getParameter(param.name);
|
Chris@63
|
276
|
Chris@63
|
277 if (i->second.spin) {
|
Chris@63
|
278 i->second.spin->blockSignals(true);
|
Chris@63
|
279 i->second.spin->setValue(value);
|
Chris@63
|
280 i->second.spin->blockSignals(false);
|
Chris@63
|
281 }
|
Chris@63
|
282
|
Chris@63
|
283 if (i->second.dial) {
|
Chris@63
|
284
|
Chris@63
|
285 float min = param.minValue;
|
Chris@63
|
286 float max = param.maxValue;
|
Chris@63
|
287
|
Chris@63
|
288 float qtz = 0.0;
|
Chris@63
|
289 if (param.isQuantized) qtz = param.quantizeStep;
|
Chris@63
|
290
|
Chris@63
|
291 if (qtz == 0.0) {
|
Chris@63
|
292 qtz = (max - min) / 100.0;
|
Chris@63
|
293 }
|
Chris@63
|
294
|
Chris@63
|
295 i->second.dial->blockSignals(true);
|
Chris@63
|
296 i->second.dial->setValue(int((value - min) / qtz));
|
Chris@63
|
297 i->second.dial->blockSignals(false);
|
Chris@63
|
298 }
|
Chris@63
|
299 }
|
Chris@64
|
300
|
Chris@71
|
301 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString());
|
Chris@63
|
302 }
|
Chris@63
|
303
|