1
0
Fork 0

Add a .plain_value() to ParamPtr

Useful for snapping when you don't have access to the concrete parameter
type.
This commit is contained in:
Robbert van der Helm 2022-03-18 18:10:22 +01:00
parent fb60f3a28b
commit f43d209a60

View file

@ -158,6 +158,24 @@ impl ParamPtr {
// 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
// can't generate them with the macro: // can't generate them with the macro:
/// Get the plain value for a plain, unnormalized value, as a float. Useful in conjunction with
/// [`preview_plain()`][Self::preview_plain()] to compare a snapped discrete value to a
/// parameter's current snapped value without having to do a back and forth conversion using
/// normalized values.
///
/// # Safety
///
/// Calling this function is only safe as long as the object this `ParamPtr` was created for is
/// still alive.
pub unsafe fn plain_value(&self) -> f32 {
match &self {
ParamPtr::FloatParam(p) => (**p).plain_value(),
ParamPtr::IntParam(p) => (**p).plain_value() as f32,
ParamPtr::BoolParam(p) => (**p).normalized_value(),
ParamPtr::EnumParam(p) => (**p).plain_value() as f32,
}
}
/// Get the normalized value for a plain, unnormalized value, as a float. Used as part of the /// Get the normalized value for a plain, unnormalized value, as a float. Used as part of the
/// wrappers. /// wrappers.
/// ///