Skip to main content

ParamSet

Trait ParamSet 

Source
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§

Source

const SPECS: &'static [ParamSpec]

All parameter specifications for this set.

Required Associated Types§

Source

type Id: Copy + Into<ParamId>

The parameter ID type (typically an enum).

Required Methods§

Source

fn spec(id: Self::Id) -> Option<&'static ParamSpec>

Get the specification for a parameter by ID.

§Arguments
  • id - The parameter ID
§Returns

The parameter specification, or None if the ID is invalid.

Source

fn iter() -> impl Iterator<Item = &'static ParamSpec>

Iterate over all parameter specifications.

Provided Methods§

Source

fn count() -> usize

Get the number of parameters in this set.

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.

Implementors§