pub type Usually = Result>; pub use crate::draw::*; pub use crate::device::*; pub use crate::time::*; pub use crate::port::*; pub use crate::layout::*; pub use std::error::Error; pub use std::io::{stdout, Stdout, Write}; pub use std::thread::{spawn, JoinHandle}; pub use std::time::Duration; pub use std::sync::{ Arc, Mutex, atomic::{ Ordering, AtomicBool, AtomicUsize }, mpsc::{self, channel, Sender, Receiver} }; pub use crossterm::{ ExecutableCommand, QueueableCommand, event::{Event, KeyEvent, KeyCode, KeyModifiers}, terminal::{ self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen, enable_raw_mode, disable_raw_mode }, }; pub use ratatui::{ prelude::{ Buffer, Rect, Style, Color, CrosstermBackend, Layout, Stylize, Direction, Line, Constraint }, widgets::{Widget, WidgetRef}, //style::Stylize, }; pub use jack::{ AsyncClient, AudioIn, AudioOut, Client, ClientOptions, ClientStatus, ClosureProcessHandler, Control, Frames, MidiIn, MidiOut, NotificationHandler, Port, PortId, ProcessHandler, ProcessScope, RawMidi, Transport, TransportState, TransportStatePosition }; pub type BoxedNotificationHandler = Box; pub type BoxedProcessHandler = Box Control + Send>; pub type Jack = AsyncClient>; pub type KeyHandler = &'static dyn Fn(&mut T)->Usually; pub type KeyBinding = ( KeyCode, KeyModifiers, &'static str, &'static str, KeyHandler ); #[macro_export] macro_rules! key { ($k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: expr) => { (KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f) }; } #[macro_export] macro_rules! keymap { ($T:ty { $([$k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: expr]),* $(,)? }) => { &[ $((KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f as KeyHandler<$T>)),* ] as &'static [KeyBinding<$T>] } } pub use crate::{key, keymap}; pub fn handle_keymap ( state: &mut T, event: &AppEvent, keymap: &[KeyBinding], ) -> Usually { match event { AppEvent::Input(Event::Key(event)) => { for (code, modifiers, _, _, command) in keymap.iter() { if *code == event.code && modifiers.bits() == event.modifiers.bits() { return command(state) } } }, _ => {} }; Ok(false) }