create VmcExtMidiCcBit

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-30 10:41:16 -05:00
parent bcf81cd44e
commit 47e34b1b71

View File

@ -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<Self, String> {
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 });
}
}