Mercurial > hg > svgui
comparison widgets/PluginParameterBox.cpp @ 207:a5b3c9f580c1
* Fixes for new Vamp API changes -- I think plugin parameters are not being
set correctly yet though
author | Chris Cannam |
---|---|
date | Mon, 26 Feb 2007 20:08:51 +0000 |
parents | 42118892f428 |
children | 8495187c13ce |
comparison
equal
deleted
inserted
replaced
206:305c129a2c4f | 207:a5b3c9f580c1 |
---|---|
85 offset = 1; | 85 offset = 1; |
86 } | 86 } |
87 | 87 |
88 for (size_t i = 0; i < params.size(); ++i) { | 88 for (size_t i = 0; i < params.size(); ++i) { |
89 | 89 |
90 QString identifier = params[i].identifier.c_str(); | |
90 QString name = params[i].name.c_str(); | 91 QString name = params[i].name.c_str(); |
91 QString description = params[i].description.c_str(); | |
92 QString unit = params[i].unit.c_str(); | 92 QString unit = params[i].unit.c_str(); |
93 | 93 |
94 float min = params[i].minValue; | 94 float min = params[i].minValue; |
95 float max = params[i].maxValue; | 95 float max = params[i].maxValue; |
96 float deft = params[i].defaultValue; | 96 float deft = params[i].defaultValue; |
97 float value = m_plugin->getParameter(params[i].name); | 97 float value = m_plugin->getParameter(params[i].identifier); |
98 | 98 |
99 float qtz = 0.0; | 99 float qtz = 0.0; |
100 if (params[i].isQuantized) qtz = params[i].quantizeStep; | 100 if (params[i].isQuantized) qtz = params[i].quantizeStep; |
101 | 101 |
102 std::vector<std::string> valueNames = params[i].valueNames; | 102 std::vector<std::string> valueNames = params[i].valueNames; |
112 } | 112 } |
113 | 113 |
114 //!!! would be nice to ensure the default value corresponds to | 114 //!!! would be nice to ensure the default value corresponds to |
115 // an integer! | 115 // an integer! |
116 | 116 |
117 QLabel *label = new QLabel(description); | 117 QLabel *label = new QLabel(name); |
118 m_layout->addWidget(label, i + offset, 0); | 118 m_layout->addWidget(label, i + offset, 0); |
119 | 119 |
120 ParamRec rec; | 120 ParamRec rec; |
121 rec.param = params[i]; | 121 rec.param = params[i]; |
122 rec.dial = 0; | 122 rec.dial = 0; |
125 rec.combo = 0; | 125 rec.combo = 0; |
126 | 126 |
127 if (params[i].isQuantized && !valueNames.empty()) { | 127 if (params[i].isQuantized && !valueNames.empty()) { |
128 | 128 |
129 QComboBox *combobox = new QComboBox; | 129 QComboBox *combobox = new QComboBox; |
130 combobox->setObjectName(name); | 130 combobox->setObjectName(identifier); |
131 for (unsigned int j = 0; j < valueNames.size(); ++j) { | 131 for (unsigned int j = 0; j < valueNames.size(); ++j) { |
132 combobox->addItem(valueNames[j].c_str()); | 132 combobox->addItem(valueNames[j].c_str()); |
133 if (lrintf((value - min) / qtz) == j) { | 133 if (lrintf((value - min) / qtz) == j) { |
134 combobox->setCurrentIndex(j); | 134 combobox->setCurrentIndex(j); |
135 } | 135 } |
140 rec.combo = combobox; | 140 rec.combo = combobox; |
141 | 141 |
142 } else if (min == 0.0 && max == 1.0 && qtz == 1.0) { | 142 } else if (min == 0.0 && max == 1.0 && qtz == 1.0) { |
143 | 143 |
144 QCheckBox *checkbox = new QCheckBox; | 144 QCheckBox *checkbox = new QCheckBox; |
145 checkbox->setObjectName(name); | 145 checkbox->setObjectName(identifier); |
146 checkbox->setCheckState(value == 0.0 ? Qt::Unchecked : Qt::Checked); | 146 checkbox->setCheckState(value == 0.0 ? Qt::Unchecked : Qt::Checked); |
147 connect(checkbox, SIGNAL(stateChanged(int)), | 147 connect(checkbox, SIGNAL(stateChanged(int)), |
148 this, SLOT(checkBoxChanged(int))); | 148 this, SLOT(checkBoxChanged(int))); |
149 m_layout->addWidget(checkbox, i + offset, 2); | 149 m_layout->addWidget(checkbox, i + offset, 2); |
150 rec.check = checkbox; | 150 rec.check = checkbox; |
151 | 151 |
152 } else { | 152 } else { |
153 | 153 |
154 AudioDial *dial = new AudioDial; | 154 AudioDial *dial = new AudioDial; |
155 dial->setObjectName(description); | 155 dial->setObjectName(name); |
156 dial->setMinimum(imin); | 156 dial->setMinimum(imin); |
157 dial->setMaximum(imax); | 157 dial->setMaximum(imax); |
158 dial->setPageStep(1); | 158 dial->setPageStep(1); |
159 dial->setNotchesVisible((imax - imin) <= 12); | 159 dial->setNotchesVisible((imax - imin) <= 12); |
160 dial->setDefaultValue(lrintf((deft - min) / qtz)); | 160 dial->setDefaultValue(lrintf((deft - min) / qtz)); |
167 connect(dial, SIGNAL(valueChanged(int)), | 167 connect(dial, SIGNAL(valueChanged(int)), |
168 this, SLOT(dialChanged(int))); | 168 this, SLOT(dialChanged(int))); |
169 m_layout->addWidget(dial, i + offset, 1); | 169 m_layout->addWidget(dial, i + offset, 1); |
170 | 170 |
171 QDoubleSpinBox *spinbox = new QDoubleSpinBox; | 171 QDoubleSpinBox *spinbox = new QDoubleSpinBox; |
172 spinbox->setObjectName(name); | 172 spinbox->setObjectName(identifier); |
173 spinbox->setMinimum(min); | 173 spinbox->setMinimum(min); |
174 spinbox->setMaximum(max); | 174 spinbox->setMaximum(max); |
175 spinbox->setSuffix(QString(" %1").arg(unit)); | 175 spinbox->setSuffix(QString(" %1").arg(unit)); |
176 spinbox->setSingleStep(qtz); | 176 spinbox->setSingleStep(qtz); |
177 spinbox->setValue(value); | 177 spinbox->setValue(value); |
181 m_layout->addWidget(spinbox, i + offset, 2); | 181 m_layout->addWidget(spinbox, i + offset, 2); |
182 rec.dial = dial; | 182 rec.dial = dial; |
183 rec.spin = spinbox; | 183 rec.spin = spinbox; |
184 } | 184 } |
185 | 185 |
186 m_params[name] = rec; | 186 m_params[identifier] = rec; |
187 m_descriptionMap[description] = name; | 187 m_nameMap[name] = identifier; |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void | 191 void |
192 PluginParameterBox::dialChanged(int ival) | 192 PluginParameterBox::dialChanged(int ival) |
193 { | 193 { |
194 QObject *obj = sender(); | 194 QObject *obj = sender(); |
195 QString name = obj->objectName(); | 195 QString identifier = obj->objectName(); |
196 | 196 |
197 if (m_params.find(name) == m_params.end() && | 197 if (m_params.find(identifier) == m_params.end() && |
198 m_descriptionMap.find(name) != m_descriptionMap.end()) { | 198 m_nameMap.find(identifier) != m_nameMap.end()) { |
199 name = m_descriptionMap[name]; | 199 identifier = m_nameMap[identifier]; |
200 } | 200 } |
201 | 201 |
202 if (m_params.find(name) == m_params.end()) { | 202 if (m_params.find(identifier) == m_params.end()) { |
203 std::cerr << "WARNING: PluginParameterBox::dialChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl; | 203 std::cerr << "WARNING: PluginParameterBox::dialChanged: Unknown parameter \"" << identifier.toStdString() << "\"" << std::endl; |
204 return; | 204 return; |
205 } | 205 } |
206 | 206 |
207 Vamp::PluginBase::ParameterDescriptor params = m_params[name].param; | 207 Vamp::PluginBase::ParameterDescriptor params = m_params[identifier].param; |
208 | 208 |
209 float min = params.minValue; | 209 float min = params.minValue; |
210 float max = params.maxValue; | 210 float max = params.maxValue; |
211 | 211 |
212 float newValue; | 212 float newValue; |
231 qtz = (max - min) / 100.0; | 231 qtz = (max - min) / 100.0; |
232 } | 232 } |
233 newValue = min + ival * qtz; | 233 newValue = min + ival * qtz; |
234 } | 234 } |
235 | 235 |
236 QDoubleSpinBox *spin = m_params[name].spin; | 236 QDoubleSpinBox *spin = m_params[identifier].spin; |
237 if (spin) { | 237 if (spin) { |
238 spin->blockSignals(true); | 238 spin->blockSignals(true); |
239 spin->setValue(newValue); | 239 spin->setValue(newValue); |
240 spin->blockSignals(false); | 240 spin->blockSignals(false); |
241 } | 241 } |
242 | 242 |
243 m_plugin->setParameter(name.toStdString(), newValue); | 243 m_plugin->setParameter(identifier.toStdString(), newValue); |
244 | 244 |
245 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString()); | 245 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString()); |
246 } | 246 } |
247 | 247 |
248 void | 248 void |
249 PluginParameterBox::checkBoxChanged(int state) | 249 PluginParameterBox::checkBoxChanged(int state) |
250 { | 250 { |
251 QObject *obj = sender(); | 251 QObject *obj = sender(); |
252 QString name = obj->objectName(); | 252 QString identifier = obj->objectName(); |
253 | 253 |
254 if (m_params.find(name) == m_params.end() && | 254 if (m_params.find(identifier) == m_params.end() && |
255 m_descriptionMap.find(name) != m_descriptionMap.end()) { | 255 m_nameMap.find(identifier) != m_nameMap.end()) { |
256 name = m_descriptionMap[name]; | 256 identifier = m_nameMap[identifier]; |
257 } | 257 } |
258 | 258 |
259 if (m_params.find(name) == m_params.end()) { | 259 if (m_params.find(identifier) == m_params.end()) { |
260 std::cerr << "WARNING: PluginParameterBox::checkBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl; | 260 std::cerr << "WARNING: PluginParameterBox::checkBoxChanged: Unknown parameter \"" << identifier.toStdString() << "\"" << std::endl; |
261 return; | 261 return; |
262 } | 262 } |
263 | 263 |
264 Vamp::PluginBase::ParameterDescriptor params = m_params[name].param; | 264 Vamp::PluginBase::ParameterDescriptor params = m_params[identifier].param; |
265 | 265 |
266 if (state) m_plugin->setParameter(name.toStdString(), 1.0); | 266 if (state) m_plugin->setParameter(identifier.toStdString(), 1.0); |
267 else m_plugin->setParameter(name.toStdString(), 0.0); | 267 else m_plugin->setParameter(identifier.toStdString(), 0.0); |
268 | 268 |
269 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString()); | 269 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString()); |
270 } | 270 } |
271 | 271 |
272 void | 272 void |
273 PluginParameterBox::spinBoxChanged(double value) | 273 PluginParameterBox::spinBoxChanged(double value) |
274 { | 274 { |
275 QObject *obj = sender(); | 275 QObject *obj = sender(); |
276 QString name = obj->objectName(); | 276 QString identifier = obj->objectName(); |
277 | 277 |
278 if (m_params.find(name) == m_params.end() && | 278 if (m_params.find(identifier) == m_params.end() && |
279 m_descriptionMap.find(name) != m_descriptionMap.end()) { | 279 m_nameMap.find(identifier) != m_nameMap.end()) { |
280 name = m_descriptionMap[name]; | 280 identifier = m_nameMap[identifier]; |
281 } | 281 } |
282 | 282 |
283 if (m_params.find(name) == m_params.end()) { | 283 if (m_params.find(identifier) == m_params.end()) { |
284 std::cerr << "WARNING: PluginParameterBox::spinBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl; | 284 std::cerr << "WARNING: PluginParameterBox::spinBoxChanged: Unknown parameter \"" << identifier.toStdString() << "\"" << std::endl; |
285 return; | 285 return; |
286 } | 286 } |
287 | 287 |
288 Vamp::PluginBase::ParameterDescriptor params = m_params[name].param; | 288 Vamp::PluginBase::ParameterDescriptor params = m_params[identifier].param; |
289 | 289 |
290 float min = params.minValue; | 290 float min = params.minValue; |
291 float max = params.maxValue; | 291 float max = params.maxValue; |
292 | 292 |
293 float qtz = 0.0; | 293 float qtz = 0.0; |
306 qtz = (max - min) / 100.0; | 306 qtz = (max - min) / 100.0; |
307 } | 307 } |
308 | 308 |
309 int ival = (value - min) / qtz; | 309 int ival = (value - min) / qtz; |
310 | 310 |
311 AudioDial *dial = m_params[name].dial; | 311 AudioDial *dial = m_params[identifier].dial; |
312 if (dial) { | 312 if (dial) { |
313 dial->blockSignals(true); | 313 dial->blockSignals(true); |
314 dial->setValue(ival); | 314 dial->setValue(ival); |
315 dial->blockSignals(false); | 315 dial->blockSignals(false); |
316 } | 316 } |
317 | 317 |
318 m_plugin->setParameter(name.toStdString(), value); | 318 m_plugin->setParameter(identifier.toStdString(), value); |
319 | 319 |
320 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString()); | 320 emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString()); |
321 } | 321 } |
322 | 322 |
323 void | 323 void |
327 | 327 |
328 for (std::map<QString, ParamRec>::iterator i = m_params.begin(); | 328 for (std::map<QString, ParamRec>::iterator i = m_params.begin(); |
329 i != m_params.end(); ++i) { | 329 i != m_params.end(); ++i) { |
330 | 330 |
331 Vamp::PluginBase::ParameterDescriptor ¶m = i->second.param; | 331 Vamp::PluginBase::ParameterDescriptor ¶m = i->second.param; |
332 float value = m_plugin->getParameter(param.name); | 332 float value = m_plugin->getParameter(param.identifier); |
333 | 333 |
334 if (i->second.spin) { | 334 if (i->second.spin) { |
335 i->second.spin->blockSignals(true); | 335 i->second.spin->blockSignals(true); |
336 i->second.spin->setValue(value); | 336 i->second.spin->setValue(value); |
337 i->second.spin->blockSignals(false); | 337 i->second.spin->blockSignals(false); |