From e8bb18c47ec19969dbc69cc365fe2bbf3eef5824 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sat, 30 Dec 2023 10:17:28 -0500 Subject: [PATCH] create VmcExtCon --- src/lib.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8e51a68..89c5cbd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -412,3 +412,82 @@ impl MessageBehavior for VmcExtCam { }); } } + +struct VmcExtCon { + active: i32, + name: String, + is_left: i32, + is_touch: i32, + axis: Vector3, +} + +impl MessageBehavior for VmcExtCon { + fn to_sendable_osc_message(&self) -> OscMessage { + return OscMessage { + addr: String::from("/VMC/Ext/Cam"), + args: vec![ + OscType::from(self.active), + OscType::from(self.name.to_owned()), + OscType::from(self.is_left), + OscType::from(self.is_touch), + OscType::from(self.axis.x), + OscType::from(self.axis.y), + OscType::from(self.axis.z), + ], + }; + } + fn parse_from_osc_message(msg: OscMessage) -> Result { + if msg.args.len() != 7 { + return Err(String::from("arg count invalid")); + } + let active: i32; + let name: String; + let is_left: i32; + let is_touch: i32; + let mut axis = Vector3::new(0.0, 0.0, 0.0); + match msg.args[0] { + OscType::Int(i) => active = i, + _ => return Err(String::from("arg type invalid")), + } + if active > 2 || active < 0 { + return Err(String::from("arg value invalid")); + } + match &msg.args[1] { + OscType::String(s) => name = s.to_owned(), + _ => return Err(String::from("arg value invalid")), + } + match msg.args[2] { + OscType::Int(i) => is_left = i, + _ => return Err(String::from("arg type invalid")), + } + if is_left < 0 || is_left > 1 { + return Err(String::from("arg value invalid")); + } + match msg.args[3] { + OscType::Int(i) => is_touch = i, + _ => return Err(String::from("arg type invalid")), + } + if is_touch < 0 || is_touch > 1 { + return Err(String::from("arg value invalid")); + } + match msg.args[4] { + OscType::Float(f) => axis.x = f, + _ => return Err(String::from("arg type invalid")), + } + match msg.args[5] { + OscType::Float(f) => axis.y = f, + _ => return Err(String::from("arg type invalid")), + } + match msg.args[6] { + OscType::Float(f) => axis.z = f, + _ => return Err(String::from("arg type invalid")), + } + return Ok(VmcExtCon { + active, + name, + is_left, + is_touch, + axis, + }); + } +}