Reorder Param methods
Moving the things that are only used internally to the bottom.
This commit is contained in:
parent
e6292a4650
commit
f103e1e14c
4 changed files with 76 additions and 76 deletions
22
src/param.rs
22
src/param.rs
|
@ -22,17 +22,6 @@ pub trait Param: Display {
|
||||||
/// The plain parameter type.
|
/// The plain parameter type.
|
||||||
type Plain;
|
type Plain;
|
||||||
|
|
||||||
/// 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
|
|
||||||
/// reset to the current value.
|
|
||||||
fn update_smoother(&mut self, sample_rate: f32, reset: bool);
|
|
||||||
|
|
||||||
/// Set this parameter based on a string. Returns whether the updating succeeded. That can fail
|
|
||||||
/// if the string cannot be parsed.
|
|
||||||
///
|
|
||||||
/// TODO: After implementing VST3, check if we handle parsing failures correctly
|
|
||||||
fn set_from_string(&mut self, string: &str) -> bool;
|
|
||||||
|
|
||||||
/// Get the unnormalized value for this parameter.
|
/// Get the unnormalized value for this parameter.
|
||||||
fn plain_value(&self) -> Self::Plain;
|
fn plain_value(&self) -> Self::Plain;
|
||||||
|
|
||||||
|
@ -67,6 +56,17 @@ pub trait Param: Display {
|
||||||
/// wrappers. This **does** snap to step sizes for continuous parameters (i.e. [FloatParam]).
|
/// wrappers. This **does** snap to step sizes for continuous parameters (i.e. [FloatParam]).
|
||||||
fn preview_plain(&self, normalized: f32) -> Self::Plain;
|
fn preview_plain(&self, normalized: f32) -> Self::Plain;
|
||||||
|
|
||||||
|
/// Set this parameter based on a string. Returns whether the updating succeeded. That can fail
|
||||||
|
/// if the string cannot be parsed.
|
||||||
|
///
|
||||||
|
/// TODO: After implementing VST3, check if we handle parsing failures correctly
|
||||||
|
fn set_from_string(&mut self, string: &str) -> bool;
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
/// reset to the current value.
|
||||||
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool);
|
||||||
|
|
||||||
/// Internal implementation detail for implementing [internals::Params]. This should not be used
|
/// Internal implementation detail for implementing [internals::Params]. This should not be used
|
||||||
/// directly.
|
/// directly.
|
||||||
fn as_ptr(&self) -> internals::ParamPtr;
|
fn as_ptr(&self) -> internals::ParamPtr;
|
||||||
|
|
|
@ -54,25 +54,6 @@ impl Display for BoolParam {
|
||||||
impl Param for BoolParam {
|
impl Param for BoolParam {
|
||||||
type Plain = bool;
|
type Plain = bool;
|
||||||
|
|
||||||
fn update_smoother(&mut self, _sample_rate: f32, _init: bool) {
|
|
||||||
// Can't really smooth a binary parameter now can you
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_from_string(&mut self, string: &str) -> bool {
|
|
||||||
let value = match &self.string_to_value {
|
|
||||||
Some(f) => f(string),
|
|
||||||
None => Some(string.eq_ignore_ascii_case("true") || string.eq_ignore_ascii_case("on")),
|
|
||||||
};
|
|
||||||
|
|
||||||
match value {
|
|
||||||
Some(plain) => {
|
|
||||||
self.set_plain_value(plain);
|
|
||||||
true
|
|
||||||
}
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn plain_value(&self) -> Self::Plain {
|
fn plain_value(&self) -> Self::Plain {
|
||||||
self.value
|
self.value
|
||||||
}
|
}
|
||||||
|
@ -122,6 +103,25 @@ impl Param for BoolParam {
|
||||||
normalized > 0.5
|
normalized > 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_from_string(&mut self, string: &str) -> bool {
|
||||||
|
let value = match &self.string_to_value {
|
||||||
|
Some(f) => f(string),
|
||||||
|
None => Some(string.eq_ignore_ascii_case("true") || string.eq_ignore_ascii_case("on")),
|
||||||
|
};
|
||||||
|
|
||||||
|
match value {
|
||||||
|
Some(plain) => {
|
||||||
|
self.set_plain_value(plain);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_smoother(&mut self, _sample_rate: f32, _init: bool) {
|
||||||
|
// Can't really smooth a binary parameter now can you
|
||||||
|
}
|
||||||
|
|
||||||
fn as_ptr(&self) -> ParamPtr {
|
fn as_ptr(&self) -> ParamPtr {
|
||||||
ParamPtr::BoolParam(self as *const BoolParam as *mut BoolParam)
|
ParamPtr::BoolParam(self as *const BoolParam as *mut BoolParam)
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,14 +99,6 @@ impl Display for EnumParamInner {
|
||||||
impl<T: Enum> Param for EnumParam<T> {
|
impl<T: Enum> Param for EnumParam<T> {
|
||||||
type Plain = T;
|
type Plain = T;
|
||||||
|
|
||||||
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
|
||||||
self.inner.update_smoother(sample_rate, reset)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_from_string(&mut self, string: &str) -> bool {
|
|
||||||
self.inner.set_from_string(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn plain_value(&self) -> Self::Plain {
|
fn plain_value(&self) -> Self::Plain {
|
||||||
T::from_index(self.inner.plain_value() as usize)
|
T::from_index(self.inner.plain_value() as usize)
|
||||||
}
|
}
|
||||||
|
@ -140,6 +132,14 @@ impl<T: Enum> Param for EnumParam<T> {
|
||||||
T::from_index(self.inner.preview_plain(normalized) as usize)
|
T::from_index(self.inner.preview_plain(normalized) as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_from_string(&mut self, string: &str) -> bool {
|
||||||
|
self.inner.set_from_string(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
||||||
|
self.inner.update_smoother(sample_rate, reset)
|
||||||
|
}
|
||||||
|
|
||||||
fn as_ptr(&self) -> ParamPtr {
|
fn as_ptr(&self) -> ParamPtr {
|
||||||
self.inner.as_ptr()
|
self.inner.as_ptr()
|
||||||
}
|
}
|
||||||
|
@ -148,20 +148,6 @@ impl<T: Enum> Param for EnumParam<T> {
|
||||||
impl Param for EnumParamInner {
|
impl Param for EnumParamInner {
|
||||||
type Plain = i32;
|
type Plain = i32;
|
||||||
|
|
||||||
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
|
||||||
self.inner.update_smoother(sample_rate, reset)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_from_string(&mut self, string: &str) -> bool {
|
|
||||||
match self.variants.iter().position(|n| n == &string) {
|
|
||||||
Some(idx) => {
|
|
||||||
self.inner.set_plain_value(idx as i32);
|
|
||||||
true
|
|
||||||
}
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn plain_value(&self) -> Self::Plain {
|
fn plain_value(&self) -> Self::Plain {
|
||||||
self.inner.plain_value()
|
self.inner.plain_value()
|
||||||
}
|
}
|
||||||
|
@ -198,6 +184,20 @@ impl Param for EnumParamInner {
|
||||||
self.inner.preview_plain(normalized)
|
self.inner.preview_plain(normalized)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_from_string(&mut self, string: &str) -> bool {
|
||||||
|
match self.variants.iter().position(|n| n == &string) {
|
||||||
|
Some(idx) => {
|
||||||
|
self.inner.set_plain_value(idx as i32);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
||||||
|
self.inner.update_smoother(sample_rate, reset)
|
||||||
|
}
|
||||||
|
|
||||||
fn as_ptr(&self) -> ParamPtr {
|
fn as_ptr(&self) -> ParamPtr {
|
||||||
ParamPtr::EnumParam(self as *const EnumParamInner as *mut EnumParamInner)
|
ParamPtr::EnumParam(self as *const EnumParamInner as *mut EnumParamInner)
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,30 +101,6 @@ macro_rules! impl_plainparam {
|
||||||
impl Param for $ty {
|
impl Param for $ty {
|
||||||
type Plain = $plain;
|
type Plain = $plain;
|
||||||
|
|
||||||
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
|
||||||
if reset {
|
|
||||||
self.smoothed.reset(self.value);
|
|
||||||
} else {
|
|
||||||
self.smoothed.set_target(sample_rate, self.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_from_string(&mut self, string: &str) -> bool {
|
|
||||||
let value = match &self.string_to_value {
|
|
||||||
Some(f) => f(string),
|
|
||||||
// TODO: Check how Rust's parse function handles trailing garbage
|
|
||||||
None => string.parse().ok(),
|
|
||||||
};
|
|
||||||
|
|
||||||
match value {
|
|
||||||
Some(plain) => {
|
|
||||||
self.set_plain_value(plain);
|
|
||||||
true
|
|
||||||
}
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn plain_value(&self) -> Self::Plain {
|
fn plain_value(&self) -> Self::Plain {
|
||||||
self.value
|
self.value
|
||||||
}
|
}
|
||||||
|
@ -186,6 +162,30 @@ macro_rules! impl_plainparam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_from_string(&mut self, string: &str) -> bool {
|
||||||
|
let value = match &self.string_to_value {
|
||||||
|
Some(f) => f(string),
|
||||||
|
// TODO: Check how Rust's parse function handles trailing garbage
|
||||||
|
None => string.parse().ok(),
|
||||||
|
};
|
||||||
|
|
||||||
|
match value {
|
||||||
|
Some(plain) => {
|
||||||
|
self.set_plain_value(plain);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool) {
|
||||||
|
if reset {
|
||||||
|
self.smoothed.reset(self.value);
|
||||||
|
} else {
|
||||||
|
self.smoothed.set_target(sample_rate, self.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn as_ptr(&self) -> ParamPtr {
|
fn as_ptr(&self) -> ParamPtr {
|
||||||
ParamPtr::$ty(self as *const $ty as *mut $ty)
|
ParamPtr::$ty(self as *const $ty as *mut $ty)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue