From 7f3425fe04c993f7600e16f7a805b8dc6fda6df5 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 3 Jul 2024 21:39:46 +0300 Subject: [PATCH] scroll sequencer --- src/control.rs | 12 ++++++++++-- src/model/track.rs | 3 +++ src/view/sequencer.rs | 10 +++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/control.rs b/src/control.rs index c8fb4f6b..1a7818d5 100644 --- a/src/control.rs +++ b/src/control.rs @@ -85,7 +85,11 @@ const KEYMAP: &'static [KeyBinding] = keymap!(App { } }, 2 => { - app.time_cursor = app.time_cursor.saturating_sub(1); + if app.entered { + app.time_cursor = app.time_cursor.saturating_sub(1); + } else { + app.time_start = app.time_start.saturating_sub(1); + } Ok(true) }, _ => Ok(false) @@ -106,7 +110,11 @@ const KEYMAP: &'static [KeyBinding] = keymap!(App { } }, 2 => { - app.time_cursor = app.time_cursor + 1; + if app.entered { + app.time_cursor = app.time_cursor + 1; + } else { + app.time_start = app.time_start + 1; + } Ok(true) }, _ => Ok(false) diff --git a/src/model/track.rs b/src/model/track.rs index bfb640b6..a0acd22a 100644 --- a/src/model/track.rs +++ b/src/model/track.rs @@ -46,6 +46,9 @@ impl Track { pub fn device (&self) -> Option<&Box> { self.devices.get(self.device) } + pub fn device_mut (&mut self) -> Option<&mut Box> { + self.devices.get_mut(self.device) + } pub fn first_device (&self) -> Option<&Box> { self.devices.get(0) } diff --git a/src/view/sequencer.rs b/src/view/sequencer.rs index 4cdb2878..017d2d44 100644 --- a/src/view/sequencer.rs +++ b/src/view/sequencer.rs @@ -131,7 +131,7 @@ mod horizontal { phrase: &Phrase, ppq: usize, time_z: usize, - _time0: usize, + time0: usize, note0: usize, ) { let Rect { x, y, width, height } = area; @@ -142,7 +142,8 @@ mod horizontal { let (bw, wh) = (bg.dim(), bg.white().not_dim()); let offset = 5; for x in x+offset..x+width-offset { - let step = (x-offset) as usize * time_z; + let step = (time0 + (x-offset) as usize) * time_z; + let next_step = (time0 + (x-offset) as usize + 1) * time_z; if step % ppq == 0 { "|".blit(buf, x as u16, y, Some(Style::default().dim())); } @@ -151,13 +152,12 @@ mod horizontal { format!("{}", (step/bar)+1) .blit(buf, x as u16, y, Some(Style::default().bold().not_dim())); } - let (a, b) = (step, step + time_z); for index in 0..height-2 { let note_a = note0 + index as usize * 2; let note_b = note0 + index as usize * 2 + 1; let (character, mut style) = match ( - phrase.contains_note_on(u7::from_int_lossy(note_a as u8), a, b), - phrase.contains_note_on(u7::from_int_lossy(note_b as u8), a, b), + phrase.contains_note_on(u7::from_int_lossy(note_a as u8), step, next_step), + phrase.contains_note_on(u7::from_int_lossy(note_b as u8), step, next_step), ) { (true, true) => ("█", wh), (false, true) => ("▀", wh),