refactors and cleanups

This commit is contained in:
🪞👃🪞 2024-07-10 21:53:38 +03:00
parent 78afaf9693
commit 6979fd67ec
8 changed files with 126 additions and 173 deletions

View file

@ -139,41 +139,3 @@ 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)
)?)
}