mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: configuring keybinds with edn... oh my
This commit is contained in:
parent
f1bd9e7e88
commit
1f10c95ed0
6 changed files with 73 additions and 35 deletions
22
midi/src/midi_keys.edn
Normal file
22
midi/src/midi_keys.edn
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(@up (note/cursor/inc))
|
||||
(@down (note/cursor/dec))
|
||||
(@left (time/cursor/dec))
|
||||
(@right (time/cursor/inc))
|
||||
(@z (time/zoom/lock))
|
||||
(@= (time/zoom/in))
|
||||
(@- (time/zoom/out))
|
||||
(@+ (note/scale/inc))
|
||||
(@- (note/scale/dec))
|
||||
(@enter (note/put))
|
||||
(@del (note/del))
|
||||
(@, (note/duration/dec))
|
||||
(@. (note/duration/inc))
|
||||
|
||||
;(@ctrl-k (midi/kbd/toggle))
|
||||
;(@space (clock/toggle))
|
||||
;(@shift-space (clock/toggle-start))
|
||||
;(@u (undo))
|
||||
;(@shift-u (redo))
|
||||
;(@tab (compact/toggle))
|
||||
;(@q (player/enqueue :clip))
|
||||
;(@0 (player/enqueue :stop)))
|
||||
|
|
@ -2,10 +2,10 @@ use crate::*;
|
|||
use std::marker::PhantomData;
|
||||
use EdnItem::*;
|
||||
|
||||
pub type EdnCallback<'a, O: Output, State> =
|
||||
pub type EdnCallback<'a, O, State> =
|
||||
dyn Fn(&'a State)-> RenderBox<'a, O> + Send + Sync + 'a;
|
||||
|
||||
pub type EdnRenderCallback<'a, O: Output, State> =
|
||||
pub type EdnRenderCallback<'a, O, State> =
|
||||
Box<EdnCallback<'a, O, State>>;
|
||||
|
||||
/// Provides values to the template
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ impl App {
|
|||
}
|
||||
render!(TuiOut: (self: App) => self.size.of(EdnView::from_source(self, self.edn.as_ref())));
|
||||
audio!(|self: App, _client, _scope|Control::Continue);
|
||||
handle!(TuiIn: |self: App, input| Ok(None));
|
||||
impl EdnViewData<TuiOut> for &App {
|
||||
fn get_content <'a> (&'a self, item: EdnItem<&'a str>) -> RenderBox<'a, TuiOut> {
|
||||
use EdnItem::*;
|
||||
|
|
@ -318,26 +317,6 @@ fn output_cells <'a> (state: &'a App) -> BoxThunk<'a, TuiOut> {
|
|||
))))
|
||||
})).boxed()).into()
|
||||
}
|
||||
fn rec_mon (bg: Color, rec: bool, mon: bool) -> impl Content<TuiOut> {
|
||||
row!(
|
||||
Tui::fg_bg(if rec { Color::Red } else { bg }, bg, "▐"),
|
||||
Tui::fg_bg(if rec { Color::White } else { Color::Rgb(0,0,0) }, bg, "REC"),
|
||||
Tui::fg_bg(if rec { Color::White } else { bg }, bg, "▐"),
|
||||
Tui::fg_bg(if mon { Color::White } else { Color::Rgb(0,0,0) }, bg, "MON"),
|
||||
Tui::fg_bg(if mon { Color::White } else { bg }, bg, "▌"),
|
||||
)
|
||||
}
|
||||
fn mute_solo (bg: Color, mute: bool, solo: bool) -> impl Content<TuiOut> {
|
||||
row!(
|
||||
Tui::fg_bg(if mute { Color::White } else { Color::Rgb(0,0,0) }, bg, "MUTE"),
|
||||
Tui::fg_bg(if mute { Color::White } else { bg }, bg, "▐"),
|
||||
Tui::fg_bg(if solo { Color::White } else { Color::Rgb(0,0,0) }, bg, "SOLO"),
|
||||
)
|
||||
}
|
||||
fn cell <T: Content<TuiOut>> (color: ItemPalette, field: T) -> impl Content<TuiOut> {
|
||||
Tui::fg_bg(color.lightest.rgb, color.base.rgb, Fixed::y(1, field))
|
||||
}
|
||||
|
||||
fn scene_headers <'a> (state: &'a App) -> BoxThunk<'a, TuiOut> {
|
||||
(||{
|
||||
let last_color = Arc::new(RwLock::new(ItemPalette::from(Color::Rgb(0, 0, 0))));
|
||||
|
|
@ -426,3 +405,24 @@ fn cell_clip <'a> (
|
|||
Fixed::xy(w, h, &Tui::bg(bg, Push::x(1, Fixed::x(w, &name.as_str()[0..max_w]))));
|
||||
}))
|
||||
}
|
||||
fn rec_mon (bg: Color, rec: bool, mon: bool) -> impl Content<TuiOut> {
|
||||
row!(
|
||||
Tui::fg_bg(if rec { Color::Red } else { bg }, bg, "▐"),
|
||||
Tui::fg_bg(if rec { Color::White } else { Color::Rgb(0,0,0) }, bg, "REC"),
|
||||
Tui::fg_bg(if rec { Color::White } else { bg }, bg, "▐"),
|
||||
Tui::fg_bg(if mon { Color::White } else { Color::Rgb(0,0,0) }, bg, "MON"),
|
||||
Tui::fg_bg(if mon { Color::White } else { bg }, bg, "▌"),
|
||||
)
|
||||
}
|
||||
fn mute_solo (bg: Color, mute: bool, solo: bool) -> impl Content<TuiOut> {
|
||||
row!(
|
||||
Tui::fg_bg(if mute { Color::White } else { Color::Rgb(0,0,0) }, bg, "MUTE"),
|
||||
Tui::fg_bg(if mute { Color::White } else { bg }, bg, "▐"),
|
||||
Tui::fg_bg(if solo { Color::White } else { Color::Rgb(0,0,0) }, bg, "SOLO"),
|
||||
)
|
||||
}
|
||||
fn cell <T: Content<TuiOut>> (color: ItemPalette, field: T) -> impl Content<TuiOut> {
|
||||
Tui::fg_bg(color.lightest.rgb, color.base.rgb, Fixed::y(1, field))
|
||||
}
|
||||
|
||||
handle!(TuiIn: |self: App, input| Ok(None));
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ mod tui_field; pub use self::tui_field::*;
|
|||
mod tui_buffer; pub use self::tui_buffer::*;
|
||||
mod tui_file; pub use self::tui_file::*;
|
||||
|
||||
mod tui_edn_keymap; pub use self::tui_edn_keymap::*;
|
||||
|
||||
pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicUsize, AtomicBool, Ordering::*}};
|
||||
pub(crate) use std::io::{stdout, Stdout};
|
||||
pub(crate) use std::error::Error;
|
||||
|
|
|
|||
26
tui/src/tui_edn_keymap.rs
Normal file
26
tui/src/tui_edn_keymap.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use crate::*;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub trait EdnControlData<E: Input> {}
|
||||
|
||||
/// Renders from EDN source and context.
|
||||
#[derive(Default)]
|
||||
pub enum EdnControls<E: Input, T: EdnControlData<E>> {
|
||||
#[default]
|
||||
Inert,
|
||||
_Unused(PhantomData<E>),
|
||||
Ok(T, EdnItem<String>),
|
||||
Err(String)
|
||||
}
|
||||
|
||||
impl<E: Input, T: EdnControlData<E>> EdnControls<E, T> {
|
||||
pub fn from_source (state: T, source: &str) -> Self {
|
||||
match EdnItem::read_one(&source) {
|
||||
Ok((layout, _)) => Self::Ok(state, layout),
|
||||
Err(error) => Self::Err(format!("{error}"))
|
||||
}
|
||||
}
|
||||
pub fn from_items (state: T, items: &[EdnItem<&str>]) -> Self {
|
||||
Self::Ok(state, EdnItem::Exp(items.iter().map(|i|(*i).clone()).collect()))
|
||||
}
|
||||
}
|
||||
|
|
@ -68,15 +68,3 @@ impl TuiOut {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut Cell, u16, u16)) {
|
||||
for row in 0..area.h() {
|
||||
let y = area.y() + row;
|
||||
for col in 0..area.w() {
|
||||
let x = area.x() + col;
|
||||
if x < buf.area.width && y < buf.area.height {
|
||||
callback(buf.get_mut(x, y), col, row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue