From 767b9ff9833a371569de512135c8f7219aa55d64 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Mon, 28 Oct 2024 20:23:15 +0200 Subject: [PATCH] vertical scroll sequencer, pt.1 --- crates/tek_core/src/lib.rs | 2 +- crates/tek_sequencer/src/sequencer_tui.rs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/tek_core/src/lib.rs b/crates/tek_core/src/lib.rs index 6a0191bb..76fc8f55 100644 --- a/crates/tek_core/src/lib.rs +++ b/crates/tek_core/src/lib.rs @@ -6,7 +6,7 @@ pub use clap; pub use std::sync::{Arc, Mutex, LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard}; pub use std::collections::BTreeMap; pub use once_cell::sync::Lazy; -pub use std::sync::atomic::{Ordering, AtomicBool, AtomicUsize}; +pub use std::sync::atomic::{Ordering, AtomicBool, AtomicUsize, AtomicU16}; pub use std::rc::Rc; pub use std::cell::RefCell; pub use std::marker::PhantomData; diff --git a/crates/tek_sequencer/src/sequencer_tui.rs b/crates/tek_sequencer/src/sequencer_tui.rs index c026507e..5e021ac5 100644 --- a/crates/tek_sequencer/src/sequencer_tui.rs +++ b/crates/tek_sequencer/src/sequencer_tui.rs @@ -72,8 +72,16 @@ impl Content for PhraseEditor { }).fill_y(); let notes_bg_null = Color::Rgb(28, 35, 25); let notes = CustomWidget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{ - self.width.store(to.area.w() as usize, Ordering::Relaxed); - self.height.store(to.area.h() as usize, Ordering::Relaxed); + let w = to.area.w() as usize; + let h = to.area.h() as usize; + self.width.store(w, Ordering::Relaxed); + self.height.store(h, Ordering::Relaxed); + let mut axis = self.note_axis.write().unwrap(); + if let Some(point) = axis.point { + if point.saturating_sub(axis.start) / 2 > h { + axis.start += 1; + } + } if to.area().h() >= 2 { let area = to.area(); to.buffer_update(area, &move |cell, x, y|{ @@ -81,7 +89,7 @@ impl Content for PhraseEditor { let src_x = (x as usize + time_start) * time_scale; let src_y = y as usize + note_start; if src_x < buffer.width && src_y < buffer.height - 1 { - buffer.get(src_x, buffer.height - src_y).map(|src|{ + buffer.get(src_x, buffer.height - src_y - 1).map(|src|{ cell.set_symbol(src.symbol()); cell.set_fg(src.fg); cell.set_bg(src.bg); @@ -97,7 +105,7 @@ impl Content for PhraseEditor { if let (Some(time), Some(note)) = (time_point, note_point) { let x1 = area.x() + (time / time_scale) as u16; let x2 = x1 + (self.note_len / time_scale) as u16; - let y = area.y() + 1 + note as u16 / 2; + let y = area.y() + note as u16 / 2; let c = if note % 2 == 0 { "▀" } else { "▄" }; for x in x1..x2 { to.blit(&c, x, y, Some(Style::default().fg(color))); @@ -142,10 +150,8 @@ impl Content for PhraseEditor { } let mut upper_right = format!("Zoom: {} (+{}:{}*{}|{})", pulses_to_name(time_scale), - time_start, - time_point.unwrap_or(0), - time_scale, - time_clamp.unwrap_or(0), + time_start, time_point.unwrap_or(0), + time_scale, time_clamp.unwrap_or(0), ); if *focused && *entered { upper_right = format!("Note: {} (+{}:{}|{}) {upper_right}",