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},
};
use rosc::{OscMessage, OscType};
use std::fmt;
pub trait MessageBehavior {
fn to_osc_message(&self) -> OscMessage;
@ -11,20 +12,32 @@ pub trait MessageBehavior {
Self: Sized;
}
struct ArgCountErr {
pub struct ArgCountErr {
expected_in: Vec<usize>,
actual: usize,
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>,
actual: OscType,
addr: String,
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_upper: i32,
actual: i32,
@ -32,21 +45,39 @@ struct IntRangeErr {
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>,
actual: i32,
addr: String,
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>,
actual: String,
addr: String,
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),
ArgType(ArgTypeErr),
IntRange(IntRangeErr),
@ -54,6 +85,7 @@ enum FromMessageErr {
StrVal(StrValErr),
}
#[derive(Debug)]
struct VmcExtOk {
loaded: i32,
calibration_state: Option<i32>,
@ -89,7 +121,7 @@ impl MessageBehavior for VmcExtOk {
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 {
@ -101,7 +133,7 @@ impl MessageBehavior for VmcExtOk {
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] {
@ -109,7 +141,7 @@ impl MessageBehavior for VmcExtOk {
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);
}
_ => {
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 {
time: f32,
}
@ -144,11 +177,12 @@ impl MessageBehavior for VmcExtT {
}
match msg.args[0] {
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 {
name: String,
transform: Transform3D,
@ -189,19 +223,19 @@ impl MessageBehavior for VmcExtRootPos {
let name: String;
match &msg.args[0] {
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] {
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] {
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] {
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 {
x: 0.0,
@ -211,19 +245,19 @@ impl MessageBehavior for VmcExtRootPos {
};
match msg.args[4] {
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] {
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] {
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] {
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 {
name,
@ -247,33 +281,34 @@ impl MessageBehavior for VmcExtRootPos {
});
match msg.args[8] {
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] {
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] {
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] {
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] {
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] {
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);
}
}
#[derive(Debug)]
struct VmcExtBonePos {
name: String,
transform: Transform3D,
@ -304,19 +339,19 @@ impl MessageBehavior for VmcExtBonePos {
}
match &msg.args[0] {
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] {
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] {
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] {
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 {
x: 0.0,
@ -326,19 +361,19 @@ impl MessageBehavior for VmcExtBonePos {
};
match msg.args[4] {
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] {
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] {
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] {
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 {
name,
@ -347,6 +382,7 @@ impl MessageBehavior for VmcExtBonePos {
}
}
#[derive(Debug)]
struct VmcExtBlendVal {
name: String,
value: f32,
@ -370,16 +406,17 @@ impl MessageBehavior for VmcExtBlendVal {
}
match &msg.args[0] {
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] {
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 });
}
}
#[derive(Debug)]
struct VmcExtCam {
name: String,
transform: Transform3D,
@ -414,39 +451,39 @@ impl MessageBehavior for VmcExtCam {
let fov: f32;
match &msg.args[0] {
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] {
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] {
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] {
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] {
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] {
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] {
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] {
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] {
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 {
name,
@ -456,6 +493,7 @@ impl MessageBehavior for VmcExtCam {
}
}
#[derive(Debug)]
struct VmcExtCon {
active: i32,
name: String,
@ -490,40 +528,40 @@ impl MessageBehavior for VmcExtCon {
let mut axis = Vector3::new(0.0, 0.0, 0.0);
match msg.args[0] {
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 {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 2, actual: active, addr: msg.addr, arg_count: 0}));
}
match &msg.args[1] {
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] {
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 {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 2}));
}
match msg.args[3] {
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 {
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 3}));
}
match msg.args[4] {
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] {
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] {
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 {
active,
@ -535,6 +573,7 @@ impl MessageBehavior for VmcExtCon {
}
}
#[derive(Debug)]
struct VmcExtKey {
active: bool,
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::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] {
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] {
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 {
active,
@ -593,6 +632,7 @@ impl MessageBehavior for VmcExtKey {
}
}
#[derive(Debug)]
struct VmcExtMidiNote {
active: bool,
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::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] {
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] {
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] {
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 {
active,
@ -659,6 +699,7 @@ impl MessageBehavior for VmcExtMidiNote {
}
}
#[derive(Debug)]
struct VmcExtMidiCcVal {
knob: i32,
value: f32,
@ -679,16 +720,17 @@ impl MessageBehavior for VmcExtMidiCcVal {
let value: f32;
match msg.args[0] {
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] {
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 });
}
}
#[derive(Debug)]
struct VmcExtMidiCcBit {
knob: i32,
active: bool,
@ -715,7 +757,7 @@ impl MessageBehavior for VmcExtMidiCcBit {
let active: bool;
match msg.args[0] {
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] {
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::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 });
}
}
#[derive(Debug)]
struct DeviceTranform {
addr: String,
serial: String,
@ -765,35 +808,35 @@ impl MessageBehavior for DeviceTranform {
let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0);
match &msg.args[0] {
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] {
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] {
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] {
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] {
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] {
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] {
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] {
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 {
addr: msg.addr.to_owned(),
@ -803,6 +846,7 @@ impl MessageBehavior for DeviceTranform {
}
}
#[derive(Debug)]
struct VmcExtRvc {
enable: bool,
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::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] {
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::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 {
match &msg.args[2] {
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 {
@ -869,6 +913,7 @@ impl MessageBehavior for VmcExtRvc {
}
}
#[derive(Debug)]
struct VmcExtLight {
name: String,
transform: Transform3D,
@ -906,51 +951,51 @@ impl MessageBehavior for VmcExtLight {
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
match &msg.args[0] {
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] {
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] {
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] {
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] {
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] {
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] {
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] {
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] {
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] {
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] {
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] {
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 {
name,
@ -960,6 +1005,7 @@ impl MessageBehavior for VmcExtLight {
}
}
#[derive(Debug)]
struct VmcExtVrm {
path: String,
title: String,
@ -989,22 +1035,23 @@ impl MessageBehavior for VmcExtVrm {
let mut hash: Option<String> = None;
match &msg.args[0] {
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] {
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 {
match &msg.args[2] {
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 });
}
}
#[derive(Debug)]
struct VmcExtRemote {
service: String,
json: String,
@ -1028,16 +1075,17 @@ impl MessageBehavior for VmcExtRemote {
let json: String;
match &msg.args[0] {
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] {
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 });
}
}
#[derive(Debug)]
struct VmcExtOpt {
option: String,
}
@ -1059,11 +1107,12 @@ impl MessageBehavior for VmcExtOpt {
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 {
color: Color,
}
@ -1087,24 +1136,25 @@ impl MessageBehavior for VmcExtSettingColor {
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
match msg.args[0] {
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] {
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] {
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] {
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 });
}
}
#[derive(Debug)]
struct VmcExtSettingWin {
is_top_most: 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::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] {
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::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] {
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] {
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);
}
}
#[derive(Debug)]
struct VmcExtConfig {
path: String,
}
@ -1193,17 +1244,18 @@ impl MessageBehavior for VmcExtConfig {
}
match &msg.args[0] {
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 {
Float(f32),
Int(i32),
}
#[derive(Debug)]
struct VmcThru {
addr: String,
arg1: String,
@ -1229,20 +1281,21 @@ impl MessageBehavior for VmcThru {
let arg1: String;
match &msg.args[0] {
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;
if msg.args.len() == 2 {
match msg.args[1] {
OscType::Int(i) => arg2 = Some(ThruType::Int(i)),
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 })
}
}
#[derive(Debug)]
struct VmcExtSetPeriod {
status: i32,
root: i32,
@ -1275,32 +1328,33 @@ impl MessageBehavior for VmcExtSetPeriod {
let devices: i32;
match msg.args[0] {
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] {
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] {
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] {
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] {
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] {
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})
}
}
#[derive(Debug)]
struct VmcExtSetEye {
enable: i32,
position: Vector3,
@ -1326,25 +1380,26 @@ impl MessageBehavior for VmcExtSetEye {
let z: f32;
match msg.args[0] {
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] {
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] {
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] {
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)})
}
}
#[derive(Debug)]
struct VmcExtSetRes {
response: String
}
@ -1353,13 +1408,13 @@ impl MessageBehavior for VmcExtSetRes {
fn to_osc_message(&self) -> OscMessage {
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 {
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] {
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}))
}
}
}