pub trait ParamSet:
'static
+ Send
+ Sync {
type Id: Copy + Into<ParamId>;
const SPECS: &'static [ParamSpec];
// Required methods
fn spec(id: Self::Id) -> Option<&'static ParamSpec>;
fn iter() -> impl Iterator<Item = &'static ParamSpec>;
// Provided method
fn count() -> usize { ... }
}Expand description
Trait for user-defined parameter sets.
Implement this trait to define custom parameters for your plugin. The trait provides type-safe access to parameter specifications.
§Example
use wavecraft_protocol::{ParamSet, ParamSpec, ParamId};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum MyParamId {
Volume = 0,
Pan = 1,
}
impl From<MyParamId> for ParamId {
fn from(id: MyParamId) -> Self {
ParamId(id as u32)
}
}
pub struct MyParams;
impl ParamSet for MyParams {
type Id = MyParamId;
const SPECS: &'static [ParamSpec] = &[
ParamSpec {
id: ParamId(0),
name: "Volume",
short_name: "Vol",
unit: "dB",
default: 0.0,
min: -60.0,
max: 12.0,
step: 0.1,
},
ParamSpec {
id: ParamId(1),
name: "Pan",
short_name: "Pan",
unit: "",
default: 0.0,
min: -1.0,
max: 1.0,
step: 0.01,
},
];
fn spec(id: Self::Id) -> Option<&'static ParamSpec> {
Self::SPECS.iter().find(|s| s.id.0 == id as u32)
}
fn iter() -> impl Iterator<Item = &'static ParamSpec> {
Self::SPECS.iter()
}
}Required Associated Constants§
Required Associated Types§
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.