mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
display clamps; pass amount to axis inc/dec
This commit is contained in:
parent
694aed6d9b
commit
27b1c27891
3 changed files with 24 additions and 26 deletions
|
|
@ -2,20 +2,20 @@ use crate::*;
|
||||||
|
|
||||||
macro_rules! impl_axis_common { ($A:ident $T:ty) => {
|
macro_rules! impl_axis_common { ($A:ident $T:ty) => {
|
||||||
impl $A<$T> {
|
impl $A<$T> {
|
||||||
#[inline] pub fn start_inc (&mut self) -> $T {
|
#[inline] pub fn start_inc (&mut self, n: $T) -> $T {
|
||||||
self.start += 1;
|
self.start = (self.start + n).min(self.clamp.unwrap_or(<$T>::MAX));
|
||||||
self.start
|
self.start
|
||||||
}
|
}
|
||||||
#[inline] pub fn start_dec (&mut self) -> $T {
|
#[inline] pub fn start_dec (&mut self, n: $T) -> $T {
|
||||||
self.start = self.start.saturating_sub(1);
|
self.start = self.start.saturating_sub(n);
|
||||||
self.start
|
self.start
|
||||||
}
|
}
|
||||||
#[inline] pub fn point_inc (&mut self) -> Option<$T> {
|
#[inline] pub fn point_inc (&mut self, n: $T) -> Option<$T> {
|
||||||
self.point = self.point.map(|p|p + 1);
|
self.point = self.point.map(|p|(p + n).min(self.clamp.unwrap_or(<$T>::MAX)));
|
||||||
self.point
|
self.point
|
||||||
}
|
}
|
||||||
#[inline] pub fn point_dec (&mut self) -> Option<$T> {
|
#[inline] pub fn point_dec (&mut self, n: $T) -> Option<$T> {
|
||||||
self.point = self.point.map(|p|p.saturating_sub(1));
|
self.point = self.point.map(|p|p.saturating_sub(n));
|
||||||
self.point
|
self.point
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,27 +89,23 @@ impl Handle<Tui> for PhraseEditor<Tui> {
|
||||||
key!(KeyCode::Char('`')) => { self.mode = !self.mode; },
|
key!(KeyCode::Char('`')) => { self.mode = !self.mode; },
|
||||||
key!(KeyCode::Enter) => { self.entered = true; },
|
key!(KeyCode::Enter) => { self.entered = true; },
|
||||||
key!(KeyCode::Esc) => { self.entered = false; },
|
key!(KeyCode::Esc) => { self.entered = false; },
|
||||||
key!(KeyCode::PageUp) => {
|
key!(KeyCode::PageUp) => { self.note_axis.start_dec(3); },
|
||||||
self.note_axis.start = self.note_axis.start.saturating_sub(3);
|
key!(KeyCode::PageDown) => { self.note_axis.start_inc(3); },
|
||||||
}
|
|
||||||
key!(KeyCode::PageDown) => {
|
|
||||||
self.note_axis.start = self.note_axis.start + 3;
|
|
||||||
}
|
|
||||||
key!(KeyCode::Up) => match self.entered {
|
key!(KeyCode::Up) => match self.entered {
|
||||||
true => { self.note_axis.point_dec(); },
|
true => { self.note_axis.point_dec(1); },
|
||||||
false => { self.note_axis.start_dec(); },
|
false => { self.note_axis.start_dec(1); },
|
||||||
},
|
},
|
||||||
key!(KeyCode::Down) => match self.entered {
|
key!(KeyCode::Down) => match self.entered {
|
||||||
true => { self.note_axis.point_inc(); },
|
true => { self.note_axis.point_inc(1); },
|
||||||
false => { self.note_axis.start_inc(); },
|
false => { self.note_axis.start_inc(1); },
|
||||||
},
|
},
|
||||||
key!(KeyCode::Left) => match self.entered {
|
key!(KeyCode::Left) => match self.entered {
|
||||||
true => { self.time_axis.point_dec(); },
|
true => { self.time_axis.point_dec(self.time_axis.scale); },
|
||||||
false => { self.time_axis.start_dec(); },
|
false => { self.time_axis.start_dec(self.time_axis.scale); },
|
||||||
},
|
},
|
||||||
key!(KeyCode::Right) => match self.entered {
|
key!(KeyCode::Right) => match self.entered {
|
||||||
true => { self.time_axis.point_inc(); },
|
true => { self.time_axis.point_inc(self.time_axis.scale); },
|
||||||
false => { self.time_axis.start_inc(); },
|
false => { self.time_axis.start_inc(self.time_axis.scale); },
|
||||||
},
|
},
|
||||||
key!(KeyCode::Char('>')) => {
|
key!(KeyCode::Char('>')) => {
|
||||||
self.time_axis.scale = prev_note_length(self.time_axis.scale)
|
self.time_axis.scale = prev_note_length(self.time_axis.scale)
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ impl Content for PhraseEditor<Tui> {
|
||||||
if *entered {
|
if *entered {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
if let (Some(time), Some(note)) = (time_axis.point, note_axis.point) {
|
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 y = area.y() + 1 + note as u16 / 2;
|
||||||
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
||||||
to.blit(&c, x, y, Some(Style::default().fg(color)));
|
to.blit(&c, x, y, Some(Style::default().fg(color)));
|
||||||
|
|
@ -130,17 +130,19 @@ impl Content for PhraseEditor<Tui> {
|
||||||
if let Some(phrase) = phrase {
|
if let Some(phrase) = phrase {
|
||||||
upper_left = format!("{upper_left}: {}", phrase.read().unwrap().name);
|
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),
|
ppq_to_name(time_axis.scale),
|
||||||
time_axis.start,
|
time_axis.start,
|
||||||
time_axis.point.unwrap_or(0),
|
time_axis.point.unwrap_or(0),
|
||||||
time_axis.scale,
|
time_axis.scale,
|
||||||
|
time_axis.clamp.unwrap_or(0),
|
||||||
);
|
);
|
||||||
if *focused && *entered {
|
if *focused && *entered {
|
||||||
upper_right = format!("Note: {} (+{}:{}) {upper_right}",
|
upper_right = format!("Note: {} (+{}:{}|{}) {upper_right}",
|
||||||
ppq_to_name(*note_len),
|
ppq_to_name(*note_len),
|
||||||
note_axis.start,
|
note_axis.start,
|
||||||
note_axis.point.unwrap_or(0)
|
note_axis.point.unwrap_or(0),
|
||||||
|
note_axis.clamp.unwrap_or(0),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
lay!(
|
lay!(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue