comparison plugin/LADSPAPluginFactory.cpp @ 356:ca3b91119482

* fix support for logarithmic hints in plugin parameters
author Chris Cannam
date Mon, 17 Dec 2007 12:32:28 +0000
parents d4a33cdca86f
children b92513201610
comparison
equal deleted inserted replaced
355:d02f71281639 356:ca3b91119482
149 149
150 float minimum = 0.0; 150 float minimum = 0.0;
151 151
152 if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) { 152 if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
153 float lb = descriptor->PortRangeHints[port].LowerBound; 153 float lb = descriptor->PortRangeHints[port].LowerBound;
154 std::cerr << "LADSPAPluginFactory::getPortMinimum: bounded below at " << lb << std::endl;
154 minimum = lb; 155 minimum = lb;
155 } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { 156 } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
156 float ub = descriptor->PortRangeHints[port].UpperBound; 157 float ub = descriptor->PortRangeHints[port].UpperBound;
157 minimum = std::min(0.0, ub - 1.0); 158 minimum = std::min(0.0, ub - 1.0);
158 } 159 }
159 160
160 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) { 161 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
161 minimum *= m_sampleRate; 162 minimum *= m_sampleRate;
163 }
164
165 if (LADSPA_IS_HINT_LOGARITHMIC(d)) {
166 if (minimum == 0.f) minimum = 1.f;
162 } 167 }
163 168
164 return minimum; 169 return minimum;
165 } 170 }
166 171
209 LADSPA_PortRangeHintDescriptor d = 214 LADSPA_PortRangeHintDescriptor d =
210 descriptor->PortRangeHints[port].HintDescriptor; 215 descriptor->PortRangeHints[port].HintDescriptor;
211 216
212 bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d); 217 bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d);
213 218
219 float logmin = 0, logmax = 0;
220 if (logarithmic) {
221 float thresh = powf(10, -10);
222 if (minimum < thresh) logmin = -10;
223 else logmin = log10f(minimum);
224 if (maximum < thresh) logmax = -10;
225 else logmax = log10f(maximum);
226 }
227
228 std::cerr << "LADSPAPluginFactory::getPortDefault: hint = " << d << std::endl;
229
214 if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) { 230 if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) {
215 231
216 deft = minimum; 232 deft = minimum;
217 233
218 } else if (LADSPA_IS_HINT_DEFAULT_MINIMUM(d)) { 234 } else if (LADSPA_IS_HINT_DEFAULT_MINIMUM(d)) {
220 deft = minimum; 236 deft = minimum;
221 237
222 } else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) { 238 } else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) {
223 239
224 if (logarithmic) { 240 if (logarithmic) {
225 deft = powf(10, log10(minimum) * 0.75 + 241 deft = powf(10, logmin * 0.75 + logmax * 0.25);
226 log10(maximum) * 0.25);
227 } else { 242 } else {
228 deft = minimum * 0.75 + maximum * 0.25; 243 deft = minimum * 0.75 + maximum * 0.25;
229 } 244 }
230 245
231 } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) { 246 } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) {
232 247
233 if (logarithmic) { 248 if (logarithmic) {
234 deft = powf(10, log10(minimum) * 0.5 + 249 deft = powf(10, logmin * 0.5 + logmax * 0.5);
235 log10(maximum) * 0.5);
236 } else { 250 } else {
237 deft = minimum * 0.5 + maximum * 0.5; 251 deft = minimum * 0.5 + maximum * 0.5;
238 } 252 }
239 253
240 } else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) { 254 } else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) {
241 255
242 if (logarithmic) { 256 if (logarithmic) {
243 deft = powf(10, log10(minimum) * 0.25 + 257 deft = powf(10, logmin * 0.25 + logmax * 0.75);
244 log10(maximum) * 0.75);
245 } else { 258 } else {
246 deft = minimum * 0.25 + maximum * 0.75; 259 deft = minimum * 0.25 + maximum * 0.75;
247 } 260 }
248 261
249 } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) { 262 } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) {
269 282
270 } else { 283 } else {
271 284
272 deft = minimum; 285 deft = minimum;
273 } 286 }
274 287
275 if (LADSPA_IS_HINT_SAMPLE_RATE(d)) { 288 //!!! No -- the min and max have already been multiplied by the rate,
276 deft *= m_sampleRate; 289 //so it would happen twice if we did it here -- and e.g. DEFAULT_440
277 } 290 //doesn't want to be multiplied by the rate either
291
292 // if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
293 // deft *= m_sampleRate;
294 // }
278 295
279 return deft; 296 return deft;
280 } 297 }
281 298
282 float 299 float