add error messages to custom errors

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-31 13:35:38 -05:00
parent 3f01f2f3fd
commit dff7e09161
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -3,6 +3,7 @@ use godot::{
prelude::{Color, Transform3D, Vector3}, prelude::{Color, Transform3D, Vector3},
}; };
use rosc::{OscMessage, OscType}; use rosc::{OscMessage, OscType};
use std::fmt;
pub trait MessageBehavior { pub trait MessageBehavior {
fn to_osc_message(&self) -> OscMessage; fn to_osc_message(&self) -> OscMessage;
@ -11,20 +12,32 @@ pub trait MessageBehavior {
Self: Sized; Self: Sized;
} }
struct ArgCountErr { pub struct ArgCountErr {
expected_in: Vec<usize>, expected_in: Vec<usize>,
actual: usize, actual: usize,
addr: String, addr: String,
} }
struct ArgTypeErr { impl fmt::Display for ArgCountErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Invalid number of arguments for message with address {}. Expected {:?}, received {}.", self.addr, self.expected_in, self.actual)
}
}
pub struct ArgTypeErr {
expected: Vec<OscType>, expected: Vec<OscType>,
actual: OscType, actual: OscType,
addr: String, addr: String,
arg_count: usize, arg_count: usize,
} }
struct IntRangeErr { impl fmt::Display for ArgTypeErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Invalid type of argument {} for message with address {}. Expected {:?}, received {:?}.", self.arg_count, self.addr, self.expected, self.actual)
}
}
pub struct IntRangeErr {
expected_lower: i32, expected_lower: i32,
expected_upper: i32, expected_upper: i32,
actual: i32, actual: i32,
@ -32,21 +45,39 @@ struct IntRangeErr {
arg_count: usize, arg_count: usize,
} }
struct IntValErr { impl fmt::Display for IntRangeErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Invalid value of integer argument {} for message with address {}. Expected in range [{}, {}], received {}.", self.arg_count, self.addr, self.expected_lower, self.expected_upper, self.actual)
}
}
pub struct IntValErr {
expected_in: Vec<i32>, expected_in: Vec<i32>,
actual: i32, actual: i32,
addr: String, addr: String,
arg_count: usize, arg_count: usize,
} }
struct StrValErr { impl fmt::Display for IntValErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Invalid value of integer argument {} for message with address {}. Expected {:?}, received {:?}.", self.arg_count, self.addr, self.expected_in, self.actual)
}
}
pub struct StrValErr {
expected_in: Vec<String>, expected_in: Vec<String>,
actual: String, actual: String,
addr: String, addr: String,
arg_count: usize, arg_count: usize,
} }
enum FromMessageErr { impl fmt::Display for StrValErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Invalid value of string argument {} for message with address {}. Expected {:?}, received {:?}.", self.arg_count, self.addr, self.expected_in, self.actual)
}
}
pub enum FromMessageErr {
ArgCount(ArgCountErr), ArgCount(ArgCountErr),
ArgType(ArgTypeErr), ArgType(ArgTypeErr),
IntRange(IntRangeErr), IntRange(IntRangeErr),
@ -54,6 +85,7 @@ enum FromMessageErr {
StrVal(StrValErr), StrVal(StrValErr),
} }
#[derive(Debug)]
struct VmcExtOk { struct VmcExtOk {
loaded: i32, loaded: i32,
calibration_state: Option<i32>, calibration_state: Option<i32>,
@ -89,7 +121,7 @@ impl MessageBehavior for VmcExtOk {
result.loaded = i; result.loaded = i;
} }
_ => { _ => {
return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0],addr: msg.addr.to_owned(), arg_count: 0})); return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(),addr: msg.addr.to_owned(), arg_count: 0}));
} }
} }
} else { } else {
@ -101,7 +133,7 @@ impl MessageBehavior for VmcExtOk {
result.calibration_state = Some(i); result.calibration_state = Some(i);
} }
_ => { _ => {
return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr.to_owned(), arg_count: 1})); return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr.to_owned(), arg_count: 1}));
} }
} }
match msg.args[2] { match msg.args[2] {
@ -109,7 +141,7 @@ impl MessageBehavior for VmcExtOk {
result.calibration_mode = Some(i); result.calibration_mode = Some(i);
} }
_ => { _ => {
return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr.to_owned(), arg_count: 2})); return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr.to_owned(), arg_count: 2}));
} }
} }
} }
@ -119,7 +151,7 @@ impl MessageBehavior for VmcExtOk {
result.tracking_status = Some(i); result.tracking_status = Some(i);
} }
_ => { _ => {
return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr.to_owned(), arg_count: 3})); return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3].to_owned(), addr: msg.addr.to_owned(), arg_count: 3}));
} }
} }
} }
@ -127,6 +159,7 @@ impl MessageBehavior for VmcExtOk {
} }
} }
#[derive(Debug)]
struct VmcExtT { struct VmcExtT {
time: f32, time: f32,
} }
@ -144,11 +177,12 @@ impl MessageBehavior for VmcExtT {
} }
match msg.args[0] { match msg.args[0] {
OscType::Float(f) => return Ok(VmcExtT { time: f }), OscType::Float(f) => return Ok(VmcExtT { time: f }),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
} }
} }
#[derive(Debug)]
struct VmcExtRootPos { struct VmcExtRootPos {
name: String, name: String,
transform: Transform3D, transform: Transform3D,
@ -189,19 +223,19 @@ impl MessageBehavior for VmcExtRootPos {
let name: String; let name: String;
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => name = s.to_owned(), OscType::String(s) => name = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => origin.x = f, OscType::Float(f) => origin.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Float(f) => origin.y = f, OscType::Float(f) => origin.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => origin.z = f, OscType::Float(f) => origin.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
let mut quat = Quaternion { let mut quat = Quaternion {
x: 0.0, x: 0.0,
@ -211,19 +245,19 @@ impl MessageBehavior for VmcExtRootPos {
}; };
match msg.args[4] { match msg.args[4] {
OscType::Float(f) => quat.x = f, OscType::Float(f) => quat.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})),
} }
match msg.args[5] { match msg.args[5] {
OscType::Float(f) => quat.y = f, OscType::Float(f) => quat.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})),
} }
match msg.args[6] { match msg.args[6] {
OscType::Float(f) => quat.z = f, OscType::Float(f) => quat.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})),
} }
match msg.args[7] { match msg.args[7] {
OscType::Float(f) => quat.w = f, OscType::Float(f) => quat.w = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})),
} }
result = VmcExtRootPos { result = VmcExtRootPos {
name, name,
@ -247,33 +281,34 @@ impl MessageBehavior for VmcExtRootPos {
}); });
match msg.args[8] { match msg.args[8] {
OscType::Float(f) => result.mr_scale.unwrap().x = f, OscType::Float(f) => result.mr_scale.unwrap().x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8], addr: msg.addr, arg_count: 8})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8].to_owned(), addr: msg.addr, arg_count: 8})),
} }
match msg.args[9] { match msg.args[9] {
OscType::Float(f) => result.mr_scale.unwrap().y = f, OscType::Float(f) => result.mr_scale.unwrap().y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9], addr: msg.addr, arg_count: 9})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9].to_owned(), addr: msg.addr, arg_count: 9})),
} }
match msg.args[10] { match msg.args[10] {
OscType::Float(f) => result.mr_scale.unwrap().z = f, OscType::Float(f) => result.mr_scale.unwrap().z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10], addr: msg.addr, arg_count: 10})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10].to_owned(), addr: msg.addr, arg_count: 10})),
} }
match msg.args[11] { match msg.args[11] {
OscType::Float(f) => result.mr_offset.unwrap().x = f, OscType::Float(f) => result.mr_offset.unwrap().x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11], addr: msg.addr, arg_count: 11})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11].to_owned(), addr: msg.addr, arg_count: 11})),
} }
match msg.args[12] { match msg.args[12] {
OscType::Float(f) => result.mr_offset.unwrap().y = f, OscType::Float(f) => result.mr_offset.unwrap().y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[12], addr: msg.addr, arg_count: 12})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[12].to_owned(), addr: msg.addr, arg_count: 12})),
} }
match msg.args[13] { match msg.args[13] {
OscType::Float(f) => result.mr_offset.unwrap().z = f, OscType::Float(f) => result.mr_offset.unwrap().z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[13], addr: msg.addr, arg_count: 13})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[13].to_owned(), addr: msg.addr, arg_count: 13})),
} }
} }
return Ok(result); return Ok(result);
} }
} }
#[derive(Debug)]
struct VmcExtBonePos { struct VmcExtBonePos {
name: String, name: String,
transform: Transform3D, transform: Transform3D,
@ -304,19 +339,19 @@ impl MessageBehavior for VmcExtBonePos {
} }
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => name = s.to_owned(), OscType::String(s) => name = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => origin.x = f, OscType::Float(f) => origin.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Float(f) => origin.y = f, OscType::Float(f) => origin.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => origin.z = f, OscType::Float(f) => origin.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
let mut quat = Quaternion { let mut quat = Quaternion {
x: 0.0, x: 0.0,
@ -326,19 +361,19 @@ impl MessageBehavior for VmcExtBonePos {
}; };
match msg.args[4] { match msg.args[4] {
OscType::Float(f) => quat.x = f, OscType::Float(f) => quat.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})),
} }
match msg.args[5] { match msg.args[5] {
OscType::Float(f) => quat.y = f, OscType::Float(f) => quat.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})),
} }
match msg.args[6] { match msg.args[6] {
OscType::Float(f) => quat.z = f, OscType::Float(f) => quat.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})),
} }
match msg.args[7] { match msg.args[7] {
OscType::Float(f) => quat.w = f, OscType::Float(f) => quat.w = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})),
} }
return Ok(VmcExtBonePos { return Ok(VmcExtBonePos {
name, name,
@ -347,6 +382,7 @@ impl MessageBehavior for VmcExtBonePos {
} }
} }
#[derive(Debug)]
struct VmcExtBlendVal { struct VmcExtBlendVal {
name: String, name: String,
value: f32, value: f32,
@ -370,16 +406,17 @@ impl MessageBehavior for VmcExtBlendVal {
} }
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => name = s.to_owned(), OscType::String(s) => name = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => value = f, OscType::Float(f) => value = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
return Ok(VmcExtBlendVal { name, value }); return Ok(VmcExtBlendVal { name, value });
} }
} }
#[derive(Debug)]
struct VmcExtCam { struct VmcExtCam {
name: String, name: String,
transform: Transform3D, transform: Transform3D,
@ -414,39 +451,39 @@ impl MessageBehavior for VmcExtCam {
let fov: f32; let fov: f32;
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => name = s.to_owned(), OscType::String(s) => name = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => origin.x = f, OscType::Float(f) => origin.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Float(f) => origin.y = f, OscType::Float(f) => origin.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => origin.z = f, OscType::Float(f) => origin.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
match msg.args[4] { match msg.args[4] {
OscType::Float(f) => quat.x = f, OscType::Float(f) => quat.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})),
} }
match msg.args[5] { match msg.args[5] {
OscType::Float(f) => quat.y = f, OscType::Float(f) => quat.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})),
} }
match msg.args[6] { match msg.args[6] {
OscType::Float(f) => quat.z = f, OscType::Float(f) => quat.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})),
} }
match msg.args[7] { match msg.args[7] {
OscType::Float(f) => quat.w = f, OscType::Float(f) => quat.w = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})),
} }
match msg.args[8] { match msg.args[8] {
OscType::Float(f) => fov = f, OscType::Float(f) => fov = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8], addr: msg.addr, arg_count: 8})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8].to_owned(), addr: msg.addr, arg_count: 8})),
} }
return Ok(VmcExtCam { return Ok(VmcExtCam {
name, name,
@ -456,6 +493,7 @@ impl MessageBehavior for VmcExtCam {
} }
} }
#[derive(Debug)]
struct VmcExtCon { struct VmcExtCon {
active: i32, active: i32,
name: String, name: String,
@ -490,40 +528,40 @@ impl MessageBehavior for VmcExtCon {
let mut axis = Vector3::new(0.0, 0.0, 0.0); let mut axis = Vector3::new(0.0, 0.0, 0.0);
match msg.args[0] { match msg.args[0] {
OscType::Int(i) => active = i, OscType::Int(i) => active = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
if active > 2 || active < 0 { if active > 2 || active < 0 {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 2, actual: active, addr: msg.addr, arg_count: 0})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 2, actual: active, addr: msg.addr, arg_count: 0}));
} }
match &msg.args[1] { match &msg.args[1] {
OscType::String(s) => name = s.to_owned(), OscType::String(s) => name = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Int(i) => is_left = i, OscType::Int(i) => is_left = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
if is_left < 0 || is_left > 1 { if is_left < 0 || is_left > 1 {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 2})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 2}));
} }
match msg.args[3] { match msg.args[3] {
OscType::Int(i) => is_touch = i, OscType::Int(i) => is_touch = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
if is_touch < 0 || is_touch > 1 { if is_touch < 0 || is_touch > 1 {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 3})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 3}));
} }
match msg.args[4] { match msg.args[4] {
OscType::Float(f) => axis.x = f, OscType::Float(f) => axis.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})),
} }
match msg.args[5] { match msg.args[5] {
OscType::Float(f) => axis.y = f, OscType::Float(f) => axis.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})),
} }
match msg.args[6] { match msg.args[6] {
OscType::Float(f) => axis.z = f, OscType::Float(f) => axis.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})),
} }
return Ok(VmcExtCon { return Ok(VmcExtCon {
active, active,
@ -535,6 +573,7 @@ impl MessageBehavior for VmcExtCon {
} }
} }
#[derive(Debug)]
struct VmcExtKey { struct VmcExtKey {
active: bool, active: bool,
name: String, name: String,
@ -575,15 +614,15 @@ impl MessageBehavior for VmcExtKey {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0}));
} }
} }
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match &msg.args[1] { match &msg.args[1] {
OscType::String(s) => name = s.to_owned(), OscType::String(s) => name = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Int(i) => keycode = i, OscType::Int(i) => keycode = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
return Ok(VmcExtKey { return Ok(VmcExtKey {
active, active,
@ -593,6 +632,7 @@ impl MessageBehavior for VmcExtKey {
} }
} }
#[derive(Debug)]
struct VmcExtMidiNote { struct VmcExtMidiNote {
active: bool, active: bool,
channel: i32, channel: i32,
@ -636,19 +676,19 @@ impl MessageBehavior for VmcExtMidiNote {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0}));
} }
} }
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Int(i) => channel = i, OscType::Int(i) => channel = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Int(i) => note = i, OscType::Int(i) => note = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => velocity = f, OscType::Float(f) => velocity = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
return Ok(VmcExtMidiNote { return Ok(VmcExtMidiNote {
active, active,
@ -659,6 +699,7 @@ impl MessageBehavior for VmcExtMidiNote {
} }
} }
#[derive(Debug)]
struct VmcExtMidiCcVal { struct VmcExtMidiCcVal {
knob: i32, knob: i32,
value: f32, value: f32,
@ -679,16 +720,17 @@ impl MessageBehavior for VmcExtMidiCcVal {
let value: f32; let value: f32;
match msg.args[0] { match msg.args[0] {
OscType::Int(i) => knob = i, OscType::Int(i) => knob = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => value = f, OscType::Float(f) => value = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
return Ok(VmcExtMidiCcVal { knob, value }); return Ok(VmcExtMidiCcVal { knob, value });
} }
} }
#[derive(Debug)]
struct VmcExtMidiCcBit { struct VmcExtMidiCcBit {
knob: i32, knob: i32,
active: bool, active: bool,
@ -715,7 +757,7 @@ impl MessageBehavior for VmcExtMidiCcBit {
let active: bool; let active: bool;
match msg.args[0] { match msg.args[0] {
OscType::Int(i) => knob = i, OscType::Int(i) => knob = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Int(i) => { OscType::Int(i) => {
@ -727,12 +769,13 @@ impl MessageBehavior for VmcExtMidiCcBit {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1}));
} }
} }
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
return Ok(VmcExtMidiCcBit { knob, active }); return Ok(VmcExtMidiCcBit { knob, active });
} }
} }
#[derive(Debug)]
struct DeviceTranform { struct DeviceTranform {
addr: String, addr: String,
serial: String, serial: String,
@ -765,35 +808,35 @@ impl MessageBehavior for DeviceTranform {
let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0); let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0);
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => serial = s.to_owned(), OscType::String(s) => serial = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => origin.x = f, OscType::Float(f) => origin.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Float(f) => origin.y = f, OscType::Float(f) => origin.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => origin.z = f, OscType::Float(f) => origin.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
match msg.args[4] { match msg.args[4] {
OscType::Float(f) => quat.x = f, OscType::Float(f) => quat.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})),
} }
match msg.args[5] { match msg.args[5] {
OscType::Float(f) => quat.y = f, OscType::Float(f) => quat.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})),
} }
match msg.args[6] { match msg.args[6] {
OscType::Float(f) => quat.z = f, OscType::Float(f) => quat.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})),
} }
match msg.args[7] { match msg.args[7] {
OscType::Float(f) => quat.w = f, OscType::Float(f) => quat.w = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})),
} }
return Ok(DeviceTranform { return Ok(DeviceTranform {
addr: msg.addr.to_owned(), addr: msg.addr.to_owned(),
@ -803,6 +846,7 @@ impl MessageBehavior for DeviceTranform {
} }
} }
#[derive(Debug)]
struct VmcExtRvc { struct VmcExtRvc {
enable: bool, enable: bool,
port: u16, port: u16,
@ -843,7 +887,7 @@ impl MessageBehavior for VmcExtRvc {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0}));
} }
} }
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Int(i) => { OscType::Int(i) => {
@ -853,12 +897,12 @@ impl MessageBehavior for VmcExtRvc {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 65535, actual: i, addr: msg.addr, arg_count: 1})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 65535, actual: i, addr: msg.addr, arg_count: 1}));
} }
} }
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
if msg.args.len() == 3 { if msg.args.len() == 3 {
match &msg.args[2] { match &msg.args[2] {
OscType::String(s) => ip_addr = Some(s.to_owned()), OscType::String(s) => ip_addr = Some(s.to_owned()),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
} }
return Ok(VmcExtRvc { return Ok(VmcExtRvc {
@ -869,6 +913,7 @@ impl MessageBehavior for VmcExtRvc {
} }
} }
#[derive(Debug)]
struct VmcExtLight { struct VmcExtLight {
name: String, name: String,
transform: Transform3D, transform: Transform3D,
@ -906,51 +951,51 @@ impl MessageBehavior for VmcExtLight {
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0); let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => name = s.to_owned(), OscType::String(s) => name = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => origin.x = f, OscType::Float(f) => origin.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Float(f) => origin.y = f, OscType::Float(f) => origin.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => origin.z = f, OscType::Float(f) => origin.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
match msg.args[4] { match msg.args[4] {
OscType::Float(f) => quat.x = f, OscType::Float(f) => quat.x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})),
} }
match msg.args[5] { match msg.args[5] {
OscType::Float(f) => quat.y = f, OscType::Float(f) => quat.y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})),
} }
match msg.args[6] { match msg.args[6] {
OscType::Float(f) => quat.z = f, OscType::Float(f) => quat.z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})),
} }
match msg.args[7] { match msg.args[7] {
OscType::Float(f) => quat.w = f, OscType::Float(f) => quat.w = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})),
} }
match msg.args[8] { match msg.args[8] {
OscType::Float(f) => color.r = f, OscType::Float(f) => color.r = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8], addr: msg.addr, arg_count: 8})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8].to_owned(), addr: msg.addr, arg_count: 8})),
} }
match msg.args[9] { match msg.args[9] {
OscType::Float(f) => color.g = f, OscType::Float(f) => color.g = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9], addr: msg.addr, arg_count: 9})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9].to_owned(), addr: msg.addr, arg_count: 9})),
} }
match msg.args[10] { match msg.args[10] {
OscType::Float(f) => color.b = f, OscType::Float(f) => color.b = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10], addr: msg.addr, arg_count: 10})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10].to_owned(), addr: msg.addr, arg_count: 10})),
} }
match msg.args[11] { match msg.args[11] {
OscType::Float(f) => color.a = f, OscType::Float(f) => color.a = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11], addr: msg.addr, arg_count: 11})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11].to_owned(), addr: msg.addr, arg_count: 11})),
} }
return Ok(VmcExtLight { return Ok(VmcExtLight {
name, name,
@ -960,6 +1005,7 @@ impl MessageBehavior for VmcExtLight {
} }
} }
#[derive(Debug)]
struct VmcExtVrm { struct VmcExtVrm {
path: String, path: String,
title: String, title: String,
@ -989,22 +1035,23 @@ impl MessageBehavior for VmcExtVrm {
let mut hash: Option<String> = None; let mut hash: Option<String> = None;
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => path = s.to_owned(), OscType::String(s) => path = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match &msg.args[1] { match &msg.args[1] {
OscType::String(s) => title = s.to_owned(), OscType::String(s) => title = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
if msg.args.len() == 3 { if msg.args.len() == 3 {
match &msg.args[2] { match &msg.args[2] {
OscType::String(s) => hash = Some(s.to_owned()), OscType::String(s) => hash = Some(s.to_owned()),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
} }
return Ok(VmcExtVrm { path, title, hash }); return Ok(VmcExtVrm { path, title, hash });
} }
} }
#[derive(Debug)]
struct VmcExtRemote { struct VmcExtRemote {
service: String, service: String,
json: String, json: String,
@ -1028,16 +1075,17 @@ impl MessageBehavior for VmcExtRemote {
let json: String; let json: String;
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => service = s.to_owned(), OscType::String(s) => service = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match &msg.args[1] { match &msg.args[1] {
OscType::String(s) => json = s.to_owned(), OscType::String(s) => json = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
return Ok(VmcExtRemote { service, json }); return Ok(VmcExtRemote { service, json });
} }
} }
#[derive(Debug)]
struct VmcExtOpt { struct VmcExtOpt {
option: String, option: String,
} }
@ -1059,11 +1107,12 @@ impl MessageBehavior for VmcExtOpt {
option: s.to_owned(), option: s.to_owned(),
}) })
} }
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
} }
} }
#[derive(Debug)]
struct VmcExtSettingColor { struct VmcExtSettingColor {
color: Color, color: Color,
} }
@ -1087,24 +1136,25 @@ impl MessageBehavior for VmcExtSettingColor {
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0); let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
match msg.args[0] { match msg.args[0] {
OscType::Float(f) => color.r = f, OscType::Float(f) => color.r = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => color.g = f, OscType::Float(f) => color.g = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Float(f) => color.b = f, OscType::Float(f) => color.b = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => color.a = f, OscType::Float(f) => color.a = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
return Ok(VmcExtSettingColor { color }); return Ok(VmcExtSettingColor { color });
} }
} }
#[derive(Debug)]
struct VmcExtSettingWin { struct VmcExtSettingWin {
is_top_most: bool, is_top_most: bool,
is_transparent: bool, is_transparent: bool,
@ -1152,7 +1202,7 @@ impl MessageBehavior for VmcExtSettingWin {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0}));
} }
} }
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
match msg.args[1] { match msg.args[1] {
OscType::Int(i) => { OscType::Int(i) => {
@ -1162,20 +1212,21 @@ impl MessageBehavior for VmcExtSettingWin {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1}));
} }
} }
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})),
} }
match msg.args[2] { match msg.args[2] {
OscType::Int(i) => result.window_click_through = i, OscType::Int(i) => result.window_click_through = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})),
} }
match msg.args[3] { match msg.args[3] {
OscType::Int(i) => result.hide_border = i, OscType::Int(i) => result.hide_border = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})),
} }
return Ok(result); return Ok(result);
} }
} }
#[derive(Debug)]
struct VmcExtConfig { struct VmcExtConfig {
path: String, path: String,
} }
@ -1193,17 +1244,18 @@ impl MessageBehavior for VmcExtConfig {
} }
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => return Ok(VmcExtConfig { path: s.to_owned() }), OscType::String(s) => return Ok(VmcExtConfig { path: s.to_owned() }),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
} }
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy, Debug)]
enum ThruType { enum ThruType {
Float(f32), Float(f32),
Int(i32), Int(i32),
} }
#[derive(Debug)]
struct VmcThru { struct VmcThru {
addr: String, addr: String,
arg1: String, arg1: String,
@ -1229,20 +1281,21 @@ impl MessageBehavior for VmcThru {
let arg1: String; let arg1: String;
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => arg1 = s.to_owned(), OscType::String(s) => arg1 = s.to_owned(),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})),
} }
let mut arg2: Option<ThruType> = None; let mut arg2: Option<ThruType> = None;
if msg.args.len() == 2 { if msg.args.len() == 2 {
match msg.args[1] { match msg.args[1] {
OscType::Int(i) => arg2 = Some(ThruType::Int(i)), OscType::Int(i) => arg2 = Some(ThruType::Int(i)),
OscType::Float(f) => arg2 = Some(ThruType::Float(f)), OscType::Float(f) => arg2 = Some(ThruType::Float(f)),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0), OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0), OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1}))
} }
} }
return Ok(VmcThru { addr: msg.addr, arg1 , arg2 }) return Ok(VmcThru { addr: msg.addr, arg1 , arg2 })
} }
} }
#[derive(Debug)]
struct VmcExtSetPeriod { struct VmcExtSetPeriod {
status: i32, status: i32,
root: i32, root: i32,
@ -1275,32 +1328,33 @@ impl MessageBehavior for VmcExtSetPeriod {
let devices: i32; let devices: i32;
match msg.args[0] { match msg.args[0] {
OscType::Int(i) => status = i, OscType::Int(i) => status = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0}))
} }
match msg.args[1] { match msg.args[1] {
OscType::Int(i) => root = i, OscType::Int(i) => root = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1}))
} }
match msg.args[2] { match msg.args[2] {
OscType::Int(i) => bone = i, OscType::Int(i) => bone = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2}))
} }
match msg.args[3] { match msg.args[3] {
OscType::Int(i) => blendshape = i, OscType::Int(i) => blendshape = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3}))
} }
match msg.args[4] { match msg.args[4] {
OscType::Int(i) => camera = i, OscType::Int(i) => camera = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4}))
} }
match msg.args[5] { match msg.args[5] {
OscType::Int(i) => devices = i, OscType::Int(i) => devices = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5}))
} }
return Ok(VmcExtSetPeriod { status, root, bone, blendshape, camera, devices}) return Ok(VmcExtSetPeriod { status, root, bone, blendshape, camera, devices})
} }
} }
#[derive(Debug)]
struct VmcExtSetEye { struct VmcExtSetEye {
enable: i32, enable: i32,
position: Vector3, position: Vector3,
@ -1326,25 +1380,26 @@ impl MessageBehavior for VmcExtSetEye {
let z: f32; let z: f32;
match msg.args[0] { match msg.args[0] {
OscType::Int(i) => enable = i, OscType::Int(i) => enable = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0}))
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => x = f, OscType::Float(f) => x = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1}))
} }
match msg.args[2] { match msg.args[2] {
OscType::Float(f) => y = f, OscType::Float(f) => y = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2}))
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => z = f, OscType::Float(f) => z = f,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3}))
} }
return Ok(VmcExtSetEye { enable, position: Vector3::new(x, y, z)}) return Ok(VmcExtSetEye { enable, position: Vector3::new(x, y, z)})
} }
} }
#[derive(Debug)]
struct VmcExtSetRes { struct VmcExtSetRes {
response: String response: String
} }
@ -1353,13 +1408,13 @@ impl MessageBehavior for VmcExtSetRes {
fn to_osc_message(&self) -> OscMessage { fn to_osc_message(&self) -> OscMessage {
return OscMessage{addr: String::from("/VMC/Ext/Set/Res"), args: vec![OscType::from(self.response.to_owned())]}; return OscMessage{addr: String::from("/VMC/Ext/Set/Res"), args: vec![OscType::from(self.response.to_owned())]};
} }
fn from_osc_message(msg: OscMessage) -> Result<Self, String> { fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
if msg.args.len() != 1 { if msg.args.len() != 1 {
return Err(String::from("arg count invalid")); return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![1], actual: msg.args.len(), addr: msg.addr}));
} }
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => return Ok(VmcExtSetRes{response: s.to_owned()}), OscType::String(s) => return Ok(VmcExtSetRes{response: s.to_owned()}),
_ => return Err(String::from("arg type invalid")) _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0}))
} }
} }
} }