Skip to main content

eosc_rs/
channel.rs

1use rosc::OscType;
2
3use crate::osc_sender::OscSender;
4use crate::osc_sender::OscSenderError;
5
6pub struct Channel<'a> {
7    pub osc_sender: &'a OscSender,
8    pub channel: u32,
9}
10
11impl Channel<'_> {
12    /// Sets this channel's intensity to the specified value
13    /// value: The intensity of that channel, in percent.
14    pub fn at(&self, value: u8) -> Result<(), OscSenderError> {
15        self.osc_sender.send_osc(
16            format!("/eos/chan/{}", self.channel),
17            vec![OscType::Int(value.into())],
18        )
19    }
20
21    /// Sets this channel's parameter to the specified value.
22    /// param: The parameter to change. e.g: "pan" or "tilt"
23    /// value: what to set this parameter to. A value in degrees for pan and tilt
24    pub fn param(&self, param: &str, value: i32) -> Result<(), OscSenderError> {
25        self.osc_sender.send_osc(
26            format!("/eos/chan/{}/param/{param}", self.channel),
27            vec![OscType::Int(value)],
28        )
29    }
30
31    /// Sets a channel's pan value to the specified angle.
32    /// degrees: The degree value of the pan of this channel
33    pub fn pan(&self, degrees: i32) -> Result<(), OscSenderError> {
34        self.param("pan", degrees)
35    }
36
37    /// Sets a channel's tilt value to the specified angle
38    /// degrees: The degree value of the pan of this channel
39    pub fn tilt(&self, degrees: i32) -> Result<(), OscSenderError> {
40        self.param("tilt", degrees)
41    }
42
43    /// Sets all other channels to zero and leaves this one untouched
44    pub fn remdim(&self) -> Result<(), OscSenderError> {
45        self.osc_sender
46            .send_osc(format!("/eos/chan/{}/remdim", self.channel), vec![])
47    }
48}