comparison widgets/PluginParameterBox.cpp @ 1348:01778052e663

Avoid blowing up when faced with min==max in parameter range
author Chris Cannam
date Mon, 01 Oct 2018 14:46:36 +0100
parents 4a578a360011
children c8a6fd3f9dff
comparison
equal deleted inserted replaced
1347:edfc38ade098 1348:01778052e663
119 int imin = 0, imax = 100; 119 int imin = 0, imax = 100;
120 120
121 if (!(hint & PortHint::Logarithmic)) { 121 if (!(hint & PortHint::Logarithmic)) {
122 if (qtz > 0.0) { 122 if (qtz > 0.0) {
123 imax = int(lrintf((max - min) / qtz)); 123 imax = int(lrintf((max - min) / qtz));
124 if (imax <= imin) {
125 imax = 100;
126 qtz = (max - min) / 100.f;
127 }
124 } else { 128 } else {
125 qtz = (max - min) / 100.f; 129 qtz = (max - min) / 100.f;
126 } 130 }
127 } 131 }
128 132
179 dial->setNotchesVisible((imax - imin) <= 12); 183 dial->setNotchesVisible((imax - imin) <= 12);
180 //!!! dial->setDefaultValue(lrintf((deft - min) / qtz)); 184 //!!! dial->setDefaultValue(lrintf((deft - min) / qtz));
181 // dial->setValue(lrintf((value - min) / qtz)); 185 // dial->setValue(lrintf((value - min) / qtz));
182 dial->setFixedWidth(32); 186 dial->setFixedWidth(32);
183 dial->setFixedHeight(32); 187 dial->setFixedHeight(32);
184 RangeMapper *rm = 0; 188 if (max == min || imax == imin) {
185 if (hint & PortHint::Logarithmic) { 189 SVCERR << "WARNING: for parameter \"" << name
186 rm = new LogRangeMapper(imin, imax, min, max, unit); 190 << "\" of plugin \"" << m_plugin->getName()
191 << "\": invalid range " << min << " -> " << max
192 << " with quantize step " << qtz << endl;
187 } else { 193 } else {
188 rm = new LinearRangeMapper(imin, imax, min, max, unit); 194 RangeMapper *rm = 0;
195 if (hint & PortHint::Logarithmic) {
196 rm = new LogRangeMapper(imin, imax, min, max, unit);
197 } else {
198 rm = new LinearRangeMapper(imin, imax, min, max, unit);
199 }
200 dial->setRangeMapper(rm);
201 dial->setDefaultValue(rm->getPositionForValue(deft));
202 dial->setValue(rm->getPositionForValue(value));
189 } 203 }
190 dial->setRangeMapper(rm);
191 dial->setDefaultValue(rm->getPositionForValue(deft));
192 dial->setValue(rm->getPositionForValue(value));
193 dial->setShowToolTip(true); 204 dial->setShowToolTip(true);
194 connect(dial, SIGNAL(valueChanged(int)), 205 connect(dial, SIGNAL(valueChanged(int)),
195 this, SLOT(dialChanged(int))); 206 this, SLOT(dialChanged(int)));
196 m_layout->addWidget(dial, i + offset, 1); 207 m_layout->addWidget(dial, i + offset, 1);
197 208