13
0

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:
Robin Gareus 2022-12-18 00:55:12 +01:00
parent bd3f713d0e
commit a5f36bbbbf
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 21 additions and 3 deletions

View File

@ -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;

View File

@ -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)