use crate::*; //impl_port!(AudioOutput: AudioOut -> AudioIn |j, n|j.register_port::(n)); #[derive(Debug)] pub struct AudioOutput<'j> { /// Handle to JACK client, for receiving reconnect events. jack: Jack<'j>, /// Port name name: Arc, /// Port handle. port: Port, /// List of ports to connect to. connections: Vec } impl<'j> AsRef> for AudioOutput<'j> { fn as_ref (&self) -> &Port { &self.port } } impl<'j> AudioOutput<'j> { pub fn new (jack: &Jack, name: impl AsRef, connect: &[PortConnect]) -> Usually { let port = Self { port: jack.register_port::(name.as_ref())?, jack, name: name.into(), connections: connect.to_vec() }; port.connect_to_matching()?; Ok(port) } pub fn name (&self) -> &Arc { &self.name } pub fn port (&self) -> &Port { &self.port } pub fn port_mut (&mut self) -> &mut Port { &mut self.port } pub fn into_port (self) -> Port { self.port } pub fn close (self) -> Usually<()> { let Self { jack, port, .. } = self; Ok(jack.with_client(|client|client.unregister_port(port))?) } } impl<'j> HasJack<'j> for AudioOutput<'j> { fn jack (&self) -> &'j Jack<'j> { &self.jack } } impl<'j> JackPort<'j> for AudioOutput<'j> { type Port = AudioOut; type Pair = AudioIn; fn port (&self) -> &Port { &self.port } } connect_to!(<'j>|self: AudioOutput<'j>, port: &str|{ self.with_client(|c|if let Some(ref port) = c.port_by_name(port.as_ref()) { self.connect_to(port) } else { Ok(Missing) }) }); connect_to!(<'j>|self: AudioOutput<'j>, port: Port|{ self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) { Connected } else if let Ok(_) = c.connect_ports(port, &self.port) { Connected } else { Mismatch })) }); connect_to!(<'j>|self: AudioOutput<'j>, port: Port|{ self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) { Connected } else if let Ok(_) = c.connect_ports(port, &self.port) { Connected } else { Mismatch })) }); impl<'j> ConnectAuto<'j> for AudioOutput<'j> { fn connections (&self) -> &[PortConnect] { &self.connections } }