#![forbid(unsafe_code)]
mod info;
mod range;
mod smooth;
mod types;
pub use info::{ParamFlags, ParamInfo, ParamUnit};
pub use range::ParamRange;
pub use smooth::{Smoother, SmoothingStyle};
pub use types::{BoolParam, EnumParam, FloatParam, IntParam, ParamEnum};
pub fn format_param_value(info: &ParamInfo, value: f64) -> String {
match info.unit {
ParamUnit::Db => format!("{:.1} dB", value),
ParamUnit::Hz => {
if value >= 1000.0 {
format!("{:.1} kHz", value / 1000.0)
} else {
format!("{:.0} Hz", value)
}
}
ParamUnit::Milliseconds => format!("{:.1} ms", value),
ParamUnit::Seconds => {
if value >= 1.0 {
format!("{:.2} s", value)
} else {
format!("{:.0} ms", value * 1000.0)
}
}
ParamUnit::Percent => format!("{:.0}%", value * 100.0),
ParamUnit::Semitones => format!("{:.1} st", value),
ParamUnit::Pan => {
if value.abs() < 0.01 {
"C".to_string()
} else if value < 0.0 {
format!("{:.0}L", -value * 100.0)
} else {
format!("{:.0}R", value * 100.0)
}
}
ParamUnit::None => format!("{:.2}", value),
}
}
pub trait Params: Send + Sync + 'static {
fn param_infos(&self) -> Vec<ParamInfo>;
fn count(&self) -> usize;
fn get_normalized(&self, id: u32) -> Option<f64>;
fn set_normalized(&self, id: u32, value: f64);
fn get_plain(&self, id: u32) -> Option<f64>;
fn set_plain(&self, id: u32, value: f64);
fn format_value(&self, id: u32, value: f64) -> Option<String>;
fn parse_value(&self, id: u32, text: &str) -> Option<f64>;
fn snap_smoothers(&self);
fn set_sample_rate(&self, sample_rate: f64);
fn collect_values(&self) -> (Vec<u32>, Vec<f64>);
fn restore_values(&self, values: &[(u32, f64)]);
fn default_for_gui() -> Self
where
Self: Sized;
}