add VmcThru message

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-31 10:16:57 -05:00
parent 979b9cd87d
commit 290dc17d3e
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -1163,3 +1163,48 @@ impl MessageBehavior for VmcExtConfig {
} }
} }
} }
#[derive(Clone, Copy)]
enum ThruType {
Float(f32),
Int(i32),
}
struct VmcThru {
addr: String,
arg1: String,
arg2: Option<ThruType>
}
impl MessageBehavior for VmcThru {
fn to_osc_message(&self) -> OscMessage {
let mut args = vec![OscType::from(self.arg1.to_owned()
)];
if self.arg2.is_some() {
match self.arg2.unwrap() {
ThruType::Float(val) => args.push(OscType::from(val)),
ThruType::Int(val) => args.push(OscType::from(val)),
}
}
return OscMessage { addr: self.addr.to_owned(), args}
}
fn from_osc_message(msg: OscMessage) -> Result<Self, String> {
if msg.args.len() > 2 || msg.args.len() < 1 {
return Err(String::from("arg count invalid"));
}
let arg1: String;
match &msg.args[0] {
OscType::String(s) => arg1 = s.to_owned(),
_ => return Err(String::from("arg type invalid"))
}
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(String::from("arg type invalid"))
}
}
return Ok(VmcThru { addr: msg.addr, arg1 , arg2 })
}
}