use crate::TryFromRawError;
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum GlobalAutomationModeOverride {
Bypass,
Mode(AutomationMode),
}
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum AutomationMode {
TrimRead,
Read,
Touch,
Write,
Latch,
LatchPreview,
}
impl AutomationMode {
pub fn try_from_raw(v: i32) -> Result<AutomationMode, TryFromRawError<i32>> {
use AutomationMode::*;
match v {
0 => Ok(TrimRead),
1 => Ok(Read),
2 => Ok(Touch),
3 => Ok(Write),
4 => Ok(Latch),
5 => Ok(LatchPreview),
_ => Err(TryFromRawError::new(
"couldn't convert to automation mode",
v,
)),
}
}
pub fn to_raw(&self) -> i32 {
use AutomationMode::*;
match self {
TrimRead => 0,
Read => 1,
Touch => 2,
Write => 3,
Latch => 4,
LatchPreview => 5,
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn to_int() {
assert_eq!(3, AutomationMode::Write.to_raw());
}
#[test]
fn from_int() {
assert_eq!(AutomationMode::try_from_raw(3), Ok(AutomationMode::Write));
assert!(AutomationMode::try_from_raw(7).is_err());
}
}