Add ParamMut method for setting modulation offset
This will be used in the CLAP wrapper to handle `CLAP_EVENT_PARAM_MOD`.
This commit is contained in:
parent
1d3ac1b2af
commit
ddbaffc0bb
15
src/param.rs
15
src/param.rs
|
@ -144,18 +144,25 @@ pub trait Param: Display {
|
||||||
|
|
||||||
/// Contains the setters for parameters. These should not be exposed to plugins to avoid confusion.
|
/// Contains the setters for parameters. These should not be exposed to plugins to avoid confusion.
|
||||||
pub(crate) trait ParamMut: Param {
|
pub(crate) trait ParamMut: Param {
|
||||||
/// Set this parameter based on a plain, unnormalized value. This does **not** snap to step
|
/// Set this parameter based on a plain, unnormalized value. This does not snap to step sizes
|
||||||
/// sizes for continuous parameters (i.e. [`FloatParam`]).
|
/// for continuous parameters (i.e. [`FloatParam`]).
|
||||||
///
|
///
|
||||||
/// This does **not** update the smoother.
|
/// This does **not** update the smoother.
|
||||||
fn set_plain_value(&mut self, plain: Self::Plain);
|
fn set_plain_value(&mut self, plain: Self::Plain);
|
||||||
|
|
||||||
/// Set this parameter based on a normalized value. This **does** snap to step sizes for
|
/// Set this parameter based on a normalized value. The normalized value will be snapped to the
|
||||||
/// continuous parameters (i.e. [`FloatParam`]).
|
/// step size for continuous parameters (i.e. [`FloatParam`]).
|
||||||
///
|
///
|
||||||
/// This does **not** update the smoother.
|
/// This does **not** update the smoother.
|
||||||
fn set_normalized_value(&mut self, normalized: f32);
|
fn set_normalized_value(&mut self, normalized: f32);
|
||||||
|
|
||||||
|
/// Add a modulation offset to the value's unmodulated value. Out of bound values will be
|
||||||
|
/// clamped to the parameter's range. The normalized value will be snapped to the step size for
|
||||||
|
/// continuous parameters (i.e. [`FloatParam`]).
|
||||||
|
///
|
||||||
|
/// This does **not** update the smoother.
|
||||||
|
fn modulate_value(&mut self, modulation_offset: f32);
|
||||||
|
|
||||||
/// Update the smoother state to point to the current value. Also used when initializing and
|
/// Update the smoother state to point to the current value. Also used when initializing and
|
||||||
/// restoring a plugin so everything is in sync. In that case the smoother should completely
|
/// restoring a plugin so everything is in sync. In that case the smoother should completely
|
||||||
/// reset to the current value.
|
/// reset to the current value.
|
||||||
|
|
|
@ -161,6 +161,15 @@ impl ParamMut for BoolParam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn modulate_value(&mut self, modulation_offset: f32) {
|
||||||
|
self.normalized_value =
|
||||||
|
(self.unmodulated_normalized_value + modulation_offset).clamp(0.0, 1.0);
|
||||||
|
self.value = self.preview_plain(self.normalized_value);
|
||||||
|
if let Some(f) = &self.value_changed {
|
||||||
|
f(self.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update_smoother(&mut self, _sample_rate: f32, _init: bool) {
|
fn update_smoother(&mut self, _sample_rate: f32, _init: bool) {
|
||||||
// Can't really smooth a binary parameter now can you
|
// Can't really smooth a binary parameter now can you
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,6 +246,10 @@ impl<T: Enum + PartialEq> ParamMut for EnumParam<T> {
|
||||||
self.inner.set_normalized_value(normalized)
|
self.inner.set_normalized_value(normalized)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn modulate_value(&mut self, modulation_offset: f32) {
|
||||||
|
self.inner.modulate_value(modulation_offset)
|
||||||
|
}
|
||||||
|
|
||||||
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
||||||
self.inner.update_smoother(sample_rate, reset)
|
self.inner.update_smoother(sample_rate, reset)
|
||||||
}
|
}
|
||||||
|
@ -260,6 +264,10 @@ impl ParamMut for EnumParamInner {
|
||||||
self.inner.set_normalized_value(normalized)
|
self.inner.set_normalized_value(normalized)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn modulate_value(&mut self, modulation_offset: f32) {
|
||||||
|
self.inner.modulate_value(modulation_offset)
|
||||||
|
}
|
||||||
|
|
||||||
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
||||||
self.inner.update_smoother(sample_rate, reset)
|
self.inner.update_smoother(sample_rate, reset)
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,6 +221,15 @@ impl ParamMut for FloatParam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn modulate_value(&mut self, modulation_offset: f32) {
|
||||||
|
self.normalized_value =
|
||||||
|
(self.unmodulated_normalized_value + modulation_offset).clamp(0.0, 1.0);
|
||||||
|
self.value = self.preview_plain(self.normalized_value);
|
||||||
|
if let Some(f) = &self.value_changed {
|
||||||
|
f(self.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
||||||
if reset {
|
if reset {
|
||||||
self.smoothed.reset(self.value);
|
self.smoothed.reset(self.value);
|
||||||
|
|
|
@ -186,6 +186,15 @@ impl ParamMut for IntParam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn modulate_value(&mut self, modulation_offset: f32) {
|
||||||
|
self.normalized_value =
|
||||||
|
(self.unmodulated_normalized_value + modulation_offset).clamp(0.0, 1.0);
|
||||||
|
self.value = self.preview_plain(self.normalized_value);
|
||||||
|
if let Some(f) = &self.value_changed {
|
||||||
|
f(self.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
||||||
if reset {
|
if reset {
|
||||||
self.smoothed.reset(self.value);
|
self.smoothed.reset(self.value);
|
||||||
|
|
|
@ -160,6 +160,7 @@ impl ParamPtr {
|
||||||
param_ptr_forward!(pub unsafe fn flags(&self) -> ParamFlags);
|
param_ptr_forward!(pub unsafe fn flags(&self) -> ParamFlags);
|
||||||
|
|
||||||
param_ptr_forward!(pub(crate) unsafe fn set_normalized_value(&self, normalized: f32));
|
param_ptr_forward!(pub(crate) unsafe fn set_normalized_value(&self, normalized: f32));
|
||||||
|
param_ptr_forward!(pub(crate) unsafe fn modulate_value(&self, modulation_offset: f32));
|
||||||
param_ptr_forward!(pub(crate) unsafe fn update_smoother(&self, sample_rate: f32, reset: bool));
|
param_ptr_forward!(pub(crate) unsafe fn update_smoother(&self, sample_rate: f32, reset: bool));
|
||||||
|
|
||||||
// These functions involve casts since the plugin formats only do floating point types, so we
|
// These functions involve casts since the plugin formats only do floating point types, so we
|
||||||
|
|
Loading…
Reference in a new issue