mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
99 lines
3.4 KiB
Rust
99 lines
3.4 KiB
Rust
use super::*;
|
|
|
|
#[derive(Default)]
|
|
pub struct JackPorts {
|
|
lifesaver: Arc<()>,
|
|
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(&self.lifesaver))
|
|
});
|
|
}
|
|
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(&self.lifesaver))
|
|
});
|
|
}
|
|
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(&self.lifesaver))
|
|
});
|
|
}
|
|
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(&self.lifesaver))
|
|
});
|
|
}
|
|
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)
|
|
})?
|
|
)?
|
|
)?}
|
|
};
|
|
}
|