Compare commits

..

No commits in common. "8de62463c08cecda9d5f469a38390a2f36fe3c50" and "ba8ff1ae69a0110fc4a457d58c9a504b816d8194" have entirely different histories.

7 changed files with 34 additions and 76 deletions

View file

@ -131,7 +131,7 @@ impl MidiEditor {
}
/// ```
/// use tek::{*, tengri::*};
/// use tek::{*, tengri::{*, lang::*}};
///
/// struct Test(Option<MidiEditor>);
/// impl_as_ref_opt!(MidiEditor: |self: Test|self.0.as_ref());

View file

@ -137,7 +137,7 @@ impl PianoHorizontal {
let note_lo = self.get_note_lo();
let note_hi = self.get_note_hi();
let buffer = self.buffer.clone();
draw(move|to: &mut Tui|{
thunk(move|to: &mut Tui|{
let xywh = to.area().into();
let XYWH(x0, y0, w, _h) = xywh;
let source = buffer.read().unwrap();
@ -175,7 +175,7 @@ impl PianoHorizontal {
let time_start = self.get_time_start();
let time_zoom = self.get_time_zoom();
let style = Some(Style::default().fg(self.color.lightest.term));
draw(move|to: &mut Tui|{
thunk(move|to: &mut Tui|{
let xywh = to.area().into();
let XYWH(x0, y0, w, _h) = xywh;
for (_area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {
@ -209,7 +209,7 @@ impl PianoHorizontal {
let key_style = Some(Style::default().fg(Rgb(192, 192, 192)).bg(Rgb(0, 0, 0)));
let off_style = Some(Style::default().fg(g(255)));
let on_style = Some(Style::default().fg(Rgb(255,0,0)).bg(color.base.term).bold());
draw(move|to: &mut Tui|{
thunk(move|to: &mut Tui|{
let xywh = to.area().into();
let XYWH(x, y0, _w, _h) = xywh;
for (_area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {
@ -228,7 +228,7 @@ impl PianoHorizontal {
}
fn timeline (&self) -> impl Draw<Tui> + '_ {
draw(move|to: &mut Tui|{
thunk(move|to: &mut Tui|{
let xywh = to.area().into();
let XYWH(x, y, w, _h) = xywh;
let style = Some(Style::default().dim());

View file

@ -141,7 +141,7 @@ impl ApplicationHandler for LV2PluginUI {
}
impl Draw<Tui> for Lv2 {
fn draw (&self, to: &mut Tui) {
fn draw(self, to: &mut Tui) {
let area = to.area();
let XYWH(x, y, _, height) = area;
let mut width = 20u16;

View file

@ -257,7 +257,7 @@ fn draw_list_item (sample: &Option<Arc<RwLock<Sample>>>) -> String {
fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> {
let min_db = -64.0;
draw(move|to: &mut Tui|{
thunk(move|to: &mut Tui|{
let xywh = to.area().into();
let XYWH(x, y, width, height) = xywh;
let area = Rect { x, y, width, height };

View file

@ -13,8 +13,8 @@
:transport)
(mode :menu (name Menu) (info Mode selector.) (keys :axis/y :confirm)
(view (bg (g 16)
(bsp/s (fill/x (bg (g 32) (max/xy 80 2 :transport)))
(view (bg (g 64)
(bsp/s (max/xy 80 2 :transport)
(bsp/s (max/y 3 (bg (g 80) :ports/out))
(bsp/n (max/y 3 (bg (g 80) :ports/in))
(bg (g 30) (bsp/s (max/y 6 :logo) :dialog/menu))))))))

View file

@ -25,7 +25,7 @@ pub(crate) use ::{
},
tengri::{
*,
dizzle::*,
lang::*,
midly::{
Smf, TrackEventKind, MidiMessage, Error as MidiError,
num::*,
@ -451,11 +451,9 @@ mod app {
}
}
}
fn get_arc_str (&self, src: impl Language) -> Perhaps<Arc<str>> {
Ok(src.src()?.map(|x|x.into()))
}
fn get_u16 (&self, src: impl Language) -> Perhaps<u16> {
Ok(Some(match src.word()? {
Some(":w/sidebar") => self.project.w_sidebar(self.editor().is_some()),
@ -463,7 +461,6 @@ mod app {
_ => return try_to_u16(src)
}))
}
fn get_usize (&self, src: impl Language) -> Perhaps<usize> {
Ok(Some(match src.word()? {
Some(":scene-count") => self.scenes().len(),
@ -474,7 +471,6 @@ mod app {
_ => return try_to_usize(src)
}))
}
fn get_bool (&self, src: impl Language) -> Perhaps<bool> {
src.word()?.map(|word|Ok(match word {
"Y" => true,
@ -495,7 +491,6 @@ mod app {
_ => return Err(format!("not bool: {word}").into())
})).transpose()
}
fn get_selection (&self, src: impl Language) -> Perhaps<Selection> {
src.word()?.map(|word|Ok(match word {
":select/scene" => self.selection().select_scene(self.tracks().len()),
@ -507,7 +502,6 @@ mod app {
_ => return Err(format!("not selection: {word}").into())
})).transpose()
}
fn get_color (&self, src: impl Language) -> Perhaps<Color> {
if let Some(expr) = src.expr()? {
match (expr.head()?, expr.tail()?) {
@ -537,7 +531,6 @@ mod app {
return Err(format!("not a color: {:?}", src.src()?).into())
}
}
fn get_opt_u7 (&self, src: impl Language) -> Perhaps<Option<u7>> {
src.word()?.map(|word|Ok(match word {
":editor/pitch" => Some((
@ -546,11 +539,9 @@ mod app {
_ => return Err(format!("unknown midi note: {word}").into())
})).transpose()
}
fn get_opt_u16 (&self, _src: impl Language) -> Perhaps<Option<u16>> {
Ok(None)
}
fn get_opt_usize (&self, src: impl Language) -> Perhaps<Option<usize>> {
src.word()?.map(|word|Ok(match word {
":selected/scene" => self.selection().scene(),
@ -558,7 +549,6 @@ mod app {
_ => return Err(format!("unknown opt<usize>: {word}").into())
})).transpose()
}
fn get_clip (&self, src: impl Language) -> Perhaps<Option<Arc<RwLock<MidiClip>>>> {
src.word()?.map(|word|Ok(match word {
":selected/clip" if let Selection::TrackClip { track, scene } = self.selection() =>
@ -566,7 +556,6 @@ mod app {
_ => return Err(format!("not a clip: {word}").into())
})).transpose()
}
pub fn inc (&mut self, axis: &ControlAxis) -> Perhaps<AppCommand> {
Ok(match (&self.dialog, axis) {
(Dialog::None, _) => todo!(),
@ -575,7 +564,6 @@ mod app {
_ => todo!()
})
}
pub fn dec (&mut self, axis: &ControlAxis) -> Perhaps<AppCommand> {
Ok(match (&self.dialog, axis) {
(Dialog::None, _) => None,
@ -584,7 +572,6 @@ mod app {
_ => todo!()
})
}
pub fn confirm (&mut self) -> Perhaps<AppCommand> {
Ok(match &self.dialog {
Dialog::Menu(index, items) => {
@ -595,7 +582,6 @@ mod app {
_ => todo!(),
})
}
}
pub fn swap_value <T: Clone + PartialEq, U> (
@ -1047,26 +1033,6 @@ pub fn show_version () {
//})?)?
//}
/// Define an enum containing commands, and implement [Command] trait for over given `State`.
#[macro_export] macro_rules! def_command (
($Command:ident: |$state:ident: $State:ty| {
// FIXME: support attrs (docstrings)
$($Variant:ident$({$($arg:ident:$Arg:ty),+ $(,)?})?=>$body:expr),* $(,)?
})=>{
#[derive(Debug)] pub enum $Command {
// FIXME: support attrs (docstrings)
$($Variant $({ $($arg: $Arg),* })?),*
}
impl ::tengri::dizzle::Act<$State> for $Command {
fn act (&self, $state: &mut $State) -> Perhaps<Self> {
match self {
$(Self::$Variant $({ $($arg),* })? => $body,)*
_ => unimplemented!("Act<{}>: {self:?}", stringify!($State)),
}
}
}
});
pub use self::config::*;
mod config {
use crate::*;
@ -1452,11 +1418,12 @@ mod draw {
/// Then, every top-level form of the DSL description is rendered.
impl View<Tui> for App {
fn view (&self) -> impl Draw<Tui> {
draw(|to: &mut Tui|{
thunk(|to: &mut Tui|{
let xywh = to.area().into();
if let Some(e) = self.error.read().unwrap().as_ref() {
e.as_ref().align_c().draw(to)?;
//to.show(area(xywh, format!("KYPbanica {xywh:?}").align_c()))?;
to.show(e.as_ref().align_c())?;
}
if let Some(ref mode) = self.mode {
@ -1470,22 +1437,13 @@ mod draw {
}
}
ShowSize.align_se().draw(to)?;
to.show(ShowSize.align_se())?;
Ok(Some(xywh))
})
}
}
impl Keywords<Tui, XYWH<u16>> for App {
fn keywords () -> impl Iterator<Item = fn(&Self, &mut Tui, &str) -> Perhaps<XYWH<u16>>> {
[
kw_when, kw_either, kw_split, kw_align,
kw_exact, kw_fixed, kw_min, kw_max, kw_push
].into_iter()
}
}
impl Interpret<Tui, Option<XYWH<u16>>> for App {
fn interpret_expr <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression) -> Drawn<u16> {
tek_draw_expr(self, to, lang)
@ -1498,7 +1456,7 @@ mod draw {
fn tek_draw_expr (state: &App, to: &mut Tui, lang: &impl Expression) -> Drawn<u16> {
Ok(Some(if let Some(area) = eval_view(state, to, lang)? {
area
} else if let Some(area) = Tui::eval_view(state, to, lang)? {
} else if let Some(area) = eval_view_tui(state, to, lang)? {
area
} else {
return Err(format!("App::interpret_expr: unexpected: {lang:?}").into())
@ -1590,7 +1548,7 @@ mod draw {
Some("menu") => if let Dialog::Menu(selected, items) = &state.dialog {
let items = items.clone();
let selected = selected;
Some(draw(move|to: &mut Tui|{
Some(thunk(move|to: &mut Tui|{
for (index, MenuItem(item, _)) in items.0.iter().enumerate() {
let f = if *selected == index { Rgb(240,200,180) } else { Rgb(200, 200, 200) };
let b = if *selected == index { Rgb(80, 80, 50) } else { Rgb(30, 30, 30) };
@ -1608,7 +1566,7 @@ mod draw {
pub fn draw_templates (to: &mut Tui, _frags: std::str::Split<&str>, state: &App) -> Drawn<u16> {
let height = (state.config.modes.len() * 2) as u16;
draw(move |to: &mut Tui|{
thunk(move |to: &mut Tui|{
let mut index = 0;
state.config.modes.for_each(|id, profile| {
let b = if index == 0 { Rgb(70,70,70) } else { Rgb(50,50,50) };
@ -1662,7 +1620,7 @@ mod draw {
let h = 6;
let w = Some(30);
let f = Rgb(224, 192, 128);
draw(move |to: &mut Tui|{
thunk(move |to: &mut Tui|{
for (index, name) in ["session1", "session2", "session3"].iter().enumerate() {
let b = if index == 0 { Rgb(50,50,50) } else { Rgb(40,40,40) };
let y = (2 * index) as u16;
@ -1740,11 +1698,11 @@ mod draw {
pub fn button_play_pause (playing: bool, compact: bool) -> impl Draw<Tui> {
bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
either(compact,
draw(move|to: &mut Tui|either(playing,
thunk(move|to: &mut Tui|either(playing,
fg(Rgb(0, 255, 0), " PLAYING "),
fg(Rgb(255, 128, 0), " STOPPED "),
).exact_w(9).draw(to)),
draw(move|to: &mut Tui|either(playing,
thunk(move|to: &mut Tui|either(playing,
fg(Rgb(0, 255, 0), south(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
fg(Rgb(255, 128, 0), south(" ▗▄▖ ", " ▝▀▘ ",)),
).exact_w(5).draw(to)),
@ -1811,7 +1769,7 @@ mod draw {
}
pub fn view_sample_info (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> {
when(sample.is_some(), draw(move|to: &mut Tui|{
when(sample.is_some(), thunk(move|to: &mut Tui|{
let sample = sample.unwrap().read().unwrap();
let theme = sample.color;
east!(
@ -1826,7 +1784,7 @@ mod draw {
}
pub fn view_sample_info_v (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> {
let a = draw(move|to: &mut Tui|{
let a = thunk(move|to: &mut Tui|{
let sample = sample.unwrap().read().unwrap();
let theme = sample.color;
south!(
@ -1839,7 +1797,7 @@ mod draw {
).exact_w(20).draw(to)
});
let b = draw(|to: &mut Tui|fg(Red, south!(
let b = thunk(|to: &mut Tui|fg(Red, south!(
bold(true, "× No sample."),
"[r] record",
"[Shift-F9] import",
@ -1983,7 +1941,7 @@ mod draw {
button_2("T", "+", false),
button_2("S", "+", false));
view_track_row_section(theme, button, button_2, bg(theme.darker.term,
draw(|to: &mut Tui|{
thunk(|to: &mut Tui|{
for (index, track, x1, _x2) in tracks {
let b = if selected.track() == Some(index) {
track.color.light.term
@ -2009,14 +1967,14 @@ mod draw {
) -> impl Draw<Tui> {
view_track_row_section(theme,
south(button_2("o", "utput", false).align_w().full_w(),
draw(|to: &mut Tui|{
thunk(|to: &mut Tui|{
for port in midi_outs {
let _ = port.port_name().align_w().full_w().draw(to)?;
}
Ok(Some(XYWH(0, 0, 0, 0)))
})),
button_2("O", "+", false),
bg(theme.darker.term, draw(|to: &mut Tui|{
bg(theme.darker.term, thunk(|to: &mut Tui|{
for (index, track, _x1, _x2) in tracks {
let f = Rgb(255, 255, 255);
let b = track.color.dark.term;
@ -2035,7 +1993,7 @@ mod draw {
theme: ItemTheme, tracks: impl TracksSizes<'a>, height: u16,
) -> impl Draw<Tui> {
view_track_row_section(theme, button_2("i", "nput", false), button_2("I", "+", false),
bg(theme.darker.term, draw(move|to: &mut Tui|{
bg(theme.darker.term, thunk(move|to: &mut Tui|{
for (index, track, _x1, _x2) in tracks {
south(
bg(track.color.base.term,
@ -2059,7 +2017,7 @@ mod draw {
editor: Option<&MidiEditor>,
editing: bool,
) -> impl Draw<Tui> {
draw(move |to: &mut Tui|{
thunk(move |to: &mut Tui|{
for (index, scene, ..) in scenes {
view_scene_name(select, editor, index, scene, editing).draw(to)?;
}
@ -2130,7 +2088,7 @@ mod draw {
) -> impl Draw<Tui> {
let title_1 = button_3("i", "nput ", format!("{}", midi_ins.len()), false).align_w().exact_wh(20, 1);
let title_2 = button_2("I", "+", false).exact_wh(4, 1);
east(title_1, west(title_2, draw(move|to: &mut Tui|{
east(title_1, west(title_2, thunk(move|to: &mut Tui|{
for (_index, track, x1, _x2) in tracks {
let _ = south(
bg(track.color.dark.term, east!(
@ -2138,7 +2096,7 @@ mod draw {
either(track.sequencer.recording, fg(Red, "rec "), "rec "),
either(track.sequencer.overdub, fg(Yellow, "dub "), "dub "),
).exact_w(track.width as u16)).align_w().push_x(x1 as u16),
draw(move |to: &mut Tui|{
thunk(move |to: &mut Tui|{
for (index, port) in midi_ins.iter().enumerate() {
let _ = east(
east(
@ -2174,7 +2132,7 @@ mod draw {
button_3(
"o", "utput", format!("{}", midi_outs.len()), false
).align_w().full_w().exact_h(1),
draw(|to: &mut Tui|{
thunk(|to: &mut Tui|{
for (_index, port) in midi_outs.iter().enumerate() {
east(
east("", fg(Rgb(255,255,255), bold(true, port.port_name()))).align_w(),
@ -2190,9 +2148,9 @@ mod draw {
);
view_track_row_section(theme, list, button_2("O", "+", false),
bg(theme.darker.term, draw(|to: &mut Tui|{
bg(theme.darker.term, thunk(|to: &mut Tui|{
for (index, track, _x1, _x2) in tracks {
let _ = draw(|to: &mut Tui|{
let _ = thunk(|to: &mut Tui|{
east(
either(true, fg(Green, "play "), "play "),
either(false, fg(Yellow, "solo "), "solo "),

2
tengri

@ -1 +1 @@
Subproject commit eb028c85fc94a1b86c44d4f079e5fb91667d4db2
Subproject commit 5ca329292f808c137b6e2b7e80892e2a9e855696