create VmcExtMidiCcVal

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-30 10:38:53 -05:00
parent 9c231edec3
commit bcf81cd44e

View File

@ -615,3 +615,33 @@ impl MessageBehavior for VmcExtMidiNote {
}); });
} }
} }
struct VmcExtMidiCcVal {
knob: i32,
value: f32,
}
impl MessageBehavior for VmcExtMidiCcVal {
fn to_sendable_osc_message(&self) -> OscMessage {
return OscMessage {
addr: String::from("/VMC/Ext/Midi/CC/Val"),
args: vec![OscType::from(self.knob), OscType::from(self.value)],
};
}
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 value: f32;
match msg.args[0] {
OscType::Int(i) => knob = i,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[1] {
OscType::Float(f) => value = f,
_ => return Err(String::from("arg type invalid")),
}
return Ok(VmcExtMidiCcVal { knob, value });
}
}