pub trait ParameterStore: Send + Sync {
// Required methods
fn count(&self) -> usize;
fn info(&self, index: usize) -> Option<&ParameterInfo>;
fn get_normalized(&self, id: ParameterId) -> ParameterValue;
fn set_normalized(&self, id: ParameterId, value: ParameterValue);
fn normalized_to_string(
&self,
id: ParameterId,
normalized: ParameterValue,
) -> String;
fn string_to_normalized(
&self,
id: ParameterId,
string: &str,
) -> Option<ParameterValue>;
fn normalized_to_plain(
&self,
id: ParameterId,
normalized: ParameterValue,
) -> ParameterValue;
fn plain_to_normalized(
&self,
id: ParameterId,
plain: ParameterValue,
) -> ParameterValue;
// Provided method
fn info_by_id(&self, id: ParameterId) -> Option<&ParameterInfo> { ... }
}Expand description
Low-level trait for plugin parameter collections (host interface).
Implement this trait to declare your plugin’s parameters. The format wrappers (VST3, AU, CLAP) use this to communicate parameter information and values to the host.
§Example
use std::sync::atomic::{AtomicU64, Ordering};
use beamer_core::{ParameterStore, ParameterInfo, ParameterId, ParameterValue};
pub struct MyParameters {
gain: AtomicU64,
gain_info: ParameterInfo,
}
impl ParameterStore for MyParameters {
fn count(&self) -> usize { 1 }
fn info(&self, index: usize) -> Option<&ParameterInfo> {
match index {
0 => Some(&self.gain_info),
_ => None,
}
}
fn get_normalized(&self, id: ParameterId) -> ParameterValue {
match id {
0 => f64::from_bits(self.gain.load(Ordering::Relaxed)),
_ => 0.0,
}
}
fn set_normalized(&self, id: ParameterId, value: ParameterValue) {
match id {
0 => self.gain.store(value.to_bits(), Ordering::Relaxed),
_ => {}
}
}
// ... implement other methods
}Required Methods§
Sourcefn info(&self, index: usize) -> Option<&ParameterInfo>
fn info(&self, index: usize) -> Option<&ParameterInfo>
Returns parameter info by index (0 to count-1).
Returns None if index is out of bounds.
Sourcefn get_normalized(&self, id: ParameterId) -> ParameterValue
fn get_normalized(&self, id: ParameterId) -> ParameterValue
Gets the current normalized value (0.0 to 1.0) for a parameter.
This must be lock-free and safe to call from the audio thread.
Sourcefn set_normalized(&self, id: ParameterId, value: ParameterValue)
fn set_normalized(&self, id: ParameterId, value: ParameterValue)
Sets the normalized value (0.0 to 1.0) for a parameter.
This must be lock-free and safe to call from the audio thread. Implementations should clamp the value to [0.0, 1.0].
Sourcefn normalized_to_string(
&self,
id: ParameterId,
normalized: ParameterValue,
) -> String
fn normalized_to_string( &self, id: ParameterId, normalized: ParameterValue, ) -> String
Converts a normalized value to a display string.
Used by the host to display parameter values in automation lanes, tooltips, etc.
Sourcefn string_to_normalized(
&self,
id: ParameterId,
string: &str,
) -> Option<ParameterValue>
fn string_to_normalized( &self, id: ParameterId, string: &str, ) -> Option<ParameterValue>
Parses a display string to a normalized value.
Used when the user types a value directly. Returns None if
the string cannot be parsed.
Sourcefn normalized_to_plain(
&self,
id: ParameterId,
normalized: ParameterValue,
) -> ParameterValue
fn normalized_to_plain( &self, id: ParameterId, normalized: ParameterValue, ) -> ParameterValue
Converts a normalized value (0.0-1.0) to a plain/real value.
For example, a frequency parameter might map 0.0-1.0 to 20-20000 Hz.
Sourcefn plain_to_normalized(
&self,
id: ParameterId,
plain: ParameterValue,
) -> ParameterValue
fn plain_to_normalized( &self, id: ParameterId, plain: ParameterValue, ) -> ParameterValue
Converts a plain/real value to a normalized value (0.0-1.0).
Inverse of normalized_to_plain.
Provided Methods§
Sourcefn info_by_id(&self, id: ParameterId) -> Option<&ParameterInfo>
fn info_by_id(&self, id: ParameterId) -> Option<&ParameterInfo>
Find parameter info by ID.
Default implementation searches linearly through all parameters.