truce_params/info.rs
1use crate::range::ParamRange;
2
3/// Metadata for a single parameter, used by format wrappers.
4///
5/// `Copy` because every field is POD (`&'static str`, scalars,
6/// bitflags, the [`ParamRange`] / [`ParamUnit`] enums). Lets the
7/// audio path pass `param_infos[i]` by value without `clone()` noise.
8#[derive(Clone, Copy, Debug)]
9pub struct ParamInfo {
10 pub id: u32,
11 pub name: &'static str,
12 pub short_name: &'static str,
13 pub group: &'static str,
14 pub range: ParamRange,
15 pub default_plain: f64,
16 pub flags: ParamFlags,
17 pub unit: ParamUnit,
18 /// Which `*Param` type backs this entry. Drives display rounding
19 /// (`IntParam` skips fractional digits) and `value_text` parsing,
20 /// independently of [`ParamRange`] - a `FloatParam` declared with
21 /// `range = "discrete(...)"` should still format as a float, so
22 /// inferring kind from range alone is wrong.
23 pub kind: ParamValueKind,
24}
25
26/// Which strongly-typed `*Param` constructor produced this
27/// [`ParamInfo`]. The `#[derive(Params)]` macro sets it from the
28/// field type so format-side code can branch on the original
29/// typing without re-deriving it from `range` / `unit`.
30#[derive(Clone, Copy, Debug, PartialEq, Eq)]
31pub enum ParamValueKind {
32 Float,
33 Int,
34 Bool,
35 Enum,
36}
37
38bitflags::bitflags! {
39 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
40 pub struct ParamFlags: u32 {
41 const AUTOMATABLE = 0b0001;
42 const HIDDEN = 0b0010;
43 const READONLY = 0b0100;
44 const IS_BYPASS = 0b1000;
45 }
46}
47
48#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49pub enum ParamUnit {
50 None,
51 Db,
52 Hz,
53 Milliseconds,
54 Seconds,
55 Percent,
56 Semitones,
57 Pan,
58}
59
60impl ParamUnit {
61 /// Format-agnostic unit string for host display.
62 #[must_use]
63 pub fn as_str(&self) -> &'static str {
64 match self {
65 Self::Db => "dB",
66 Self::Hz => "Hz",
67 Self::Milliseconds => "ms",
68 Self::Seconds => "s",
69 Self::Percent => "%",
70 Self::Semitones => "st",
71 Self::Pan | Self::None => "",
72 }
73 }
74}