use std::{net::IpAddr, vec};
use rosc::{OscError, OscType};
use snafu::Snafu;
use crate::{
channel::Channel,
osc_sender::{OscSender, OscSenderError},
};
pub struct EosDesk {
osc_sender: OscSender,
}
#[derive(Debug, Snafu)]
pub enum EosDeskError {
#[snafu(display("failed to create EOS OSC UDP Socket on {to:#?}"))]
FailedUDPSocket {
source: std::io::Error,
to: (IpAddr, u16),
},
#[snafu(display("failed to encode OSC packet with destination {address}"))]
FailedPacketEncoding { source: OscError, address: String },
#[snafu(display("failed to send UDP packet with data: {data:#?} to {to:#?}"))]
FailedUDPSend {
source: std::io::Error,
data: Vec<u8>,
to: (IpAddr, u16),
},
}
impl EosDesk {
pub fn new(host: (IpAddr, u16), desk: (IpAddr, u16)) -> Result<Self, OscSenderError> {
let osc_sender = OscSender::new(host, desk)?;
Ok(Self { osc_sender })
}
pub fn command(&self, command: &str) -> Result<(), OscSenderError> {
self.osc_sender.send_osc(
"/eos/newcmd".to_string(),
vec![OscType::String(format!("{command} ENTER"))],
)?;
Ok(())
}
pub fn channel(&'_ self, channel: u32) -> Channel<'_> {
Channel {
osc_sender: &self.osc_sender,
channel,
}
}
pub fn record_cue(&self, cue_number: &str, time: f32) -> Result<(), OscSenderError> {
let command: String = format!("Record Cue {} Time {}", cue_number, time);
self.command(&command)
}
pub fn go(&self) -> Result<(), OscSenderError> {
self.osc_sender
.send_osc(" /eos/key/go_0".to_string(), vec![])
}
pub fn fire(&self, cue: &str) -> Result<(), OscSenderError> {
self.osc_sender.send_osc(
" /eos/cue/fire".to_string(),
vec![OscType::String(cue.to_string())],
)
}
}