diff --git a/crates/tek_sequencer/src/sequencer_tui.rs b/crates/tek_sequencer/src/sequencer_tui.rs index a0d09ba6..588ffba8 100644 --- a/crates/tek_sequencer/src/sequencer_tui.rs +++ b/crates/tek_sequencer/src/sequencer_tui.rs @@ -71,6 +71,7 @@ impl Content for PhrasePool { impl Content for PhraseEditor { type Engine = Tui; fn content (&self) -> impl Widget { + let Self { focused, entered, time_axis, note_axis, keys, phrase, buffer, .. } = self; //let field_bg = Color::Rgb(28, 35, 25); //let toolbar = Stack::down(move|add|{ ////let name = format!("{:>9}", self.name.read().unwrap().as_str()); @@ -95,17 +96,17 @@ impl Content for PhraseEditor { CustomWidget::new(|_|Ok(Some([32u16,4u16])), |to: &mut TuiOutput|{ if to.area().h() < 2 { return Ok(()) } Ok(to.buffer_update(to.area().set_w(5), &|cell, x, y|{ - let y = y + self.note_axis.start as u16; - if x < self.keys.area.width && y < self.keys.area.height { - *cell = self.keys.get(x, y).clone() + let y = y + note_axis.start as u16; + if x < keys.area.width && y < keys.area.height { + *cell = keys.get(x, y).clone() } })) }).fill_y(), // playhead CustomWidget::new(|_|Ok(Some([32u16,2u16])), |to: &mut TuiOutput|{ - if let Some(phrase) = &self.phrase { - let time_0 = self.time_axis.start; - let time_z = self.time_axis.scale; + if let Some(phrase) = phrase { + let time_0 = time_axis.start; + let time_z = time_axis.scale; let now = 0; // TODO FIXME: self.now % phrase.read().unwrap().length; let [x, y, width, _] = to.area(); let x2 = x as usize + Self::H_KEYS_OFFSET; @@ -127,19 +128,19 @@ impl Content for PhraseEditor { let area = to.area().push_x(offset).shrink_x(offset); Ok(to.buffer_update(area, &move |cell, x, y|{ cell.set_bg(Color::Rgb(20, 20, 20)); - let src_x = ((x as usize + self.time_axis.start) * self.time_axis.scale) as usize; - let src_y = (y as usize + self.note_axis.start) as usize; - if src_x < self.buffer.width && src_y < self.buffer.height - 1 { - let src = self.buffer.get(src_x, self.buffer.height - src_y); + let src_x = ((x as usize + time_axis.start) * time_axis.scale) as usize; + let src_y = (y as usize + note_axis.start) as usize; + if src_x < buffer.width && src_y < buffer.height - 1 { + let src = buffer.get(src_x, buffer.height - src_y); src.map(|src|{ cell.set_symbol(src.symbol()); cell.set_fg(src.fg); }); } })) }).fill_x(), // note cursor CustomWidget::new(|_|Ok(Some([1u16,1u16])), |to: &mut TuiOutput|{ - if self.entered { + if *entered { let area = to.area(); - if let (Some(time), Some(note)) = (self.time_axis.point, self.note_axis.point) { + if let (Some(time), Some(note)) = (time_axis.point, note_axis.point) { let x = area.x() + Self::H_KEYS_OFFSET as u16 + time as u16; let y = area.y() + 1 + note as u16 / 2; let c = if note % 2 == 0 { "▀" } else { "▄" }; @@ -149,26 +150,27 @@ impl Content for PhraseEditor { Ok(()) }), ); - let border_color = - if self.focused { Color::Rgb(100, 110, 40) } else { Color::Rgb(70, 80, 50) }; - let title_color = - if self.focused { Color::Rgb(150, 160, 90) } else { Color::Rgb(120, 130, 100) }; - let border = - Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color)); - let content = - piano_roll.fill_x().bg(Color::Rgb(40, 50, 30)).border(border); - let title = TuiStyle::fg("Sequencer", title_color) - .push_x(1); - let zoom = TuiStyle::fg(format!("{}Zoom: {}", - if self.focused && !self.entered { "[,.] " } else { "" }, - ppq_to_name(self.time_axis.scale), - ), title_color).pull_x(1).align_se().fill_xy(); - let enter = TuiStyle::fg(if self.focused { - if self.entered { "[Esc] Exit edit mode [A]ppend [I]nsert" } else { - "[Enter] Edit notes" + let border_color = if *focused{Color::Rgb(100, 110, 40)}else{Color::Rgb(70, 80, 50)}; + let title_color = if *focused{Color::Rgb(150, 160, 90)}else{Color::Rgb(120, 130, 100)}; + let border = Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color)); + let content = piano_roll.fill_x().bg(Color::Rgb(40, 50, 30)).border(border); + let mut lower_left = String::new(); + let mut lower_right = format!("Zoom: {}", ppq_to_name(time_axis.scale)); + if *focused { + if *entered { + lower_left = "[Esc] Exit edit mode [A]ppend [I]nsert".to_string(); + lower_right = format!("[,.] Length: ?? {}", lower_right); + } else { + lower_left = "[Enter] Edit notes".to_string(); + lower_right = format!("[,.] {}", lower_right); } - } else { "" }, title_color).push_x(1).align_sw().fill_xy(); - lay!(content, title, enter, zoom) + } + lay!( + content, + TuiStyle::fg("Sequencer", title_color).push_x(1).align_nw().fill_xy(), + TuiStyle::fg(lower_left.to_string(), title_color).push_x(1).align_sw().fill_xy(), + TuiStyle::fg(lower_right.to_string(), title_color).pull_x(1).align_se().fill_xy(), + ) } } impl PhraseEditor {