diff --git a/src/lib.rs b/src/lib.rs index 708f49d..4fbf4b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -645,3 +645,47 @@ impl MessageBehavior for VmcExtMidiCcVal { return Ok(VmcExtMidiCcVal { knob, value }); } } + +struct VmcExtMidiCcBit { + knob: i32, + active: bool, +} + +impl MessageBehavior for VmcExtMidiCcBit { + fn to_sendable_osc_message(&self) -> OscMessage { + let mut args = vec![OscType::from(self.knob)]; + if self.active { + args.push(OscType::from(1)); + } else { + args.push(OscType::from(0)); + } + return OscMessage { + addr: String::from("/VMC/Ext/Midi/CC/Val"), + args, + }; + } + fn parse_from_osc_message(msg: OscMessage) -> Result { + if msg.args.len() != 2 { + return Err(String::from("arg count invalid")); + } + let knob: i32; + let active: bool; + match msg.args[0] { + OscType::Int(i) => knob = i, + _ => return Err(String::from("arg type invalid")), + } + match msg.args[1] { + OscType::Int(i) => { + if i == 0 { + active = false; + } else if i == 1 { + active = true; + } else { + return Err(String::from("arg value invalid")); + } + } + _ => return Err(String::from("arg type invalid")), + } + return Ok(VmcExtMidiCcBit { knob, active }); + } +}