pub type Usually = Result>; pub use crate::draw::*; pub use crate::device::{ Device, DynamicDevice, AppEvent, }; pub use crate::time::*; pub use crate::layout::{ Rows, Columns }; 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 KeyBinding = ( KeyCode, KeyModifiers, &'static str, &'static str, &'static dyn Fn(&mut T) ); #[macro_export] macro_rules! key { ($k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: ident) => { (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: ident]),* }) => { &[ $((KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f as &'static dyn Fn(&mut $T))),* ] as &'static [KeyBinding<$T>] } } pub use crate::{key, keymap}; pub fn handle_keymap ( commands: &[KeyBinding], state: &mut T, event: &AppEvent ) -> Result> { match event { AppEvent::Input(Event::Key(event)) => { for (code, modifiers, _, _, command) in commands.iter() { if *code == event.code && modifiers.bits() == event.modifiers.bits() { command(state); return Ok(true) } } }, _ => {} }; Ok(false) }