diff --git a/src/lib.rs b/src/lib.rs index 21daa45..726b2dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -925,3 +925,48 @@ impl MessageBehavior for VmcExtLight { }); } } + +struct VmcExtVrm { + path: String, + title: String, + hash: Option, +} + +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 { + 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 = 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 }); + } +}