mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
refactor: jack proto-lib
This commit is contained in:
parent
4aadc712b8
commit
fe6ffea5df
12 changed files with 467 additions and 441 deletions
119
src/core/port.rs
119
src/core/port.rs
|
|
@ -1,119 +0,0 @@
|
|||
use crate::core::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct JackPorts {
|
||||
pub audio_ins: BTreeMap<String, Port<AudioIn>>,
|
||||
pub midi_ins: BTreeMap<String, Port<MidiIn>>,
|
||||
pub audio_outs: BTreeMap<String, Port<AudioOut>>,
|
||||
pub midi_outs: BTreeMap<String, Port<MidiOut>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UnownedJackPorts {
|
||||
pub audio_ins: BTreeMap<String, Port<::jack::Unowned>>,
|
||||
pub midi_ins: BTreeMap<String, Port<::jack::Unowned>>,
|
||||
pub audio_outs: BTreeMap<String, Port<::jack::Unowned>>,
|
||||
pub midi_outs: BTreeMap<String, Port<::jack::Unowned>>,
|
||||
}
|
||||
|
||||
impl JackPorts {
|
||||
pub fn clone_unowned (&self, client: &Client) -> UnownedJackPorts {
|
||||
let mut unowned = UnownedJackPorts::default();
|
||||
for (name, port) in self.midi_ins.iter() {
|
||||
unowned.midi_ins.insert(name.clone(), unsafe {
|
||||
Port::from_raw(::jack::Unowned, client.raw(), port.raw(), Arc::downgrade(&Arc::default()))
|
||||
});
|
||||
}
|
||||
for (name, port) in self.midi_outs.iter() {
|
||||
unowned.midi_outs.insert(name.clone(), unsafe {
|
||||
Port::from_raw(::jack::Unowned, client.raw(), port.raw(), Arc::downgrade(&Arc::default()))
|
||||
});
|
||||
}
|
||||
for (name, port) in self.audio_ins.iter() {
|
||||
unowned.audio_ins.insert(name.clone(), unsafe {
|
||||
Port::from_raw(::jack::Unowned, client.raw(), port.raw(), Arc::downgrade(&Arc::default()))
|
||||
});
|
||||
}
|
||||
for (name, port) in self.audio_outs.iter() {
|
||||
unowned.audio_outs.insert(name.clone(), unsafe {
|
||||
Port::from_raw(::jack::Unowned, client.raw(), port.raw(), Arc::downgrade(&Arc::default()))
|
||||
});
|
||||
}
|
||||
unowned
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for things that may expose JACK ports.
|
||||
pub trait Ports {
|
||||
fn audio_ins <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn audio_outs <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn midi_ins <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! ports {
|
||||
($T:ty $({ $(audio: {
|
||||
$(ins: |$ai_arg:ident|$ai_impl:expr,)?
|
||||
$(outs: |$ao_arg:ident|$ao_impl:expr,)?
|
||||
})? $(midi: {
|
||||
$(ins: |$mi_arg:ident|$mi_impl:expr,)?
|
||||
$(outs: |$mo_arg:ident|$mo_impl:expr,)?
|
||||
})?})?) => {
|
||||
impl Ports for $T {$(
|
||||
$(
|
||||
$(fn audio_ins <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
let cb = |$ai_arg:&'a Self|$ai_impl;
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
$(
|
||||
$(fn audio_outs <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
let cb = (|$ao_arg:&'a Self|$ao_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
)? $(
|
||||
$(
|
||||
$(fn midi_ins <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
let cb = (|$mi_arg:&'a Self|$mi_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
$(
|
||||
$(fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
let cb = (|$mo_arg:&'a Self|$mo_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
)?}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
pub struct DevicePort<T: PortSpec> {
|
||||
pub name: String,
|
||||
pub port: Port<T>,
|
||||
pub connect: Vec<String>,
|
||||
}
|
||||
|
||||
impl<T: PortSpec + Default> DevicePort<T> {
|
||||
pub fn new (client: &Client, name: &str, connect: &[&str]) -> Usually<Self> {
|
||||
let mut connects = vec![];
|
||||
for port in connect.iter() {
|
||||
connects.push(port.to_string());
|
||||
}
|
||||
Ok(Self {
|
||||
name: name.to_string(),
|
||||
port: client.register_port(name, T::default())?,
|
||||
connect: connects,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue