move the jack stuff from tek into tengri

This commit is contained in:
same mf who else 2026-02-23 21:21:03 +02:00
parent 5d0dc40fdc
commit c1b727bafc
11 changed files with 3006 additions and 1494 deletions

View file

@ -181,14 +181,14 @@ pub use self::spatial::*; mod spatial {
/// Set the maximum width and/or height of the content.
///
/// ```
/// let maximum = tengri::Min::XY(3, 5, "Hello"); // 3x1
/// let maximum = tengri::Max::XY(3, 5, "Hello"); // 3x1
/// ```
pub enum Max<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Set the minimum width and/or height of the content.
///
/// ```
/// let minimam = tengri::Min::XY(3, 5, "Hello"); // 5x5
/// let minimum = tengri::Min::XY(3, 5, "Hello"); // 5x5
/// ```
pub enum Min<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
@ -269,11 +269,10 @@ pub use self::spatial::*; mod spatial {
pub __: PhantomData<(O, B)>,
}
/// A color in OKHSL and RGB representations.
#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct ItemColor {
pub okhsl: Okhsl<f32>,
pub rgb: Color,
#[cfg(feature = "tui")] pub rgb: Color,
}
/// A color in OKHSL and RGB with lighter and darker variants.
#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct ItemTheme {
@ -285,9 +284,26 @@ pub use self::spatial::*; mod spatial {
pub darker: ItemColor,
pub darkest: ItemColor,
}
// TODO DOCUMENTME
pub struct FieldH<Theme, Label, Value>(pub Theme, pub Label, pub Value);
// TODO DOCUMENTME
pub struct FieldV<Theme, Label, Value>(pub Theme, pub Label, pub Value);
// TODO:
pub struct Field<C, T, U> {
pub direction: Direction,
pub label: Option<T>,
pub label_fg: Option<C>,
pub label_bg: Option<C>,
pub label_align: Option<Direction>,
pub value: Option<U>,
pub value_fg: Option<C>,
pub value_bg: Option<C>,
pub value_align: Option<Direction>,
}
}
pub use self::terminal::*; mod terminal {
#[cfg(feature = "tui")] pub use self::terminal::*;
#[cfg(feature = "tui")] mod terminal {
use crate::*;
/// The TUI engine.
@ -354,16 +370,6 @@ pub use self::terminal::*; mod terminal {
pub struct Styled<T>(pub Option<Style>, pub T);
/// Displays an owned [str]-like with fixed maximum width.
///
/// Width is computed using [unicode_width].
pub struct TrimString<T: AsRef<str>>(pub u16, pub T);
/// Displays a borrowed [str]-like with fixed maximum width
///
/// Width is computed using [unicode_width].
pub struct TrimStringRef<'a, T: AsRef<str>>(pub u16, pub &'a T);
/// A cell that takes up 3 rows on its own,
/// but stacks, giving (N+1)*2 rows per N cells.
pub struct Phat<T> {
@ -382,25 +388,6 @@ pub use self::terminal::*; mod terminal {
pub right: (u16, C),
}
// TODO:
pub struct Field<C, T, U> {
pub direction: Direction,
pub label: Option<T>,
pub label_fg: Option<C>,
pub label_bg: Option<C>,
pub label_align: Option<Direction>,
pub value: Option<U>,
pub value_fg: Option<C>,
pub value_bg: Option<C>,
pub value_align: Option<Direction>,
}
// TODO DOCUMENTME
pub struct FieldH<Theme, Label, Value>(pub Theme, pub Label, pub Value);
// TODO DOCUMENTME
pub struct FieldV<Theme, Label, Value>(pub Theme, pub Label, pub Value);
/// Repeat a string, e.g. for background
pub enum Repeat<'a> {
X(&'a str),
@ -416,3 +403,99 @@ pub use self::terminal::*; mod terminal {
Y { offset: usize, length: usize, total: usize, }
}
}
pub use self::textual::*;
mod textual {
/// Displays an owned [str]-like with fixed maximum width.
///
/// Width is computed using [unicode_width].
pub struct TrimString<T: AsRef<str>>(pub u16, pub T);
/// Displays a borrowed [str]-like with fixed maximum width
///
/// Width is computed using [unicode_width].
pub struct TrimStringRef<'a, T: AsRef<str>>(pub u16, pub &'a T);
}
#[cfg(feature = "jack")] pub use self::aural::*;
#[cfg(feature = "jack")] mod aural {
use crate::*;
use ::jack::*;
/// Wraps [JackState], and through it [jack::Client] when connected.
///
/// ```
/// let jack = tengri::Jack::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 = tengri::JackState::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 = tengri::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 = tengri::JackNotify(|_|{});
/// ```
pub struct JackNotify<T: Fn(JackEvent) + Send>(pub T);
/// Running JACK [AsyncClient] with maximum type erasure.
///
/// One [Box] contains function that handles [JackEvent]s.
///
/// Another [Box] containing a function that handles realtime IO.
///
/// That's all it knows about them.
pub type DynamicAsyncClient<'j>
= AsyncClient<DynamicNotifications<'j>, DynamicAudioHandler<'j>>;
/// Notification handler wrapper for [BoxedAudioHandler].
pub type DynamicAudioHandler<'j> =
::jack::contrib::ClosureProcessHandler<(), BoxedAudioHandler<'j>>;
/// Boxed realtime callback.
pub type BoxedAudioHandler<'j> =
Box<dyn FnMut(&Client, &ProcessScope) -> Control + Send + Sync + 'j>;
/// Notification handler wrapper for [BoxedJackEventHandler].
pub type DynamicNotifications<'j> =
JackNotify<BoxedJackEventHandler<'j>>;
/// Boxed [JackEvent] callback.
pub type BoxedJackEventHandler<'j> =
Box<dyn Fn(JackEvent) + Send + Sync + 'j>;
}