mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
clone ports as unowned and pass outwards
This commit is contained in:
parent
394355331d
commit
ddaf870271
9 changed files with 123 additions and 112 deletions
|
|
@ -1,17 +1,60 @@
|
|||
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<AudioIn>>> {
|
||||
fn audio_ins <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn audio_outs <'a> (&'a self) -> Usually<Vec<&'a Port<AudioOut>>> {
|
||||
fn audio_outs <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn midi_ins <'a> (&'a self) -> Usually<Vec<&'a Port<MidiIn>>> {
|
||||
fn midi_ins <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<MidiOut>>> {
|
||||
fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
|
|
@ -26,26 +69,26 @@ pub trait Ports {
|
|||
})?})?) => {
|
||||
impl Ports for $T {$(
|
||||
$(
|
||||
$(fn audio_ins <'a> (&'a self) -> Usually<Vec<&'a Port<AudioIn>>> {
|
||||
$(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<AudioOut>>> {
|
||||
$(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<MidiIn>>> {
|
||||
$(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<MidiOut>>> {
|
||||
$(fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<Unowned>>> {
|
||||
let cb = (|$mo_arg:&'a Self|$mo_impl);
|
||||
cb(self)
|
||||
})?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue