From 27b1c2789159e75c26f4735fe8a54ff22ab01164 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 23 Oct 2024 01:14:09 +0300 Subject: [PATCH] display clamps; pass amount to axis inc/dec --- crates/tek_core/src/space.rs | 16 +++++++-------- crates/tek_sequencer/src/sequencer_cmd.rs | 24 ++++++++++------------- crates/tek_sequencer/src/sequencer_tui.rs | 10 ++++++---- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index fa6477d7..3dd60a40 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -2,20 +2,20 @@ use crate::*; macro_rules! impl_axis_common { ($A:ident $T:ty) => { impl $A<$T> { - #[inline] pub fn start_inc (&mut self) -> $T { - self.start += 1; + #[inline] pub fn start_inc (&mut self, n: $T) -> $T { + self.start = (self.start + n).min(self.clamp.unwrap_or(<$T>::MAX)); self.start } - #[inline] pub fn start_dec (&mut self) -> $T { - self.start = self.start.saturating_sub(1); + #[inline] pub fn start_dec (&mut self, n: $T) -> $T { + self.start = self.start.saturating_sub(n); self.start } - #[inline] pub fn point_inc (&mut self) -> Option<$T> { - self.point = self.point.map(|p|p + 1); + #[inline] pub fn point_inc (&mut self, n: $T) -> Option<$T> { + self.point = self.point.map(|p|(p + n).min(self.clamp.unwrap_or(<$T>::MAX))); self.point } - #[inline] pub fn point_dec (&mut self) -> Option<$T> { - self.point = self.point.map(|p|p.saturating_sub(1)); + #[inline] pub fn point_dec (&mut self, n: $T) -> Option<$T> { + self.point = self.point.map(|p|p.saturating_sub(n)); self.point } } diff --git a/crates/tek_sequencer/src/sequencer_cmd.rs b/crates/tek_sequencer/src/sequencer_cmd.rs index 1e6109dd..18e9dd31 100644 --- a/crates/tek_sequencer/src/sequencer_cmd.rs +++ b/crates/tek_sequencer/src/sequencer_cmd.rs @@ -89,27 +89,23 @@ impl Handle for PhraseEditor { key!(KeyCode::Char('`')) => { self.mode = !self.mode; }, key!(KeyCode::Enter) => { self.entered = true; }, key!(KeyCode::Esc) => { self.entered = false; }, - key!(KeyCode::PageUp) => { - self.note_axis.start = self.note_axis.start.saturating_sub(3); - } - key!(KeyCode::PageDown) => { - self.note_axis.start = self.note_axis.start + 3; - } + key!(KeyCode::PageUp) => { self.note_axis.start_dec(3); }, + key!(KeyCode::PageDown) => { self.note_axis.start_inc(3); }, key!(KeyCode::Up) => match self.entered { - true => { self.note_axis.point_dec(); }, - false => { self.note_axis.start_dec(); }, + true => { self.note_axis.point_dec(1); }, + false => { self.note_axis.start_dec(1); }, }, key!(KeyCode::Down) => match self.entered { - true => { self.note_axis.point_inc(); }, - false => { self.note_axis.start_inc(); }, + true => { self.note_axis.point_inc(1); }, + false => { self.note_axis.start_inc(1); }, }, key!(KeyCode::Left) => match self.entered { - true => { self.time_axis.point_dec(); }, - false => { self.time_axis.start_dec(); }, + true => { self.time_axis.point_dec(self.time_axis.scale); }, + false => { self.time_axis.start_dec(self.time_axis.scale); }, }, key!(KeyCode::Right) => match self.entered { - true => { self.time_axis.point_inc(); }, - false => { self.time_axis.start_inc(); }, + true => { self.time_axis.point_inc(self.time_axis.scale); }, + false => { self.time_axis.start_inc(self.time_axis.scale); }, }, key!(KeyCode::Char('>')) => { self.time_axis.scale = prev_note_length(self.time_axis.scale) diff --git a/crates/tek_sequencer/src/sequencer_tui.rs b/crates/tek_sequencer/src/sequencer_tui.rs index 4dad360c..b8b476e7 100644 --- a/crates/tek_sequencer/src/sequencer_tui.rs +++ b/crates/tek_sequencer/src/sequencer_tui.rs @@ -88,7 +88,7 @@ impl Content for PhraseEditor { if *entered { let area = to.area(); if let (Some(time), Some(note)) = (time_axis.point, note_axis.point) { - let x = area.x() + time as u16; + let x = area.x() + (time / time_axis.scale) as u16; let y = area.y() + 1 + note as u16 / 2; let c = if note % 2 == 0 { "▀" } else { "▄" }; to.blit(&c, x, y, Some(Style::default().fg(color))); @@ -130,17 +130,19 @@ impl Content for PhraseEditor { if let Some(phrase) = phrase { upper_left = format!("{upper_left}: {}", phrase.read().unwrap().name); } - let mut upper_right = format!("Zoom: {} (+{}:{}*{})", + let mut upper_right = format!("Zoom: {} (+{}:{}*{}|{})", ppq_to_name(time_axis.scale), time_axis.start, time_axis.point.unwrap_or(0), time_axis.scale, + time_axis.clamp.unwrap_or(0), ); if *focused && *entered { - upper_right = format!("Note: {} (+{}:{}) {upper_right}", + upper_right = format!("Note: {} (+{}:{}|{}) {upper_right}", ppq_to_name(*note_len), note_axis.start, - note_axis.point.unwrap_or(0) + note_axis.point.unwrap_or(0), + note_axis.clamp.unwrap_or(0), ); } lay!(