Make parameter names owned
That way you can generate parameters with custom `Params` implementations.
This commit is contained in:
parent
44603b1a6d
commit
3c69fb72cf
6 changed files with 25 additions and 25 deletions
|
@ -47,7 +47,7 @@ pub trait Param: Display {
|
|||
type Plain: PartialEq;
|
||||
|
||||
/// Get the human readable name for this parameter.
|
||||
fn name(&self) -> &'static str;
|
||||
fn name(&self) -> &str;
|
||||
|
||||
/// Get the unit label for this parameter, if any.
|
||||
fn unit(&self) -> &'static str;
|
||||
|
|
|
@ -23,7 +23,7 @@ pub struct BoolParam {
|
|||
pub value_changed: Option<Arc<dyn Fn(bool) + Send + Sync>>,
|
||||
|
||||
/// The parameter's human readable display name.
|
||||
pub name: &'static str,
|
||||
pub name: String,
|
||||
/// Optional custom conversion function from a boolean value to a string.
|
||||
pub value_to_string: Option<Arc<dyn Fn(bool) -> String + Send + Sync>>,
|
||||
/// Optional custom conversion function from a string to a boolean value. If the string cannot
|
||||
|
@ -40,7 +40,7 @@ impl Default for BoolParam {
|
|||
default: false,
|
||||
flags: ParamFlags::default(),
|
||||
value_changed: None,
|
||||
name: "",
|
||||
name: String::new(),
|
||||
value_to_string: None,
|
||||
string_to_value: None,
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ impl Display for BoolParam {
|
|||
impl Param for BoolParam {
|
||||
type Plain = bool;
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
self.name
|
||||
fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
fn unit(&self) -> &'static str {
|
||||
|
@ -144,11 +144,11 @@ impl Param for BoolParam {
|
|||
impl BoolParam {
|
||||
/// Build a new [`BoolParam`]. Use the other associated functions to modify the behavior of the
|
||||
/// parameter.
|
||||
pub fn new(name: &'static str, default: bool) -> Self {
|
||||
pub fn new(name: impl Into<String>, default: bool) -> Self {
|
||||
Self {
|
||||
value: default,
|
||||
default,
|
||||
name,
|
||||
name: name.into(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ impl Display for EnumParamInner {
|
|||
impl<T: Enum + PartialEq> Param for EnumParam<T> {
|
||||
type Plain = T;
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
fn name(&self) -> &str {
|
||||
self.inner.name()
|
||||
}
|
||||
|
||||
|
@ -171,8 +171,8 @@ impl<T: Enum + PartialEq> Param for EnumParam<T> {
|
|||
impl Param for EnumParamInner {
|
||||
type Plain = i32;
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
self.inner.name
|
||||
fn name(&self) -> &str {
|
||||
&self.inner.name
|
||||
}
|
||||
|
||||
fn unit(&self) -> &'static str {
|
||||
|
@ -244,7 +244,7 @@ impl Param for EnumParamInner {
|
|||
impl<T: Enum + PartialEq + 'static> EnumParam<T> {
|
||||
/// Build a new [Self]. Use the other associated functions to modify the behavior of the
|
||||
/// parameter.
|
||||
pub fn new(name: &'static str, default: T) -> Self {
|
||||
pub fn new(name: impl Into<String>, default: T) -> Self {
|
||||
let variants = T::variants();
|
||||
|
||||
Self {
|
||||
|
@ -255,7 +255,7 @@ impl<T: Enum + PartialEq + 'static> EnumParam<T> {
|
|||
min: 0,
|
||||
max: variants.len() as i32 - 1,
|
||||
},
|
||||
name,
|
||||
name: name.into(),
|
||||
..Default::default()
|
||||
},
|
||||
variants,
|
||||
|
|
|
@ -50,7 +50,7 @@ pub struct FloatParam {
|
|||
/// this is also used when formatting the parameter. This must be a positive, nonzero number.
|
||||
pub step_size: Option<f32>,
|
||||
/// The parameter's human readable display name.
|
||||
pub name: &'static str,
|
||||
pub name: String,
|
||||
/// The parameter value's unit, added after [`value_to_string`][Self::value_to_string] if that
|
||||
/// is set. NIH-plug will not automatically add a space before the unit.
|
||||
pub unit: &'static str,
|
||||
|
@ -75,7 +75,7 @@ impl Default for FloatParam {
|
|||
value_changed: None,
|
||||
range: FloatRange::default(),
|
||||
step_size: None,
|
||||
name: "",
|
||||
name: String::new(),
|
||||
unit: "",
|
||||
value_to_string: None,
|
||||
string_to_value: None,
|
||||
|
@ -99,8 +99,8 @@ impl Display for FloatParam {
|
|||
impl Param for FloatParam {
|
||||
type Plain = f32;
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
self.name
|
||||
fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
fn unit(&self) -> &'static str {
|
||||
|
@ -213,12 +213,12 @@ impl Param for FloatParam {
|
|||
impl FloatParam {
|
||||
/// Build a new [`FloatParam`]. Use the other associated functions to modify the behavior of the
|
||||
/// parameter.
|
||||
pub fn new(name: &'static str, default: f32, range: FloatRange) -> Self {
|
||||
pub fn new(name: impl Into<String>, default: f32, range: FloatRange) -> Self {
|
||||
Self {
|
||||
value: default,
|
||||
default,
|
||||
range,
|
||||
name,
|
||||
name: name.into(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ pub struct IntParam {
|
|||
/// The distribution of the parameter's values.
|
||||
pub range: IntRange,
|
||||
/// The parameter's human readable display name.
|
||||
pub name: &'static str,
|
||||
pub name: String,
|
||||
/// The parameter value's unit, added after `value_to_string` if that is set. NIH-plug will not
|
||||
/// automatically add a space before the unit.
|
||||
pub unit: &'static str,
|
||||
|
@ -70,7 +70,7 @@ impl Default for IntParam {
|
|||
flags: ParamFlags::default(),
|
||||
value_changed: None,
|
||||
range: IntRange::default(),
|
||||
name: "",
|
||||
name: String::new(),
|
||||
unit: "",
|
||||
value_to_string: None,
|
||||
string_to_value: None,
|
||||
|
@ -90,8 +90,8 @@ impl Display for IntParam {
|
|||
impl Param for IntParam {
|
||||
type Plain = i32;
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
self.name
|
||||
fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
fn unit(&self) -> &'static str {
|
||||
|
@ -177,12 +177,12 @@ impl Param for IntParam {
|
|||
impl IntParam {
|
||||
/// Build a new [`IntParam`]. Use the other associated functions to modify the behavior of the
|
||||
/// parameter.
|
||||
pub fn new(name: &'static str, default: i32, range: IntRange) -> Self {
|
||||
pub fn new(name: impl Into<String>, default: i32, range: IntRange) -> Self {
|
||||
Self {
|
||||
value: default,
|
||||
default,
|
||||
range,
|
||||
name,
|
||||
name: name.into(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ macro_rules! param_ptr_forward(
|
|||
);
|
||||
|
||||
impl ParamPtr {
|
||||
param_ptr_forward!(pub unsafe fn name(&self) -> &'static str);
|
||||
param_ptr_forward!(pub unsafe fn name(&self) -> &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 default_normalized_value(&self) -> f32);
|
||||
|
|
Loading…
Add table
Reference in a new issue