move cursor movement methods into sequencer.rs

This commit is contained in:
🪞👃🪞 2024-10-28 23:50:32 +02:00
parent 6665921de3
commit ac65cea371
2 changed files with 86 additions and 75 deletions

View file

@ -270,6 +270,76 @@ impl<E: Engine> PhraseEditor<E> {
}),
}
}
pub fn note_cursor_inc (&self) {
let mut axis = self.note_axis.write().unwrap();
axis.point_dec(1);
if let Some(point) = axis.point {
if point < axis.start {
axis.start = point;
}
}
}
pub fn note_cursor_dec (&self) {
let mut axis = self.note_axis.write().unwrap();
axis.point_inc(1);
if let Some(point) = axis.point {
if point > 73 {
axis.point = Some(73);
}
}
}
pub fn note_page_up (&self) {
let mut axis = self.note_axis.write().unwrap();
axis.start_dec(3);
axis.point_dec(3);
}
pub fn note_page_down (&self) {
let mut axis = self.note_axis.write().unwrap();
axis.start_inc(3);
axis.point_inc(3);
}
pub fn note_scroll_inc (&self) {
self.note_axis.write().unwrap().start_dec(1);
}
pub fn note_scroll_dec (&self) {
self.note_axis.write().unwrap().start_inc(1);
}
pub fn note_length_inc (&mut self) {
self.note_len = next_note_length(self.note_len)
}
pub fn note_length_dec (&mut self) {
self.note_len = prev_note_length(self.note_len)
}
pub fn time_cursor_advance (&self) {
let point = self.time_axis.read().unwrap().point;
let length = self.phrase.as_ref().map(|p|p.read().unwrap().length).unwrap_or(1);
let forward = |time|(time + self.note_len) % length;
self.time_axis.write().unwrap().point = point.map(forward);
}
pub fn time_cursor_inc (&self) {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().point_inc(scale);
}
pub fn time_cursor_dec (&self) {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().point_dec(scale);
}
pub fn time_scroll_inc (&self) {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().start_inc(scale);
}
pub fn time_scroll_dec (&self) {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().start_dec(scale);
}
pub fn time_zoom_in (&self) {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().scale = prev_note_length(scale)
}
pub fn time_zoom_out (&self) {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().scale = next_note_length(scale)
}
}
impl Phrase {
pub fn new (

View file

@ -90,87 +90,28 @@ impl Handle<Tui> for PhraseEditor<Tui> {
key!(KeyCode::Char('`')) => { self.mode = !self.mode; },
key!(KeyCode::Enter) => { self.entered = true; },
key!(KeyCode::Esc) => { self.entered = false; },
key!(KeyCode::PageUp) => {
let mut axis = self.note_axis.write().unwrap();
axis.start_dec(3);
axis.point_dec(3);
},
key!(KeyCode::PageDown) => {
let mut axis = self.note_axis.write().unwrap();
axis.start_inc(3);
axis.point_inc(3);
},
key!(KeyCode::Char('[')) => if self.entered { self.note_length_dec() },
key!(KeyCode::Char(']')) => if self.entered { self.note_length_inc() },
key!(KeyCode::Char('a')) => if self.entered { self.put(); self.time_cursor_advance() },
key!(KeyCode::Char('s')) => if self.entered { self.put() },
key!(KeyCode::Char('-')) => self.time_zoom_out(),
key!(KeyCode::Char('_')) => self.time_zoom_out(),
key!(KeyCode::Char('=')) => self.time_zoom_in(),
key!(KeyCode::Char('+')) => self.time_zoom_in(),
key!(KeyCode::PageUp) => self.note_page_up(),
key!(KeyCode::PageDown) => self.note_page_down(),
key!(KeyCode::Up) => match self.entered {
true => {
let mut axis = self.note_axis.write().unwrap();
axis.point_dec(1);
if let Some(point) = axis.point {
if point < axis.start {
axis.start = point;
}
}
},
false => { self.note_axis.write().unwrap().start_dec(1); },
true => self.note_cursor_inc(), false => self.note_scroll_inc(),
},
key!(KeyCode::Down) => match self.entered {
true => {
let mut axis = self.note_axis.write().unwrap();
axis.point_inc(1);
if let Some(point) = axis.point {
if point > 73 {
axis.point = Some(73);
}
}
},
false => { self.note_axis.write().unwrap().start_inc(1); },
true => self.note_cursor_dec(), false => self.note_scroll_dec(),
},
key!(KeyCode::Left) => {
let scale = self.time_axis.read().unwrap().scale;
match self.entered {
true => { self.time_axis.write().unwrap().point_dec(scale); },
false => { self.time_axis.write().unwrap().start_dec(scale); },
};
key!(KeyCode::Left) => match self.entered {
true => self.time_cursor_dec(), false => self.time_scroll_dec(),
},
key!(KeyCode::Right) => {
let scale = self.time_axis.read().unwrap().scale;
match self.entered {
true => { self.time_axis.write().unwrap().point_inc(scale); },
false => { self.time_axis.write().unwrap().start_inc(scale); },
}
key!(KeyCode::Right) => match self.entered {
true => self.time_cursor_inc(), false => self.time_scroll_inc(),
},
key!(KeyCode::Char('-')) => {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().scale = next_note_length(scale)
},
key!(KeyCode::Char('_')) => {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().scale = next_note_length(scale)
},
key!(KeyCode::Char('=')) => {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().scale = prev_note_length(scale)
},
key!(KeyCode::Char('+')) => {
let scale = self.time_axis.read().unwrap().scale;
self.time_axis.write().unwrap().scale = prev_note_length(scale)
},
key!(KeyCode::Char('[')) => if self.entered {
self.note_len = prev_note_length(self.note_len)
},
key!(KeyCode::Char(']')) => if self.entered {
self.note_len = next_note_length(self.note_len)
},
key!(KeyCode::Char('a')) => if self.entered {
self.put();
let point = self.time_axis.read().unwrap().point;
let length = self.phrase.as_ref().map(|p|p.read().unwrap().length).unwrap_or(1);
let forward = |time|(time + self.note_len) % length;
self.time_axis.write().unwrap().point = point.map(forward);
},
key!(KeyCode::Char('s')) => if self.entered {
self.put();
},
_ => { return Ok(None) }
}
return Ok(Some(true))