Mercurial > hg > svgui
comparison widgets/PluginParameterBox.cpp @ 373:0895517bb2d1 1.2-stable
* merge from trunk (1.2 ended up being tracked from trunk, but we may want
this branch for fixes later)
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 10:32:45 +0000 |
parents | 15b8a4bfe855 |
children | 4cb5cd9ccac7 |
comparison
equal
deleted
inserted
replaced
337:813170c57b13 | 373:0895517bb2d1 |
---|---|
16 #include "PluginParameterBox.h" | 16 #include "PluginParameterBox.h" |
17 | 17 |
18 #include "AudioDial.h" | 18 #include "AudioDial.h" |
19 | 19 |
20 #include "plugin/PluginXml.h" | 20 #include "plugin/PluginXml.h" |
21 #include "plugin/RealTimePluginInstance.h" // for PortHint stuff | |
21 | 22 |
22 #include "base/RangeMapper.h" | 23 #include "base/RangeMapper.h" |
23 | 24 |
24 #include <QDoubleSpinBox> | 25 #include <QDoubleSpinBox> |
25 #include <QGridLayout> | 26 #include <QGridLayout> |
96 float min = params[i].minValue; | 97 float min = params[i].minValue; |
97 float max = params[i].maxValue; | 98 float max = params[i].maxValue; |
98 float deft = params[i].defaultValue; | 99 float deft = params[i].defaultValue; |
99 float value = m_plugin->getParameter(params[i].identifier); | 100 float value = m_plugin->getParameter(params[i].identifier); |
100 | 101 |
102 int hint = PortHint::NoHint; | |
103 RealTimePluginInstance *rtpi = dynamic_cast<RealTimePluginInstance *> | |
104 (m_plugin); | |
105 if (rtpi) { | |
106 hint = rtpi->getParameterDisplayHint(i); | |
107 } | |
108 | |
101 float qtz = 0.0; | 109 float qtz = 0.0; |
102 if (params[i].isQuantized) qtz = params[i].quantizeStep; | 110 if (params[i].isQuantized) qtz = params[i].quantizeStep; |
103 | 111 |
112 std::cerr << "PluginParameterBox: hint = " << hint << ", min = " << min << ", max = " | |
113 << max << ", qtz = " << qtz << std::endl; | |
114 | |
104 std::vector<std::string> valueNames = params[i].valueNames; | 115 std::vector<std::string> valueNames = params[i].valueNames; |
105 | 116 |
106 // construct an integer range | 117 // construct an integer range |
107 | 118 |
108 int imin = 0, imax = 100; | 119 int imin = 0, imax = 100; |
109 | 120 |
110 if (qtz > 0.0) { | 121 if (!(hint & PortHint::Logarithmic)) { |
111 imax = int((max - min) / qtz); | 122 if (qtz > 0.0) { |
112 } else { | 123 imax = int((max - min) / qtz); |
113 qtz = (max - min) / 100.0; | 124 } else { |
125 qtz = (max - min) / 100.0; | |
126 } | |
114 } | 127 } |
115 | 128 |
116 //!!! would be nice to ensure the default value corresponds to | 129 //!!! would be nice to ensure the default value corresponds to |
117 // an integer! | 130 // an integer! |
118 | 131 |
160 dial->setObjectName(name); | 173 dial->setObjectName(name); |
161 dial->setMinimum(imin); | 174 dial->setMinimum(imin); |
162 dial->setMaximum(imax); | 175 dial->setMaximum(imax); |
163 dial->setPageStep(1); | 176 dial->setPageStep(1); |
164 dial->setNotchesVisible((imax - imin) <= 12); | 177 dial->setNotchesVisible((imax - imin) <= 12); |
165 dial->setDefaultValue(lrintf((deft - min) / qtz)); | 178 //!!! dial->setDefaultValue(lrintf((deft - min) / qtz)); |
166 dial->setValue(lrintf((value - min) / qtz)); | 179 // dial->setValue(lrintf((value - min) / qtz)); |
167 dial->setFixedWidth(32); | 180 dial->setFixedWidth(32); |
168 dial->setFixedHeight(32); | 181 dial->setFixedHeight(32); |
169 dial->setRangeMapper(new LinearRangeMapper | 182 RangeMapper *rm = 0; |
170 (imin, imax, min, max, unit)); | 183 if (hint & PortHint::Logarithmic) { |
184 rm = new LogRangeMapper(imin, imax, min, max, unit); | |
185 } else { | |
186 rm = new LinearRangeMapper(imin, imax, min, max, unit); | |
187 } | |
188 dial->setRangeMapper(rm); | |
189 dial->setDefaultValue(rm->getPositionForValue(deft)); | |
190 dial->setValue(rm->getPositionForValue(value)); | |
171 dial->setShowToolTip(true); | 191 dial->setShowToolTip(true); |
172 connect(dial, SIGNAL(valueChanged(int)), | 192 connect(dial, SIGNAL(valueChanged(int)), |
173 this, SLOT(dialChanged(int))); | 193 this, SLOT(dialChanged(int))); |
174 m_layout->addWidget(dial, i + offset, 1); | 194 m_layout->addWidget(dial, i + offset, 1); |
175 | 195 |
176 QDoubleSpinBox *spinbox = new QDoubleSpinBox; | 196 QDoubleSpinBox *spinbox = new QDoubleSpinBox; |
177 spinbox->setObjectName(identifier); | 197 spinbox->setObjectName(identifier); |
178 spinbox->setMinimum(min); | 198 spinbox->setMinimum(min); |
179 spinbox->setMaximum(max); | 199 spinbox->setMaximum(max); |
180 spinbox->setSuffix(QString(" %1").arg(unit)); | 200 spinbox->setSuffix(QString(" %1").arg(unit)); |
181 spinbox->setSingleStep(qtz); | 201 if (qtz != 0) spinbox->setSingleStep(qtz); |
182 spinbox->setValue(value); | 202 spinbox->setValue(value); |
183 spinbox->setDecimals(4); | 203 spinbox->setDecimals(4); |
184 connect(spinbox, SIGNAL(valueChanged(double)), | 204 connect(spinbox, SIGNAL(valueChanged(double)), |
185 this, SLOT(spinBoxChanged(double))); | 205 this, SLOT(spinBoxChanged(double))); |
186 m_layout->addWidget(spinbox, i + offset, 2); | 206 m_layout->addWidget(spinbox, i + offset, 2); |
236 qtz = (max - min) / 100.0; | 256 qtz = (max - min) / 100.0; |
237 } | 257 } |
238 newValue = min + ival * qtz; | 258 newValue = min + ival * qtz; |
239 } | 259 } |
240 | 260 |
261 std::cerr << "PluginParameterBox::dialChanged: newValue = " << newValue << std::endl; | |
262 | |
241 QDoubleSpinBox *spin = m_params[identifier].spin; | 263 QDoubleSpinBox *spin = m_params[identifier].spin; |
242 if (spin) { | 264 if (spin) { |
243 spin->blockSignals(true); | 265 spin->blockSignals(true); |
244 spin->setValue(newValue); | 266 spin->setValue(newValue); |
245 spin->blockSignals(false); | 267 spin->blockSignals(false); |
318 int ival = lrintf((value - min) / qtz); | 340 int ival = lrintf((value - min) / qtz); |
319 | 341 |
320 AudioDial *dial = m_params[identifier].dial; | 342 AudioDial *dial = m_params[identifier].dial; |
321 if (dial) { | 343 if (dial) { |
322 dial->blockSignals(true); | 344 dial->blockSignals(true); |
323 dial->setValue(ival); | 345 if (dial->rangeMapper()) { |
346 dial->setMappedValue(value); | |
347 } else { | |
348 dial->setValue(ival); | |
349 } | |
324 dial->blockSignals(false); | 350 dial->blockSignals(false); |
325 } | 351 } |
326 | 352 |
327 m_plugin->setParameter(identifier.toStdString(), value); | 353 m_plugin->setParameter(identifier.toStdString(), value); |
328 | 354 |