comparison widgets/PluginParameterBox.cpp @ 63:fb02fe13ff47

* Add editing for auralisation plugin parameters and programs * Rename and reorganise the sample plugin sample set
author Chris Cannam
date Thu, 23 Mar 2006 15:49:41 +0000
parents 50429a56680f
children 10bcd53ddc71
comparison
equal deleted inserted replaced
62:50429a56680f 63:fb02fe13ff47
17 17
18 #include "AudioDial.h" 18 #include "AudioDial.h"
19 19
20 #include <QDoubleSpinBox> 20 #include <QDoubleSpinBox>
21 #include <QGridLayout> 21 #include <QGridLayout>
22 #include <QComboBox>
23 #include <QCheckBox>
22 #include <QLayout> 24 #include <QLayout>
23 #include <QLabel> 25 #include <QLabel>
24 26
25 #include <iostream> 27 #include <iostream>
26 #include <string> 28 #include <string>
40 42
41 void 43 void
42 PluginParameterBox::populate() 44 PluginParameterBox::populate()
43 { 45 {
44 PluginInstance::ParameterList params = m_plugin->getParameterDescriptors(); 46 PluginInstance::ParameterList params = m_plugin->getParameterDescriptors();
47 PluginInstance::ProgramList programs = m_plugin->getPrograms();
45 48
46 m_params.clear(); 49 m_params.clear();
47 50
48 if (params.empty()) { 51 if (params.empty() && programs.empty()) {
49 m_layout->addWidget 52 m_layout->addWidget
50 (new QLabel(tr("This plugin has no adjustable parameters.")), 53 (new QLabel(tr("This plugin has no adjustable parameters.")),
51 0, 0); 54 0, 0);
55 }
56
57 int offset = 0;
58
59 if (!programs.empty()) {
60
61 std::string currentProgram = m_plugin->getCurrentProgram();
62
63 QComboBox *programCombo = new QComboBox;
64 programCombo->setMaxVisibleItems(20);
65
66 for (int i = 0; i < programs.size(); ++i) {
67 programCombo->addItem(programs[i].c_str());
68 if (programs[i] == currentProgram) {
69 programCombo->setCurrentIndex(i);
70 }
71 }
72
73 m_layout->addWidget(new QLabel(tr("Program")), 0, 0);
74 m_layout->addWidget(programCombo, 0, 1, 1, 2);
75
76 connect(programCombo, SIGNAL(currentIndexChanged(const QString &)),
77 this, SLOT(programComboChanged(const QString &)));
78
79 offset = 1;
52 } 80 }
53 81
54 for (size_t i = 0; i < params.size(); ++i) { 82 for (size_t i = 0; i < params.size(); ++i) {
55 83
56 QString name = params[i].name.c_str(); 84 QString name = params[i].name.c_str();
77 105
78 //!!! would be nice to ensure the default value corresponds to 106 //!!! would be nice to ensure the default value corresponds to
79 // an integer! 107 // an integer!
80 108
81 QLabel *label = new QLabel(description); 109 QLabel *label = new QLabel(description);
82 m_layout->addWidget(label, i, 0); 110 m_layout->addWidget(label, i + offset, 0);
111
112 ParamRec rec;
113 rec.param = params[i];
114 rec.dial = 0;
115 rec.spin = 0;
116 rec.check = 0;
83 117
84 AudioDial *dial = new AudioDial; 118 if (min == 0.0 && max == 1.0 && qtz == 1.0) {
85 dial->setObjectName(name); 119
86 dial->setMinimum(imin); 120 QCheckBox *checkbox = new QCheckBox;
87 dial->setMaximum(imax); 121 checkbox->setObjectName(name);
88 dial->setPageStep(1); 122 checkbox->setCheckState(value == 0.0 ? Qt::Unchecked : Qt::Checked);
89 dial->setNotchesVisible((imax - imin) <= 12); 123 connect(checkbox, SIGNAL(stateChanged(int)),
90 dial->setDefaultValue(int((deft - min) / qtz)); 124 this, SLOT(checkBoxChanged(int)));
91 dial->setValue(int((value - min) / qtz)); 125 m_layout->addWidget(checkbox, i + offset, 2);
92 dial->setFixedWidth(32); 126 rec.check = checkbox;
93 dial->setFixedHeight(32); 127
94 connect(dial, SIGNAL(valueChanged(int)), 128 } else {
95 this, SLOT(dialChanged(int))); 129
96 m_layout->addWidget(dial, i, 1); 130 AudioDial *dial = new AudioDial;
97 131 dial->setObjectName(name);
98 QDoubleSpinBox *spinbox = new QDoubleSpinBox; 132 dial->setMinimum(imin);
99 spinbox->setObjectName(name); 133 dial->setMaximum(imax);
100 spinbox->setMinimum(min); 134 dial->setPageStep(1);
101 spinbox->setMaximum(max); 135 dial->setNotchesVisible((imax - imin) <= 12);
102 spinbox->setSuffix(QString(" %1").arg(unit)); 136 dial->setDefaultValue(int((deft - min) / qtz));
103 spinbox->setSingleStep(qtz); 137 dial->setValue(int((value - min) / qtz));
104 spinbox->setValue(value); 138 dial->setFixedWidth(32);
105 connect(spinbox, SIGNAL(valueChanged(double)), 139 dial->setFixedHeight(32);
106 this, SLOT(spinBoxChanged(double))); 140 connect(dial, SIGNAL(valueChanged(int)),
107 m_layout->addWidget(spinbox, i, 2); 141 this, SLOT(dialChanged(int)));
108 142 m_layout->addWidget(dial, i + offset, 1);
109 ParamRec rec; 143
110 rec.dial = dial; 144 QDoubleSpinBox *spinbox = new QDoubleSpinBox;
111 rec.spin = spinbox; 145 spinbox->setObjectName(name);
112 rec.param = params[i]; 146 spinbox->setMinimum(min);
147 spinbox->setMaximum(max);
148 spinbox->setSuffix(QString(" %1").arg(unit));
149 spinbox->setSingleStep(qtz);
150 spinbox->setValue(value);
151 connect(spinbox, SIGNAL(valueChanged(double)),
152 this, SLOT(spinBoxChanged(double)));
153 m_layout->addWidget(spinbox, i + offset, 2);
154 rec.dial = dial;
155 rec.spin = spinbox;
156 }
157
113 m_params[name] = rec; 158 m_params[name] = rec;
114 } 159 }
115 } 160 }
116 161
117 void 162 void
138 } 183 }
139 184
140 float newValue = min + ival * qtz; 185 float newValue = min + ival * qtz;
141 186
142 QDoubleSpinBox *spin = m_params[name].spin; 187 QDoubleSpinBox *spin = m_params[name].spin;
143 spin->blockSignals(true); 188 if (spin) {
144 spin->setValue(newValue); 189 spin->blockSignals(true);
145 spin->blockSignals(false); 190 spin->setValue(newValue);
191 spin->blockSignals(false);
192 }
146 193
147 m_plugin->setParameter(name.toStdString(), newValue); 194 m_plugin->setParameter(name.toStdString(), newValue);
195 }
196
197 void
198 PluginParameterBox::checkBoxChanged(int state)
199 {
200 QObject *obj = sender();
201 QString name = obj->objectName();
202
203 if (m_params.find(name) == m_params.end()) {
204 std::cerr << "WARNING: PluginParameterBox::checkBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
205 return;
206 }
207
208 PluginInstance::ParameterDescriptor params = m_params[name].param;
209
210 if (state) m_plugin->setParameter(name.toStdString(), 1.0);
211 else m_plugin->setParameter(name.toStdString(), 0.0);
148 } 212 }
149 213
150 void 214 void
151 PluginParameterBox::spinBoxChanged(double value) 215 PluginParameterBox::spinBoxChanged(double value)
152 { 216 {
180 } 244 }
181 245
182 int ival = (value - min) / qtz; 246 int ival = (value - min) / qtz;
183 247
184 AudioDial *dial = m_params[name].dial; 248 AudioDial *dial = m_params[name].dial;
185 dial->blockSignals(true); 249 if (dial) {
186 dial->setValue(ival); 250 dial->blockSignals(true);
187 dial->blockSignals(false); 251 dial->setValue(ival);
252 dial->blockSignals(false);
253 }
188 254
189 m_plugin->setParameter(name.toStdString(), value); 255 m_plugin->setParameter(name.toStdString(), value);
190 } 256 }
191 257
192 258 void
259 PluginParameterBox::programComboChanged(const QString &newProgram)
260 {
261 m_plugin->selectProgram(newProgram.toStdString());
262
263 for (std::map<QString, ParamRec>::iterator i = m_params.begin();
264 i != m_params.end(); ++i) {
265
266 PluginInstance::ParameterDescriptor &param = i->second.param;
267 float value = m_plugin->getParameter(param.name);
268
269 if (i->second.spin) {
270 i->second.spin->blockSignals(true);
271 i->second.spin->setValue(value);
272 i->second.spin->blockSignals(false);
273 }
274
275 if (i->second.dial) {
276
277 float min = param.minValue;
278 float max = param.maxValue;
279
280 float qtz = 0.0;
281 if (param.isQuantized) qtz = param.quantizeStep;
282
283 if (qtz == 0.0) {
284 qtz = (max - min) / 100.0;
285 }
286
287 i->second.dial->blockSignals(true);
288 i->second.dial->setValue(int((value - min) / qtz));
289 i->second.dial->blockSignals(false);
290 }
291 }
292 }
293