1
0
Fork 0

Warn on invalid ranges with logarithmic smoothing

This commit is contained in:
Robbert van der Helm 2022-03-06 12:27:52 +01:00
parent 8355c38b9a
commit 963696cbff
2 changed files with 29 additions and 0 deletions

View file

@ -211,6 +211,22 @@ impl FloatParam {
/// Set up a smoother that can gradually interpolate changes made to this parameter, preventing
/// clicks and zipper noises.
pub fn with_smoother(mut self, style: SmoothingStyle) -> Self {
// Logarithmic smoothing will cause problems if the range goes through zero since then you
// end up multplying by zero
let goes_through_zero = match (&style, &self.range) {
(
SmoothingStyle::Logarithmic(_),
FloatRange::Linear { min, max }
| FloatRange::Skewed { min, max, .. }
| FloatRange::SymmetricalSkewed { min, max, .. },
) => *min == 0.0 || *max == 0.0 || min.signum() != max.signum(),
_ => false,
};
nih_debug_assert!(
!goes_through_zero,
"Logarithmic smoothing does not work with ranges that go through zero"
);
self.smoothed = Smoother::new(style);
self
}

View file

@ -190,6 +190,19 @@ impl IntParam {
/// Set up a smoother that can gradually interpolate changes made to this parameter, preventing
/// clicks and zipper noises.
pub fn with_smoother(mut self, style: SmoothingStyle) -> Self {
// Logarithmic smoothing will cause problems if the range goes through zero since then you
// end up multplying by zero
let goes_through_zero = match (&style, &self.range) {
(SmoothingStyle::Logarithmic(_), IntRange::Linear { min, max }) => {
*min == 0 || *max == 0 || min.signum() != max.signum()
}
_ => false,
};
nih_debug_assert!(
!goes_through_zero,
"Logarithmic smoothing does not work with ranges that go through zero"
);
self.smoothed = Smoother::new(style);
self
}