mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
refactor app/jack init
This commit is contained in:
parent
117f4d5363
commit
23d9910399
7 changed files with 166 additions and 80 deletions
49
src/jack.rs
49
src/jack.rs
|
|
@ -30,6 +30,55 @@ pub use ::_jack::{
|
|||
Unowned
|
||||
};
|
||||
|
||||
pub enum JackClient {
|
||||
Inactive(Client),
|
||||
Active(DynamicAsyncClient),
|
||||
}
|
||||
|
||||
impl JackClient {
|
||||
pub fn client (&self) -> &Client {
|
||||
match self {
|
||||
Self::Inactive(ref client) =>
|
||||
client,
|
||||
Self::Active(ref client) =>
|
||||
client.as_client(),
|
||||
}
|
||||
}
|
||||
pub fn transport (&self) -> Transport {
|
||||
match self {
|
||||
Self::Inactive(client) =>
|
||||
client.transport(),
|
||||
Self::Active(client) =>
|
||||
client.as_client().transport(),
|
||||
}
|
||||
}
|
||||
fn register_port <PS: PortSpec> (&self, name: &str, spec: PS) -> Usually<Port<PS>> {
|
||||
Ok(match self {
|
||||
Self::Inactive(client) =>
|
||||
client.register_port(name, spec)?,
|
||||
Self::Active(client) =>
|
||||
client.as_client().register_port(name, spec)?,
|
||||
})
|
||||
}
|
||||
pub fn activate <T: Send + Sync + 'static> (
|
||||
self,
|
||||
state: &Arc<RwLock<T>>,
|
||||
mut process: impl FnMut(&Arc<RwLock<T>>, &Client, &ProcessScope)->Control + Send + 'static
|
||||
) -> Usually<Self> {
|
||||
Ok(match self {
|
||||
Self::Active(_) => self,
|
||||
Self::Inactive(client) => Self::Active(client.activate_async(
|
||||
Notifications(Box::new(move|_|{/*TODO*/})
|
||||
as Box<dyn Fn(AppEvent) + Send + Sync>),
|
||||
ClosureProcessHandler::new(Box::new({
|
||||
let state = state.clone();
|
||||
move|c: &Client, s: &ProcessScope|process(&state, c, s)
|
||||
}) as BoxedProcessHandler)
|
||||
)?)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub type DynamicAsyncClient =
|
||||
AsyncClient<DynamicNotifications, DynamicProcessHandler>;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue