diff --git a/src/params/boolean.rs b/src/params/boolean.rs index abc2a0b6..704d1a8d 100644 --- a/src/params/boolean.rs +++ b/src/params/boolean.rs @@ -276,11 +276,17 @@ impl BoolParam { /// is the parameter's new value. This should not do anything expensive as it may be called /// multiple times in rapid succession, and it can be run from both the GUI and the audio /// thread. + #[inline] pub fn with_callback(mut self, callback: Arc) -> Self { - self.value_changed = Some(callback); + self.set_callback(callback); self } + /// Run a callback whenever this parameter's value changes. See [`BoolParam::with_callback`]. + pub fn set_callback(&mut self, callback: Arc) { + self.value_changed = Some(callback) + } + /// Use a custom conversion function to convert the boolean value to a string. pub fn with_value_to_string( mut self, diff --git a/src/params/enums.rs b/src/params/enums.rs index 9b59c509..ada22943 100644 --- a/src/params/enums.rs +++ b/src/params/enums.rs @@ -384,11 +384,17 @@ impl EnumParam { /// is the parameter's new value. This should not do anything expensive as it may be called /// multiple times in rapid succession, and it can be run from both the GUI and the audio /// thread. + #[inline] pub fn with_callback(mut self, callback: Arc) -> Self { - self.inner.inner = self.inner.inner.with_callback(Arc::new(move |value| { + self.set_callback(callback); + self + } + + /// Run a callback whenever this parameter's value changes. See [`EnumParam::with_callback`]. + pub fn set_callback(&mut self, callback: Arc) { + self.inner.inner.set_callback(Arc::new(move |value| { callback(T::from_index(value as usize)) })); - self } /// Mark the parameter as non-automatable. This means that the parameter cannot be changed from diff --git a/src/params/float.rs b/src/params/float.rs index 83cb8fd8..68176172 100644 --- a/src/params/float.rs +++ b/src/params/float.rs @@ -350,11 +350,17 @@ impl FloatParam { /// is the parameter's new value. This should not do anything expensive as it may be called /// multiple times in rapid succession, and it can be run from both the GUI and the audio /// thread. + #[inline] pub fn with_callback(mut self, callback: Arc) -> Self { - self.value_changed = Some(callback); + self.set_callback(callback); self } + /// Run a callback whenever this parameter's value changes. See [`FloatParam::with_callback`]. + pub fn set_callback(&mut self, callback: Arc) { + self.value_changed = Some(callback); + } + /// Display a unit when rendering this parameter to a string. Appended after the /// [`value_to_string`][Self::with_value_to_string()] function if that is also set. NIH-plug /// will not automatically add a space before the unit. diff --git a/src/params/integer.rs b/src/params/integer.rs index 2ae174c9..77ee85a4 100644 --- a/src/params/integer.rs +++ b/src/params/integer.rs @@ -326,11 +326,17 @@ impl IntParam { /// is the parameter's new value. This should not do anything expensive as it may be called /// multiple times in rapid succession, and it can be run from both the GUI and the audio /// thread. + #[inline] pub fn with_callback(mut self, callback: Arc) -> Self { - self.value_changed = Some(callback); + self.set_callback(callback); self } + /// Run a callback whenever this parameter's value changes. See [`IntParam::with_callback`]. + pub fn set_callback(&mut self, callback: Arc) { + self.value_changed = Some(callback); + } + /// Display a unit when rendering this parameter to a string. Appended after the /// [`value_to_string`][Self::with_value_to_string()] function if that is also set. NIH-plug /// will not automatically add a space before the unit.