mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-10 21:56:42 +01:00
wip: refactor into crates
This commit is contained in:
parent
96e17e7f7c
commit
5ae99b4ada
87 changed files with 2281 additions and 2217 deletions
55
crates/tek_jack/src/device.rs
Normal file
55
crates/tek_jack/src/device.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
//! Wrap JACK-enabled [Device]s.
|
||||
|
||||
use super::*;
|
||||
use tek_core::ratatui::prelude::{Buffer, Rect};
|
||||
|
||||
/// A [Device] bound to a JACK client and a set of ports.
|
||||
pub struct JackDevice {
|
||||
/// The active JACK client of this device.
|
||||
pub client: DynamicAsyncClient,
|
||||
/// The device state, encapsulated for sharing between threads.
|
||||
pub state: Arc<RwLock<Box<dyn Device>>>,
|
||||
/// Unowned copies of the device's JACK ports, for connecting to the device.
|
||||
/// The "real" readable/writable `Port`s are owned by the `state`.
|
||||
pub ports: UnownedJackPorts,
|
||||
}
|
||||
impl std::fmt::Debug for JackDevice {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("JackDevice").field("ports", &self.ports).finish()
|
||||
}
|
||||
}
|
||||
render!(JackDevice |self, buf, area| {
|
||||
self.state.read().unwrap().render(buf, area)
|
||||
});
|
||||
ports!(JackDevice {
|
||||
audio: {
|
||||
ins: |s|Ok(s.ports.audio_ins.values().collect()),
|
||||
outs: |s|Ok(s.ports.audio_outs.values().collect()),
|
||||
}
|
||||
midi: {
|
||||
ins: |s|Ok(s.ports.midi_ins.values().collect()),
|
||||
outs: |s|Ok(s.ports.midi_outs.values().collect()),
|
||||
}
|
||||
});
|
||||
impl JackDevice {
|
||||
/// Returns a locked mutex of the state's contents.
|
||||
pub fn state (&self) -> LockResult<RwLockReadGuard<Box<dyn Device>>> {
|
||||
self.state.read()
|
||||
}
|
||||
/// Returns a locked mutex of the state's contents.
|
||||
pub fn state_mut (&self) -> LockResult<RwLockWriteGuard<Box<dyn Device>>> {
|
||||
self.state.write()
|
||||
}
|
||||
pub fn connect_midi_in (&self, index: usize, port: &Port<Unowned>) -> Usually<()> {
|
||||
Ok(self.client.as_client().connect_ports(port, self.midi_ins()?[index])?)
|
||||
}
|
||||
pub fn connect_midi_out (&self, index: usize, port: &Port<Unowned>) -> Usually<()> {
|
||||
Ok(self.client.as_client().connect_ports(self.midi_outs()?[index], port)?)
|
||||
}
|
||||
pub fn connect_audio_in (&self, index: usize, port: &Port<Unowned>) -> Usually<()> {
|
||||
Ok(self.client.as_client().connect_ports(port, self.audio_ins()?[index])?)
|
||||
}
|
||||
pub fn connect_audio_out (&self, index: usize, port: &Port<Unowned>) -> Usually<()> {
|
||||
Ok(self.client.as_client().connect_ports(self.audio_outs()?[index], port)?)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue