mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +01:00
ports macro
This commit is contained in:
parent
2067004d4a
commit
e86be4facc
10 changed files with 104 additions and 102 deletions
|
|
@ -5,14 +5,14 @@ pub trait Component: Render + Handle {}
|
|||
impl<T: Render + Handle> Component for T {}
|
||||
|
||||
/// A UI component that may have presence on the JACK grap.
|
||||
pub trait Device: Render + Handle + PortList + Send + Sync {
|
||||
pub trait Device: Render + Handle + Ports + Send + Sync {
|
||||
fn boxed (self) -> Box<dyn Device> where Self: Sized + 'static {
|
||||
Box::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// All things that implement the required traits can be treated as `Device`.
|
||||
impl<T: Render + Handle + PortList + Send + Sync> Device for T {}
|
||||
impl<T: Render + Handle + Ports + Send + Sync> Device for T {}
|
||||
|
||||
/// A device dynamicammy composed of state and handlers.
|
||||
pub struct DynamicDevice<T> {
|
||||
|
|
@ -35,20 +35,7 @@ impl<T: Send> Render for DynamicDevice<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: PortList + Send + Sync + 'static> PortList for DynamicDevice<T> {
|
||||
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||
self.state().audio_ins()
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
self.state().audio_outs()
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
self.state().midi_ins()
|
||||
}
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
self.state().midi_outs()
|
||||
}
|
||||
}
|
||||
impl<T: Ports + Send + Sync + 'static> Ports for DynamicDevice<T> {}
|
||||
|
||||
impl<T: Send + Sync + 'static> DynamicDevice<T> {
|
||||
pub fn new <'a, R, H, P> (render: R, handle: H, process: P, state: T) -> Self where
|
||||
|
|
|
|||
|
|
@ -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