From 16e6a0397c715292ba6bd5fd2148eea2edfda44e Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 31 Dec 2024 15:50:53 +0100 Subject: [PATCH] down to 28e, sane ones --- engine/src/output.rs | 47 +++++++++++++-------------- layout/src/direction.rs | 4 +-- layout/src/transform.rs | 10 +++--- src/arranger/arranger_v/v_cursor.rs | 17 ++++++---- src/border.rs | 3 +- src/groovebox.rs | 19 +++++------ src/lib.rs | 2 +- src/meter.rs | 4 +-- src/mixer.rs | 2 +- src/piano_h/piano_h_keys.rs | 4 +-- src/sampler/sample_import.rs | 2 +- src/sampler/sample_viewer.rs | 2 -- src/sampler/sampler_tui.rs | 2 +- src/style.rs | 10 +++--- src/transport.rs | 50 +++++++++++++++-------------- 15 files changed, 91 insertions(+), 87 deletions(-) diff --git a/engine/src/output.rs b/engine/src/output.rs index a8911fc3..e94c4ea6 100644 --- a/engine/src/output.rs +++ b/engine/src/output.rs @@ -1,4 +1,5 @@ use crate::*; +use std::marker::PhantomData; //use std::sync::{Arc, Mutex, RwLock}; /// Rendering target @@ -42,54 +43,52 @@ impl> Content for Option {} impl> Content for Vec {} +pub struct Thunk, F: Fn()->T + Send + Sync>(F, PhantomData); + +impl, F: Fn()->T + Send + Sync> Thunk { + pub fn new (thunk: F) -> Self { + Self(thunk, Default::default()) + } +} +impl, F: Fn()->T + Send + Sync> Content for Thunk { + fn content (&self) -> impl Content { + (self.0)() + } +} + #[macro_export] macro_rules! render { (($self:ident:$Struct:ty) => $content:expr) => { impl Content for $Struct { - fn content (&$self) -> Option> { - Some($content) - } + fn content (&$self) -> impl Content { Some($content) } } }; (|$self:ident:$Struct:ident $(< - $($L:lifetime),* - $($T:ident $(:$Trait:path)?),* + $($L:lifetime),* $($T:ident $(:$Trait:path)?),* >)?, $to:ident | $render:expr) => { impl <$($($L),*)? E: Engine, $($T$(:$Trait)?),*> Content for $Struct $(<$($L),* $($T),*>>)? { - fn render (&$self, $to: &mut E::Output) { - Some($render) - } + fn render (&$self, $to: &mut E::Output) { $render } } }; ($Engine:ty: ($self:ident:$Struct:ident $(<$( - $($L:lifetime)? - $($T:ident)? - $(:$Trait:path)? + $($L:lifetime)? $($T:ident)? $(:$Trait:path)? ),+>)?) => $content:expr ) => { impl $(<$($($L)? $($T)? $(:$Trait)?),+>)? Content<$Engine> - for $Struct $(<$($($L)? $($T)?),+>)? - { - fn content (&$self) -> Option> { - Some($content) - } + for $Struct $(<$($($L)? $($T)?),+>)? { + fn content (&$self) -> impl Content<$Engine> { $content } } }; ($Engine:ty: |$self:ident : $Struct:ident $(<$( - $($L:lifetime)? - $($T:ident)? - $(:$Trait:path)? + $($L:lifetime)? $($T:ident)? $(:$Trait:path)? ),+>)?, $to:ident| $render:expr ) => { impl $(<$($($L)? $($T)? $(:$Trait)?),+>)? Content<$Engine> - for $Struct $(<$($($L)? $($T)?),+>)? - { - fn render (&$self, $to: &mut <$Engine as Engine>::Output) { - Some($render) - } + for $Struct $(<$($($L)? $($T)?),+>)? { + fn render (&$self, $to: &mut <$Engine as Engine>::Output) { $render } } }; } diff --git a/layout/src/direction.rs b/layout/src/direction.rs index 1b56954c..88802d9f 100644 --- a/layout/src/direction.rs +++ b/layout/src/direction.rs @@ -121,8 +121,8 @@ impl, Y: Content> Default for Bsp { impl, Y: Content> Content for Bsp { fn render (&self, to: &mut E::Output) { - let n = E::Size::zero(); - let s = to.wh(); + let _n = E::Size::zero(); + let _s = to.wh(); match self { Self::Null(_) => {}, //Self::S(p, a, b) => { diff --git a/layout/src/transform.rs b/layout/src/transform.rs index f759fc5e..87037ec8 100644 --- a/layout/src/transform.rs +++ b/layout/src/transform.rs @@ -25,13 +25,13 @@ macro_rules! transform_xy { pub fn xy (item: T) -> Self { Self::XY(item) } } impl> Content for $Enum { - fn content (&self) -> Option> { - Some(match self { + fn content (&self) -> impl Content { + match self { Self::X(item) => item, Self::Y(item) => item, Self::XY(item) => item, _ => unreachable!() - }) + } } fn area (&$self, $to: ::Area) -> ::Area { $area @@ -42,7 +42,7 @@ macro_rules! transform_xy { transform_xy!(self: Fill |to|{ let [x0, y0, wmax, hmax] = to.xywh(); - let [x, y, w, h] = self.content().unwrap().area(to).xywh(); + let [x, y, w, h] = self.content().area(to).xywh(); return match self { Self::X(_) => [x0, y, wmax, h], Self::Y(_) => [x, y0, w, hmax], @@ -78,7 +78,7 @@ macro_rules! transform_xy_unit { } } impl> Content for $Enum { - fn content (&self) -> Option> { + fn content (&self) -> impl Content { Some(match self { Self::X(_, content) => content, Self::Y(_, content) => content, diff --git a/src/arranger/arranger_v/v_cursor.rs b/src/arranger/arranger_v/v_cursor.rs index 71532ad9..5859f9d6 100644 --- a/src/arranger/arranger_v/v_cursor.rs +++ b/src/arranger/arranger_v/v_cursor.rs @@ -72,11 +72,16 @@ impl Content for ArrangerVCursor { to.fill_ul([area.x(), y - 1, area.w(), 1], bg); to.fill_ul([area.x(), y + height - 1, area.w(), 1], bg); } - Ok(if focused { - to.render_in(if let Some(clip_area) = clip_area { clip_area } - else if let Some(track_area) = track_area { track_area.clip_h(HEADER_H) } - else if let Some(scene_area) = scene_area { scene_area.clip_w(self.scenes_w) } - else { area.clip_w(self.scenes_w).clip_h(HEADER_H) }, &self.reticle)? - }) + if focused { + to.place(if let Some(clip_area) = clip_area { + clip_area + } else if let Some(track_area) = track_area { + track_area.clip_h(HEADER_H) + } else if let Some(scene_area) = scene_area { + scene_area.clip_w(self.scenes_w) + } else { + area.clip_w(self.scenes_w).clip_h(HEADER_H) + }, &self.reticle) + }; } } diff --git a/src/border.rs b/src/border.rs index ddcf16e2..afc77bd3 100644 --- a/src/border.rs +++ b/src/border.rs @@ -24,7 +24,6 @@ render!(Tui: |self: Border, to| { to.blit(&self.0.e(), area.x() + area.w() - 1, y, self.0.style()); } } - Ok(()) }); pub trait BorderStyle: Send + Sync + Copy { @@ -130,7 +129,7 @@ macro_rules! border { #[derive(Copy, Clone)] pub struct $T(pub Style); impl Content for $T { - fn render (&self, to: &mut TuiOutput) { self.draw(to) } + fn render (&self, to: &mut TuiOutput) { self.draw(to); } } )+} } diff --git a/src/groovebox.rs b/src/groovebox.rs index bb8806f4..883ecdf3 100644 --- a/src/groovebox.rs +++ b/src/groovebox.rs @@ -149,13 +149,14 @@ render!(Tui: (self: Groovebox) => { struct EditStatus<'a, T: Content>(&'a Sampler, &'a MidiEditor, usize, T); impl<'a, T: Content> Content for EditStatus<'a, T> { - fn content (&self) -> Option> { - Some(Split::n(false, 9, col!( + fn content (&self) -> impl Content { + Split::n(false, 9, col!( row!( - Cond::opt( - &self.0.mapped[self.2], - |sample|format!("Sample {}", sample.read().unwrap().end) - ), + self.0.mapped[self.2].as_ref().map(|sample|format!( + "Sample {}-{}", + sample.read().unwrap().start, + sample.read().unwrap().end, + )), MidiEditStatus(&self.1), ), lay!( @@ -168,7 +169,7 @@ impl<'a, T: Content> Content for EditStatus<'a, T> { SampleViewer(None) })), ), - ), &self.3)) + ), &self.3) } } @@ -177,7 +178,7 @@ render!(Tui: (self: GrooveboxSamples<'a>) => { let note_lo = self.0.editor.note_lo().load(Relaxed); let note_pt = self.0.editor.note_point(); let note_hi = self.0.editor.note_hi(); - Fill::xy(Coll::map((note_lo..=note_hi).rev(), |note, i| { + Fill::xy(Coll::map((note_lo..=note_hi).rev(), move|note, i| { let mut bg = if note == note_pt { TuiTheme::g(64) } else { Color::Reset }; let mut fg = TuiTheme::g(160); if let Some((index, _)) = self.0.sampler.recording { @@ -188,7 +189,7 @@ render!(Tui: (self: GrooveboxSamples<'a>) => { } else if self.0.sampler.mapped[note].is_some() { fg = TuiTheme::g(224); } - Push::y(i, Tui::bg(bg, if let Some(sample) = &self.0.sampler.mapped[note] { + Push::y(i as u16, Tui::bg(bg, if let Some(sample) = &self.0.sampler.mapped[note] { Tui::fg(fg, format!("{note:3} ?????? ")) } else { Tui::fg(fg, format!("{note:3} (none) ")) diff --git a/src/lib.rs b/src/lib.rs index db8b4397..65854e7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ pub(crate) use ::tek_layout::{ tek_engine::{ Usually, Perhaps, Engine, Size, Area, - Output, Content, render, + Output, Content, Thunk, render, Input, Handle, handle, kexp, key_pat, key_event_pat, key_event_expr, tui::{ diff --git a/src/meter.rs b/src/meter.rs index 97cb1a21..57dc5b5e 100644 --- a/src/meter.rs +++ b/src/meter.rs @@ -3,6 +3,6 @@ use crate::*; pub struct Meters<'a>(pub &'a[f32]); render!(Tui: (self: Meters<'a>) => col!( - &format!("L/{:>+9.3}", self.0[0]), - &format!("R/{:>+9.3}", self.0[1]), + format!("L/{:>+9.3}", self.0[0]), + format!("R/{:>+9.3}", self.0[1]), )); diff --git a/src/mixer.rs b/src/mixer.rs index fee90830..70d0960f 100644 --- a/src/mixer.rs +++ b/src/mixer.rs @@ -97,7 +97,7 @@ pub struct TrackView<'a> { } impl<'a> Content for TrackView<'a> { - fn render (&self, to: &mut TuiOutput) -> Usually<()> { + fn render (&self, to: &mut TuiOutput) { todo!(); //let mut area = to.area(); //if let Some(chain) = self.chain { diff --git a/src/piano_h/piano_h_keys.rs b/src/piano_h/piano_h_keys.rs index be02b317..73c7d816 100644 --- a/src/piano_h/piano_h_keys.rs +++ b/src/piano_h/piano_h_keys.rs @@ -5,14 +5,14 @@ pub struct PianoHorizontalKeys<'a>(pub(crate) &'a PianoHorizontal); render!(Tui: |self: PianoHorizontalKeys<'a>, to|{ let state = self.0; - let color = state.color(); + let color = state.color; let note_lo = state.note_lo().get(); let note_hi = state.note_hi(); let note_point = state.note_point(); let [x, y0, w, h] = to.area().xywh(); let key_style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0))); let off_style = Some(Style::default().fg(TuiTheme::g(160))); - let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(color.rgb).bold()); + let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(color.base.rgb).bold()); for (area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) { to.blit(&to_key(note), x, screen_y, key_style); if note > 127 { diff --git a/src/sampler/sample_import.rs b/src/sampler/sample_import.rs index 930f0c65..a2505b40 100644 --- a/src/sampler/sample_import.rs +++ b/src/sampler/sample_import.rs @@ -171,7 +171,7 @@ fn draw_sample ( } impl Content for AddSampleModal { - fn render (&self, to: &mut TuiOutput) -> Usually<()> { + fn render (&self, to: &mut TuiOutput) { todo!() //let area = to.area(); //to.make_dim(); diff --git a/src/sampler/sample_viewer.rs b/src/sampler/sample_viewer.rs index 8fb53ab6..44cc4d0f 100644 --- a/src/sampler/sample_viewer.rs +++ b/src/sampler/sample_viewer.rs @@ -52,6 +52,4 @@ render!(Tui: |self: SampleViewer, to|{ .y_bounds(y_bounds) .paint(|ctx| { for line in lines.iter() { ctx.draw(line) } }) .render(area, &mut to.buffer); - - Ok(()) }); diff --git a/src/sampler/sampler_tui.rs b/src/sampler/sampler_tui.rs index 187637ff..ec5fe9b6 100644 --- a/src/sampler/sampler_tui.rs +++ b/src/sampler/sampler_tui.rs @@ -82,7 +82,7 @@ render!(Tui: |self: SamplesTui, render|{ let note = self.note_hi - y as usize; let bg = if note == self.note_pt { bg_selected } else { bg_base }; let style = Some(style_empty.bg(bg)); - render.blit(&" (no sample) ", x, render.area.y() + y as u16, style) + render.blit(&" (no sample) ", x, render.area.y() + y as u16, style); } }); diff --git a/src/style.rs b/src/style.rs index 941f7feb..58a977a0 100644 --- a/src/style.rs +++ b/src/style.rs @@ -23,7 +23,7 @@ impl TuiStyle for Tui {} pub struct Bold>(pub bool, W); impl> Content for Bold { - fn content (&self) -> Option> { + fn content (&self) -> impl Content { Some(&self.1) } fn render (&self, to: &mut TuiOutput) { @@ -35,7 +35,7 @@ impl> Content for Bold { pub struct Foreground>(pub Color, W); impl> Content for Foreground { - fn content (&self) -> Option> { + fn content (&self) -> impl Content { Some(&self.1) } fn render (&self, to: &mut TuiOutput) { @@ -47,7 +47,7 @@ impl> Content for Foreground { pub struct Background>(pub Color, W); impl> Content for Background { - fn content (&self) -> Option> { + fn content (&self) -> impl Content { Some(&self.1) } fn render (&self, to: &mut TuiOutput) { @@ -59,14 +59,14 @@ impl> Content for Background { pub struct Styled>(pub Option