add VmcExtVrm

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-30 11:32:33 -05:00
parent 1abd398b67
commit 92fdc84506

View File

@ -925,3 +925,48 @@ impl MessageBehavior for VmcExtLight {
});
}
}
struct VmcExtVrm {
path: String,
title: String,
hash: Option<String>,
}
impl MessageBehavior for VmcExtVrm {
fn to_osc_message(&self) -> OscMessage {
let mut args = vec![
OscType::from(self.path.to_owned()),
OscType::from(self.title.to_owned()),
];
if self.hash.is_some() {
args.push(OscType::from(self.hash.clone().unwrap()));
}
return OscMessage {
addr: String::from("/Vmc/Ext/VRM"),
args,
};
}
fn from_osc_message(msg: OscMessage) -> Result<Self, String> {
if msg.args.len() < 2 || msg.args.len() > 3 {
return Err(String::from("arg count invalid"));
}
let path: String;
let title: String;
let mut hash: Option<String> = None;
match &msg.args[0] {
OscType::String(s) => path = s.to_owned(),
_ => return Err(String::from("arg type invalid")),
}
match &msg.args[1] {
OscType::String(s) => title = s.to_owned(),
_ => return Err(String::from("arg type invalid")),
}
if msg.args.len() == 3 {
match &msg.args[2] {
OscType::String(s) => hash = Some(s.to_owned()),
_ => return Err(String::from("arg type invalid")),
}
}
return Ok(VmcExtVrm { path, title, hash });
}
}