mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
ports macro
This commit is contained in:
parent
2067004d4a
commit
e86be4facc
10 changed files with 104 additions and 102 deletions
|
|
@ -1,32 +1,58 @@
|
|||
use crate::core::*;
|
||||
|
||||
/// Trait for things that may expose JACK ports.
|
||||
pub trait PortList {
|
||||
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||
pub trait Ports {
|
||||
fn audio_ins (&self) -> Usually<Vec<&Port<AudioIn>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
fn audio_outs (&self) -> Usually<Vec<&Port<AudioOut>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
fn midi_ins <'a> (&'a self) -> Usually<Vec<&'a Port<MidiIn>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<MidiOut>>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn connect (&mut self, _connect: bool, _source: &str, _target: &str)
|
||||
-> Usually<()>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
fn connect_all (&mut self, connections: &[(bool, &str, &str)])
|
||||
-> Usually<()>
|
||||
{
|
||||
for (connect, source, target) in connections.iter() {
|
||||
self.connect(*connect, source, target)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[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<AudioIn>>> {
|
||||
let cb = |$ai_arg:&'a Self|$ai_impl;
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
$(
|
||||
$(fn audio_outs <'a> (&'a self) -> Usually<Vec<&'a Port<AudioOut>>> {
|
||||
let cb = (|$ao_arg:&'a Self|$ao_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
)? $(
|
||||
$(
|
||||
$(fn midi_ins <'a> (&'a self) -> Usually<Vec<&'a Port<MidiIn>>> {
|
||||
let cb = (|$mi_arg:&'a Self|$mi_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
$(
|
||||
$(fn midi_outs <'a> (&'a self) -> Usually<Vec<&'a Port<MidiOut>>> {
|
||||
let cb = (|$mo_arg:&'a Self|$mo_impl);
|
||||
cb(self)
|
||||
})?
|
||||
)?
|
||||
)?}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
pub struct DevicePort<T: PortSpec> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue