launchkey_sdk/launchkey/surface/
display.rs

1use crate::launchkey::surface::encoders::Encoder;
2use crate::launchkey::surface::faders::Fader;
3use strum::IntoEnumIterator;
4use strum_macros::{Display, EnumIter};
5
6#[derive(Debug, Clone, Copy)]
7#[repr(u8)]
8pub enum DisplayTarget {
9    Global(GlobalDisplayTarget),
10    Contextual(ContextualDisplayTarget),
11}
12
13impl From<DisplayTarget> for u8 {
14    fn from(target: DisplayTarget) -> Self {
15        match target {
16            DisplayTarget::Global(global) => global.into(),
17            DisplayTarget::Contextual(contextual) => contextual.into(),
18        }
19    }
20}
21
22#[derive(Debug, Clone, Copy)]
23pub enum GlobalDisplayTarget {
24    Stationary,
25    Temporary,
26}
27
28impl From<GlobalDisplayTarget> for DisplayTarget {
29    fn from(target: GlobalDisplayTarget) -> Self {
30        DisplayTarget::Global(target)
31    }
32}
33
34impl From<GlobalDisplayTarget> for u8 {
35    fn from(target: GlobalDisplayTarget) -> Self {
36        match target {
37            GlobalDisplayTarget::Stationary => 0x20,
38            GlobalDisplayTarget::Temporary => 0x21,
39        }
40    }
41}
42
43#[derive(Debug, Clone, Copy)]
44pub enum ContextualDisplayTarget {
45    Temporary(TemporaryTarget),
46    ModeName(ModeNameTarget),
47}
48
49impl From<ContextualDisplayTarget> for DisplayTarget {
50    fn from(target: ContextualDisplayTarget) -> Self {
51        DisplayTarget::Contextual(target)
52    }
53}
54
55impl From<ContextualDisplayTarget> for u8 {
56    fn from(target: ContextualDisplayTarget) -> Self {
57        match target {
58            ContextualDisplayTarget::Temporary(temporary_target) => temporary_target.into(),
59            ContextualDisplayTarget::ModeName(mode_name_target) => match mode_name_target {
60                ModeNameTarget::Plugin => 0x25,
61                ModeNameTarget::Mixer => 0x24,
62                ModeNameTarget::Sends => 0x26,
63                ModeNameTarget::Transport => 0x27,
64                ModeNameTarget::DAW => 0x22,
65                ModeNameTarget::Drum => 0x23,
66                ModeNameTarget::Volume => 0x28,
67            },
68        }
69    }
70}
71
72#[derive(Debug, Clone, Copy)]
73pub enum TemporaryTarget {
74    Encoder(Encoder),
75    Fader(Fader),
76}
77
78impl From<TemporaryTarget> for u8 {
79    fn from(temporary_target: TemporaryTarget) -> Self {
80        match temporary_target {
81            TemporaryTarget::Encoder(encoder) => encoder.to_index(true),
82            TemporaryTarget::Fader(fader) => fader.to_value(),
83        }
84    }
85}
86
87#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, Display)]
88pub enum ModeNameTarget {
89    Plugin,
90    Mixer,
91    Sends,
92    Transport,
93    DAW,
94    Drum,
95    Volume,
96}
97
98impl ModeNameTarget {
99    /// Get all possible variants of `ModeNameTarget`.
100    pub fn all() -> impl Iterator<Item = Self> {
101        Self::iter()
102    }
103
104    /// Get the count of all variants
105    pub fn count() -> usize {
106        Self::all().count()
107    }
108
109    /// Safely get a variant by its index
110    pub fn from_index(index: usize) -> Option<Self> {
111        Self::all().nth(index)
112    }
113}
114
115#[derive(Debug, Clone)]
116#[repr(u8)]
117pub enum DisplayConfig {
118    Cancel,
119    Arrangement(Arrangement),
120    Trigger,
121}
122
123#[derive(Debug, Clone)]
124pub enum Arrangement {
125    NameValue(String, String),              // (name, value)
126    TitleNameValue(String, String, String), // (title, name, value)
127    TitleEightNames(String, [String; 8]),   // (title, eight names)
128    NameNumericValue(String),               // (name)
129}
130
131impl From<DisplayConfig> for u8 {
132    fn from(config: DisplayConfig) -> Self {
133        match config {
134            DisplayConfig::Cancel => 0x00,
135            DisplayConfig::Arrangement(arrangement) => match arrangement {
136                Arrangement::NameValue(_, _) => 0x01,
137                Arrangement::TitleNameValue(_, _, _) => 0x02,
138                Arrangement::TitleEightNames(_, _) => 0x03,
139                Arrangement::NameNumericValue(_) => 0x04,
140            },
141            DisplayConfig::Trigger => 0x7F,
142        }
143    }
144}