1
0
Fork 0

Add methods for normalized parameter stepping

This is mostly useful for GUIs.
This commit is contained in:
Robbert van der Helm 2022-03-19 16:12:10 +01:00
parent 95370667d7
commit a6e35cfaa9
2 changed files with 14 additions and 0 deletions

View file

@ -52,6 +52,18 @@ pub trait Param: Display {
/// hundredth of the normalized range instead. /// hundredth of the normalized range instead.
fn next_step(&self, from: Self::Plain) -> Self::Plain; fn next_step(&self, from: Self::Plain) -> Self::Plain;
/// The same as [`previous_step()`][Self::previous_step()], but for normalized values. This is
/// mostly useful for GUI widgets.
fn previous_normaliezd_step(&self, from: f32) -> f32 {
self.preview_normalized(self.previous_step(self.preview_plain(from)))
}
/// The same as [`next_step()`][Self::next_step()], but for normalized values. This is mostly
/// useful for GUI widgets.
fn next_normaliezd_step(&self, from: f32) -> f32 {
self.preview_normalized(self.next_step(self.preview_plain(from)))
}
/// 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 for continuous parameters (i.e. [`FloatParam`]). /// sizes for continuous parameters (i.e. [`FloatParam`]).
/// ///

View file

@ -149,6 +149,8 @@ impl ParamPtr {
param_ptr_forward!(pub unsafe fn unit(&self) -> &'static str); param_ptr_forward!(pub unsafe fn unit(&self) -> &'static str);
param_ptr_forward!(pub unsafe fn normalized_value(&self) -> f32); param_ptr_forward!(pub unsafe fn normalized_value(&self) -> f32);
param_ptr_forward!(pub unsafe fn step_count(&self) -> Option<usize>); param_ptr_forward!(pub unsafe fn step_count(&self) -> Option<usize>);
param_ptr_forward!(pub unsafe fn previous_normaliezd_step(&self, from: f32) -> f32);
param_ptr_forward!(pub unsafe fn next_normaliezd_step(&self, from: f32) -> f32);
param_ptr_forward!(pub unsafe fn set_normalized_value(&self, normalized: f32)); param_ptr_forward!(pub unsafe fn set_normalized_value(&self, normalized: f32));
param_ptr_forward!(pub unsafe fn update_smoother(&self, sample_rate: f32, reset: bool)); param_ptr_forward!(pub unsafe fn update_smoother(&self, sample_rate: f32, reset: bool));
param_ptr_forward!(pub unsafe fn initialize_block_smoother(&mut self, max_block_size: usize)); param_ptr_forward!(pub unsafe fn initialize_block_smoother(&mut self, max_block_size: usize));