mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
use iterator in sampler
This commit is contained in:
parent
81717f17b8
commit
c5369328f4
9 changed files with 175 additions and 120 deletions
89
src/jack.rs
89
src/jack.rs
|
|
@ -1,18 +1,6 @@
|
|||
use crate::core::*;
|
||||
|
||||
submod!( device event factory ports process );
|
||||
|
||||
pub type DynamicAsyncClient =
|
||||
AsyncClient<DynamicNotifications, DynamicProcessHandler>;
|
||||
|
||||
pub type DynamicNotifications =
|
||||
Notifications<Box<dyn Fn(AppEvent) + Send + Sync>>;
|
||||
|
||||
pub type DynamicProcessHandler =
|
||||
ClosureProcessHandler<BoxedProcessHandler>;
|
||||
|
||||
pub type BoxedProcessHandler =
|
||||
Box<dyn FnMut(&Client, &ProcessScope)-> Control + Send>;
|
||||
submod!( device event factory ports );
|
||||
|
||||
pub use ::_jack::{
|
||||
AsyncClient,
|
||||
|
|
@ -42,6 +30,43 @@ pub use ::_jack::{
|
|||
Unowned
|
||||
};
|
||||
|
||||
pub type DynamicAsyncClient =
|
||||
AsyncClient<DynamicNotifications, DynamicProcessHandler>;
|
||||
|
||||
type DynamicProcessHandler =
|
||||
ClosureProcessHandler<BoxedProcessHandler>;
|
||||
|
||||
pub type BoxedProcessHandler =
|
||||
Box<dyn FnMut(&Client, &ProcessScope)-> Control + Send>;
|
||||
|
||||
/// Trait for things that have a JACK process callback.
|
||||
pub trait Process {
|
||||
fn process (&mut self, _: &Client, _: &ProcessScope) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
|
||||
/// Define the JACK process callback associated with a struct.
|
||||
#[macro_export] macro_rules! process {
|
||||
($T:ty) => {
|
||||
impl Process for $T {}
|
||||
};
|
||||
($T:ty |$self:ident, $c:ident, $s:ident|$block:tt) => {
|
||||
impl Process for $T {
|
||||
fn process (&mut $self, $c: &Client, $s: &ProcessScope) -> Control {
|
||||
$block
|
||||
}
|
||||
}
|
||||
};
|
||||
($T:ty = $process:path) => {
|
||||
impl Process for $T {
|
||||
fn process (&mut self, c: &Client, s: &ProcessScope) -> Control {
|
||||
$process(self, c, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Just run thing with JACK. Returns the activated client.
|
||||
pub fn jack_run <T: Sync> (name: &str, app: &Arc<RwLock<T>>) -> Usually<DynamicAsyncClient>
|
||||
where T: Handle + Process + Send + 'static
|
||||
|
|
@ -65,3 +90,41 @@ pub fn jack_run <T: Sync> (name: &str, app: &Arc<RwLock<T>>) -> Usually<DynamicA
|
|||
}) as BoxedProcessHandler)
|
||||
)?)
|
||||
}
|
||||
|
||||
pub trait ProcessSplit {
|
||||
fn process_in (&mut self, _: &Client, _: &ProcessScope) -> Usually<()>;
|
||||
fn process_out (&self, _: &Client, _: &ProcessScope) -> Usually<()>;
|
||||
}
|
||||
|
||||
impl<T: ProcessSplit> Process for T {
|
||||
fn process (&mut self, c: &Client, s: &ProcessScope) -> Control {
|
||||
self.process_in(c, s).unwrap();
|
||||
self.process_out(c, s).unwrap();
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
|
||||
/// Just run thing with JACK. Returns the activated client.
|
||||
pub fn jack_run_split <T: Sync> (name: &str, app: &Arc<RwLock<T>>) -> Usually<DynamicAsyncClient>
|
||||
where T: Handle + ProcessSplit + Send + 'static
|
||||
{
|
||||
let options = ClientOptions::NO_START_SERVER;
|
||||
let (client, _status) = Client::new(name, options)?;
|
||||
Ok(client.activate_async(
|
||||
Notifications(Box::new({
|
||||
let _app = app.clone();
|
||||
move|_event|{
|
||||
// FIXME: this deadlocks
|
||||
//app.lock().unwrap().handle(&event).unwrap();
|
||||
}
|
||||
}) as Box<dyn Fn(AppEvent) + Send + Sync>),
|
||||
ClosureProcessHandler::new(Box::new({
|
||||
let app = app.clone();
|
||||
move|c: &Client, s: &ProcessScope|{
|
||||
app.write().unwrap().process_in(c, s).unwrap();
|
||||
app.read().unwrap().process_out(c, s).unwrap();
|
||||
Control::Continue
|
||||
}
|
||||
}) as BoxedProcessHandler)
|
||||
)?)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue