1
0
Fork 0

Move parameter step count to ParamPtr

This commit is contained in:
Robbert van der Helm 2022-03-01 01:48:16 +01:00
parent 1c4a5bc4da
commit 0fd80330bb
2 changed files with 21 additions and 10 deletions

View file

@ -3,6 +3,7 @@
use std::collections::HashMap;
use std::pin::Pin;
use super::range::Range;
use super::Param;
/// Re-export for use in the [Params] proc-macro.
@ -82,6 +83,25 @@ where
}
impl ParamPtr {
/// Get the number of steps for this paramter, if it is stepped.
///
/// # Safety
///
/// Calling this function is only safe as long as the object this `ParamPtr` was created for is
/// still alive.
pub unsafe fn step_count(&self) -> Option<i32> {
match self {
ParamPtr::FloatParam(_) => None,
ParamPtr::IntParam(p) => match (**p).range {
Range::Linear { min, max } => Some(max - min),
Range::Skewed { min, max, .. } => Some(max - min),
Range::SymmetricalSkewed { min, max, .. } => Some(max - min),
},
ParamPtr::BoolParam(_) => Some(1),
ParamPtr::EnumParam(p) => Some((**p).len() as i32 - 1),
}
}
/// Get the human readable name for this parameter.
///
/// # Safety

View file

@ -433,16 +433,7 @@ impl<P: Vst3Plugin> IEditController for Wrapper<P> {
u16strlcpy(&mut info.title, param_ptr.name());
u16strlcpy(&mut info.short_title, param_ptr.name());
u16strlcpy(&mut info.units, param_ptr.unit());
info.step_count = match param_ptr {
ParamPtr::FloatParam(_) => 0,
ParamPtr::IntParam(p) => match (**p).range {
Range::Linear { min, max } => max - min,
Range::Skewed { min, max, .. } => max - min,
Range::SymmetricalSkewed { min, max, .. } => max - min,
},
ParamPtr::BoolParam(_) => 1,
ParamPtr::EnumParam(p) => (**p).len() as i32 - 1,
};
info.step_count = param_ptr.step_count().unwrap_or(0);
info.default_normalized_value = *default_value as f64;
info.unit_id = vst3_sys::vst::kRootUnitId;
info.flags = vst3_sys::vst::ParameterFlags::kCanAutomate as i32;