reaper_medium/
automation_mode.rs1use crate::TryFromRawError;
2
3#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
5pub enum GlobalAutomationModeOverride {
6 Bypass,
8 Mode(AutomationMode),
10}
11
12#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
14pub enum AutomationMode {
15 TrimRead,
16 Read,
17 Touch,
18 Write,
19 Latch,
20 LatchPreview,
21}
22
23impl AutomationMode {
24 pub fn try_from_raw(v: i32) -> Result<AutomationMode, TryFromRawError<i32>> {
26 use AutomationMode::*;
27 match v {
28 0 => Ok(TrimRead),
29 1 => Ok(Read),
30 2 => Ok(Touch),
31 3 => Ok(Write),
32 4 => Ok(Latch),
33 5 => Ok(LatchPreview),
34 _ => Err(TryFromRawError::new(
35 "couldn't convert to automation mode",
36 v,
37 )),
38 }
39 }
40
41 pub fn to_raw(&self) -> i32 {
43 use AutomationMode::*;
44 match self {
45 TrimRead => 0,
46 Read => 1,
47 Touch => 2,
48 Write => 3,
49 Latch => 4,
50 LatchPreview => 5,
51 }
52 }
53}
54
55#[cfg(test)]
56mod test {
57 use super::*;
58
59 #[test]
60 fn to_int() {
61 assert_eq!(3, AutomationMode::Write.to_raw());
62 }
63
64 #[test]
65 fn from_int() {
66 assert_eq!(AutomationMode::try_from_raw(3), Ok(AutomationMode::Write));
67 assert!(AutomationMode::try_from_raw(7).is_err());
68 }
69}