Fix thinning (normalize parameter value)
This fixes thinning of MIDI data (range 0..127) and other parameters with range other than 0..1.
This commit is contained in:
parent
bd3f713d0e
commit
a5f36bbbbf
@ -381,6 +381,14 @@ ControlList::thin (double thinning_factor)
|
||||
return;
|
||||
}
|
||||
|
||||
/* compat. In the past the actual (internal) value was used
|
||||
* to compute the area. For gain the range is 0..2 (exp).
|
||||
* Since we cannot change automation-thinning-factor
|
||||
* in user's existing config, we simply re-normalize
|
||||
* the thinning factor.
|
||||
*/
|
||||
thinning_factor *= .7071;
|
||||
|
||||
assert (is_sorted ());
|
||||
|
||||
bool changed = false;
|
||||
@ -407,9 +415,13 @@ ControlList::thin (double thinning_factor)
|
||||
const double pw = prev->when.samples ();
|
||||
const double cw = cur->when.samples ();
|
||||
|
||||
double area = fabs ((ppw * (prev->value - cur->value)) +
|
||||
(pw * (cur->value - prevprev->value)) +
|
||||
(cw * (prevprev->value - prev->value)));
|
||||
const float ppv = _desc.to_interface (prevprev->value);
|
||||
const float cv = _desc.to_interface (cur->value);
|
||||
const float pv = _desc.to_interface (prev->value);
|
||||
|
||||
double area = fabs ((ppw * (pv - cv)) +
|
||||
(pw * (cv - ppv)) +
|
||||
(cw * (ppv - pv)));
|
||||
|
||||
if (area < thinning_factor) {
|
||||
iterator tmp = pprev;
|
||||
@ -420,6 +432,7 @@ ControlList::thin (double thinning_factor)
|
||||
*/
|
||||
|
||||
pprev = i;
|
||||
prev = cur;
|
||||
_events.erase (tmp);
|
||||
changed = true;
|
||||
continue;
|
||||
|
@ -33,6 +33,11 @@ struct ParameterDescriptor
|
||||
, rangesteps (0)
|
||||
{}
|
||||
|
||||
virtual ~ParameterDescriptor () {}
|
||||
virtual float to_interface (float val, bool rotary = false) const {
|
||||
return (val - lower) / (upper - lower);
|
||||
}
|
||||
|
||||
float normal; ///< Default value
|
||||
float lower; ///< Minimum value (in Hz, for frequencies)
|
||||
float upper; ///< Maximum value (in Hz, for frequencies)
|
||||
|
Loading…
Reference in New Issue
Block a user