mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
This commit is contained in:
parent
573534a9a6
commit
447638ee71
30 changed files with 824 additions and 548 deletions
77
crates/engine/src/audio/audio_out.rs
Normal file
77
crates/engine/src/audio/audio_out.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
use crate::*;
|
||||
|
||||
//impl_port!(AudioOutput: AudioOut -> AudioIn |j, n|j.register_port::<AudioOut>(n));
|
||||
|
||||
#[derive(Debug)] pub struct AudioOutput<'j> {
|
||||
/// Handle to JACK client, for receiving reconnect events.
|
||||
jack: Jack<'j>,
|
||||
/// Port name
|
||||
name: Arc<str>,
|
||||
/// Port handle.
|
||||
port: Port<AudioOut>,
|
||||
/// List of ports to connect to.
|
||||
connections: Vec<PortConnect>
|
||||
}
|
||||
impl<'j> AsRef<Port<AudioOut>> for AudioOutput<'j> {
|
||||
fn as_ref (&self) -> &Port<AudioOut> { &self.port }
|
||||
}
|
||||
impl<'j> AudioOutput<'j> {
|
||||
pub fn new (jack: &Jack, name: impl AsRef<str>, connect: &[PortConnect])
|
||||
-> Usually<Self>
|
||||
{
|
||||
let port = Self {
|
||||
port: jack.register_port::<AudioOut>(name.as_ref())?,
|
||||
jack,
|
||||
name: name.into(),
|
||||
connections: connect.to_vec()
|
||||
};
|
||||
port.connect_to_matching()?;
|
||||
Ok(port)
|
||||
}
|
||||
pub fn name (&self) -> &Arc<str> { &self.name }
|
||||
pub fn port (&self) -> &Port<AudioOut> { &self.port }
|
||||
pub fn port_mut (&mut self) -> &mut Port<AudioOut> { &mut self.port }
|
||||
pub fn into_port (self) -> Port<AudioOut> { 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<AudioOut> { &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<AudioIn>|{
|
||||
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<Unowned>|{
|
||||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue