tek/engine/jack_structs.rs
stop screaming 37068784cb refactor(engine): flatten
- add `just stats`
- add basic doctests
2026-02-21 00:03:06 +02:00

53 lines
1.4 KiB
Rust

use crate::*;
/// Wraps [JackState], and through it [jack::Client] when connected.
///
/// ```
/// let jack: tek_engine::Jack = Default::default();
/// ```
#[derive(Clone, Debug, Default)]
pub struct Jack<'j> (pub(crate) Arc<RwLock<JackState<'j>>>);
/// This is a connection which may be [Inactive], [Activating], or [Active].
/// In the [Active] and [Inactive] states, [JackState::client] returns a
/// [jack::Client], which you can use to talk to the JACK API.
///
/// ```
/// let state: tek_engine::JackState = Default::default();
/// ```
#[derive(Debug, Default)]
pub enum JackState<'j> {
/// Unused
#[default] Inert,
/// Before activation.
Inactive(Client),
/// During activation.
Activating,
/// After activation. Must not be dropped for JACK thread to persist.
Active(DynamicAsyncClient<'j>),
}
/// Event enum for JACK events.
///
/// ```
/// let event: tek_engine::JackState = JackEvent::XRun;
/// ```
#[derive(Debug, Clone, PartialEq)] pub enum JackEvent {
ThreadInit,
Shutdown(ClientStatus, Arc<str>),
Freewheel(bool),
SampleRate(Frames),
ClientRegistration(Arc<str>, bool),
PortRegistration(PortId, bool),
PortRename(PortId, Arc<str>, Arc<str>),
PortsConnected(PortId, PortId, bool),
GraphReorder,
XRun,
}
/// Generic notification handler that emits [JackEvent]
///
/// ```
/// let notify = tek_engine::JackNotify(|_: JackEvent|{});
/// ```
pub struct JackNotify<T: Fn(JackEvent) + Send>(pub T);