Skip to main content

endless_rs/
types.rs

1//! Public types for the Endless patch API.
2
3/// Audio sample rate in Hz.
4pub const SAMPLE_RATE: u32 = 48_000;
5
6/// Size of the external working buffer (in floats).
7pub const WORKING_BUFFER_SIZE: usize = 2_400_000;
8
9/// Number of hardware knob parameters.
10pub const NUM_PARAMS: usize = 3;
11
12/// LED color indices matching `Patch::Color` in the C++ SDK.
13#[repr(i32)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15pub enum Color {
16    DimWhite = 0,
17    DarkRed = 1,
18    DarkLime = 2,
19    DarkCobalt = 3,
20    LightYellow = 4,
21    DimBlue = 5,
22    Beige = 6,
23    DimCyan = 7,
24    Magenta = 8,
25    LightBlue = 9,
26    PastelGreen = 10,
27    DimYellow = 11,
28    Blue = 12,
29    LightGreen = 13,
30    Red = 14,
31    DimGreen = 15,
32}
33
34/// Hardware knob parameter identifiers.
35#[repr(i32)]
36#[derive(Clone, Copy, Debug, PartialEq, Eq)]
37pub enum ParamId {
38    Left = 0,
39    Mid = 1,
40    Right = 2,
41}
42
43impl ParamId {
44    /// Convert from a raw ABI index. Returns `None` for out-of-range values.
45    #[must_use]
46    pub fn from_raw(idx: i32) -> Option<Self> {
47        match idx {
48            0 => Some(Self::Left),
49            1 => Some(Self::Mid),
50            2 => Some(Self::Right),
51            _ => None,
52        }
53    }
54}
55
56/// Foot-switch action identifiers.
57#[repr(i32)]
58#[derive(Clone, Copy, Debug, PartialEq, Eq)]
59pub enum ActionId {
60    LeftFootSwitchPress = 0,
61    LeftFootSwitchHold = 1,
62}
63
64impl ActionId {
65    /// Convert from a raw ABI index. Returns `None` for out-of-range values.
66    #[must_use]
67    pub fn from_raw(idx: i32) -> Option<Self> {
68        match idx {
69            0 => Some(Self::LeftFootSwitchPress),
70            1 => Some(Self::LeftFootSwitchHold),
71            _ => None,
72        }
73    }
74}
75
76/// Metadata describing a single parameter's range and default.
77#[derive(Clone, Copy, Debug)]
78pub struct ParameterMetadata {
79    pub min: f32,
80    pub max: f32,
81    pub default: f32,
82}
83
84impl Default for ParameterMetadata {
85    fn default() -> Self {
86        Self {
87            min: 0.0,
88            max: 1.0,
89            default: 0.5,
90        }
91    }
92}