Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/params/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Fn(bool) + Send + Sync>) -> 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<dyn Fn(bool) + Send + Sync>) {
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,
Expand Down
10 changes: 8 additions & 2 deletions src/params/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,17 @@ impl<T: Enum + PartialEq + 'static> EnumParam<T> {
/// 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<dyn Fn(T) + Send + Sync>) -> 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<dyn Fn(T) + Send + Sync>) {
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
Expand Down
8 changes: 7 additions & 1 deletion src/params/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Fn(f32) + Send + Sync>) -> 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<dyn Fn(f32) + Send + Sync>) {
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.
Expand Down
8 changes: 7 additions & 1 deletion src/params/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Fn(i32) + Send + Sync>) -> 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<dyn Fn(i32) + Send + Sync>) {
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.
Expand Down