Move parameter step count to ParamPtr
This commit is contained in:
parent
1c4a5bc4da
commit
0fd80330bb
2 changed files with 21 additions and 10 deletions
|
@ -3,6 +3,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
|
use super::range::Range;
|
||||||
use super::Param;
|
use super::Param;
|
||||||
|
|
||||||
/// Re-export for use in the [Params] proc-macro.
|
/// Re-export for use in the [Params] proc-macro.
|
||||||
|
@ -82,6 +83,25 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParamPtr {
|
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.
|
/// Get the human readable name for this parameter.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|
|
@ -433,16 +433,7 @@ impl<P: Vst3Plugin> IEditController for Wrapper<P> {
|
||||||
u16strlcpy(&mut info.title, param_ptr.name());
|
u16strlcpy(&mut info.title, param_ptr.name());
|
||||||
u16strlcpy(&mut info.short_title, param_ptr.name());
|
u16strlcpy(&mut info.short_title, param_ptr.name());
|
||||||
u16strlcpy(&mut info.units, param_ptr.unit());
|
u16strlcpy(&mut info.units, param_ptr.unit());
|
||||||
info.step_count = match param_ptr {
|
info.step_count = param_ptr.step_count().unwrap_or(0);
|
||||||
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.default_normalized_value = *default_value as f64;
|
info.default_normalized_value = *default_value as f64;
|
||||||
info.unit_id = vst3_sys::vst::kRootUnitId;
|
info.unit_id = vst3_sys::vst::kRootUnitId;
|
||||||
info.flags = vst3_sys::vst::ParameterFlags::kCanAutomate as i32;
|
info.flags = vst3_sys::vst::ParameterFlags::kCanAutomate as i32;
|
||||||
|
|
Loading…
Add table
Reference in a new issue