From 265d4a3953cc573f4d6b854fb0902f5c52963133 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 8 Dec 2024 13:42:40 +0100 Subject: [PATCH] refactor sequencer layout --- crates/tek_tui/src/tui_view_phrase_editor.rs | 98 +++++++++----------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/crates/tek_tui/src/tui_view_phrase_editor.rs b/crates/tek_tui/src/tui_view_phrase_editor.rs index 5c8ae6f0..116796e0 100644 --- a/crates/tek_tui/src/tui_view_phrase_editor.rs +++ b/crates/tek_tui/src/tui_view_phrase_editor.rs @@ -56,31 +56,22 @@ impl<'a> Content for PhraseView<'a> { type Engine = Tui; fn content (&self) -> impl Render { let Self { - focused, - entered, - phrase, - size, - buffer, - view_mode, - note_len, + focused, entered, size, + phrase, view_mode, buffer, + note_point, note_len, note_range: (note_lo, note_hi), note_names: (note_lo_name, note_hi_name), - note_point, - time_start, - time_point, - now, + time_start, time_point, + //now: _, .. } = self; - let upper_left = format!( "╭{note_hi} {note_hi_name} {}", phrase.as_ref().map(|p|p.read().unwrap().name.clone()).unwrap_or(String::new()) ); - let lower_left = format!( "╰{note_lo} {note_lo_name}" ); - let mut lower_right = format!( " {} ", size.format() ); @@ -89,7 +80,6 @@ impl<'a> Content for PhraseView<'a> { note_point, to_note_name(*note_point), pulses_to_name(*note_len) ); } - let mut upper_right = format!( "[{}]", if *entered {"■"} else {" "} @@ -99,51 +89,55 @@ impl<'a> Content for PhraseView<'a> { time_point, phrase.read().unwrap().length, pulses_to_name(view_mode.time_zoom()), ) }; - let title_color = if *focused{Color::Rgb(150, 160, 90)}else{Color::Rgb(120, 130, 100)}; + // is it r6d that `to` is the receiver? + let keys = move|to: &mut TuiOutput|{ + Ok(if to.area().h() >= 2 { view_mode.render_keys(to, *note_hi, *note_lo) }) + }; + let notes = |to: &mut TuiOutput|{ + size.set_wh(to.area.w(), to.area.h() as usize - 1); + let draw = to.area().h() >= 2; + Ok(if draw { view_mode.render_notes(to, buffer, *time_start, *note_hi) }) + }; + let cursor = move|to: &mut TuiOutput|{ + Ok(if *focused && *entered { + view_mode.render_cursor( + to, + *time_point, *time_start, view_mode.time_zoom(), + *note_point, *note_len, *note_hi, *note_lo, + ) + }) + }; + //let playhead = move|_: &mut TuiOutput|{ // will this live or die? + ////let playhead_inactive = Style::default().fg(Color::Rgb(255,255,255)).bg(Color::Rgb(40,50,30)); + ////let playhead_active = playhead_inactive.clone().yellow().bold().not_dim(); + ////if let Some(_) = phrase { + ////let now = now.get() as usize; // TODO FIXME: self.now % phrase.read().unwrap().length; + ////let time_clamp = time_clamp; + ////for x in 0..(time_clamp/time_zoom).saturating_sub(*time_start) { + ////let this_step = time_start + (x + 0) * time_zoom; + ////let next_step = time_start + (x + 1) * time_zoom; + ////let x = to.area().x() + x as u16; + ////let active = this_step <= now && now < next_step; + ////let character = if active { "|" } else { "·" }; + ////let style = if active { playhead_active } else { playhead_inactive }; + ////to.blit(&character, x, to.area.y(), Some(style)); + ////} + ////} + //Ok(()) + //}; lay!( row!( - Widget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), move|to: &mut TuiOutput|{ - Ok(if to.area().h() >= 2 { view_mode.render_keys(to, *note_hi, *note_lo) }) - }).fill_y().push_y(1), + Widget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), keys).fill_y().push_y(1), lay!( - Widget::new(|to|Ok(Some(to)), |to: &mut TuiOutput|{ - size.set_wh(to.area.w(), to.area.h() as usize - 1); - let draw = to.area().h() >= 2; - Ok(if draw { view_mode.render_notes(to, buffer, *time_start, *note_hi) }) - }).fill_x().push_y(1), - Widget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{ - Ok(if *focused && *entered { - view_mode.render_cursor( - to, - *time_point, *time_start, view_mode.time_zoom(), - *note_point, *note_len, *note_hi, *note_lo, - ) - }) - }).push_y(1) + Widget::new(|to|Ok(Some(to)), notes).fill_x().push_y(1), + Widget::new(|to|Ok(Some(to)), cursor).push_y(1) ).fill_x() ) .fill_x() .bg(Color::Rgb(40, 50, 30)), - Widget::new(|to:[u16;2]|Ok(Some(to.clip_h(1))), move|to: &mut TuiOutput|{ - //let playhead_inactive = Style::default().fg(Color::Rgb(255,255,255)).bg(Color::Rgb(40,50,30)); - //let playhead_active = playhead_inactive.clone().yellow().bold().not_dim(); - //if let Some(_) = phrase { - //let now = now.get() as usize; // TODO FIXME: self.now % phrase.read().unwrap().length; - //let time_clamp = time_clamp; - //for x in 0..(time_clamp/time_zoom).saturating_sub(*time_start) { - //let this_step = time_start + (x + 0) * time_zoom; - //let next_step = time_start + (x + 1) * time_zoom; - //let x = to.area().x() + x as u16; - //let active = this_step <= now && now < next_step; - //let character = if active { "|" } else { "·" }; - //let style = if active { playhead_active } else { playhead_inactive }; - //to.blit(&character, x, to.area.y(), Some(style)); - //} - //} - Ok(()) - }).push_x(6).align_sw(), + //Widget::new(|to:[u16;2]|Ok(Some(to.clip_h(1))), playhead).push_x(6).align_sw(), TuiStyle::fg(upper_left.to_string(), title_color).align_nw(), TuiStyle::fg(lower_left.to_string(), title_color).align_sw(), TuiStyle::fg(upper_right.to_string(), title_color).pull_x(1).align_ne().fill_xy(), @@ -329,7 +323,6 @@ impl PhraseViewMode { target: &mut BigBuffer, phrase: &Phrase, time_zoom: usize, _: usize ) { let style = Style::default().fg(Color::Rgb(255, 255, 255)); - let mut notes_on = [false;128]; for (y, note) in (0..127).rev().enumerate() { for (x, time) in (0..target.width).map(|x|(x, x*time_zoom)) { let cell = target.get_mut(x, y).unwrap(); @@ -345,6 +338,7 @@ impl PhraseViewMode { }); } } + let mut notes_on = [false;128]; for (x, time_start) in (0..phrase.length).step_by(time_zoom).enumerate() { let time_end = time_start + time_zoom; for time in time_start..time_end {