1#![forbid(unsafe_code)]
2
3mod info;
4mod range;
5mod smooth;
6mod types;
7
8pub use info::{ParamFlags, ParamInfo, ParamUnit};
9pub use range::ParamRange;
10pub use smooth::{Smoother, SmoothingStyle};
11pub use types::{BoolParam, EnumParam, FloatParam, IntParam, ParamEnum};
12
13pub fn format_param_value(info: &ParamInfo, value: f64) -> String {
18 match info.unit {
19 ParamUnit::Db => format!("{:.1} dB", value),
20 ParamUnit::Hz => {
21 if value >= 1000.0 {
22 format!("{:.1} kHz", value / 1000.0)
23 } else {
24 format!("{:.0} Hz", value)
25 }
26 }
27 ParamUnit::Milliseconds => format!("{:.1} ms", value),
28 ParamUnit::Seconds => {
29 if value >= 1.0 {
30 format!("{:.2} s", value)
31 } else {
32 format!("{:.0} ms", value * 1000.0)
33 }
34 }
35 ParamUnit::Percent => format!("{:.0}%", value * 100.0),
36 ParamUnit::Semitones => format!("{:.1} st", value),
37 ParamUnit::Pan => {
38 if value.abs() < 0.01 {
39 "C".to_string()
40 } else if value < 0.0 {
41 format!("{:.0}L", -value * 100.0)
42 } else {
43 format!("{:.0}R", value * 100.0)
44 }
45 }
46 ParamUnit::None => format!("{:.2}", value),
47 }
48}
49
50pub trait Params: Send + Sync + 'static {
53 fn param_infos(&self) -> Vec<ParamInfo>;
55
56 fn count(&self) -> usize;
58
59 fn get_normalized(&self, id: u32) -> Option<f64>;
61
62 fn set_normalized(&self, id: u32, value: f64);
64
65 fn get_plain(&self, id: u32) -> Option<f64>;
67
68 fn set_plain(&self, id: u32, value: f64);
70
71 fn format_value(&self, id: u32, value: f64) -> Option<String>;
73
74 fn parse_value(&self, id: u32, text: &str) -> Option<f64>;
76
77 fn snap_smoothers(&self);
79
80 fn set_sample_rate(&self, sample_rate: f64);
82
83 fn collect_values(&self) -> (Vec<u32>, Vec<f64>);
85
86 fn restore_values(&self, values: &[(u32, f64)]);
88
89 fn default_for_gui() -> Self
92 where
93 Self: Sized;
94}