wip: refactor pt.6, fixed tek_api

This commit is contained in:
🪞👃🪞 2024-11-10 14:35:20 +01:00
parent 5df08409e5
commit 869d92110d
29 changed files with 1678 additions and 1679 deletions

View file

@ -0,0 +1,95 @@
use crate::*;
#[derive(Clone, PartialEq)]
pub enum PhraseEditorCommand {
// TODO: 1-9 seek markers that by default start every 8th of the phrase
ToggleDirection,
EnterEditMode,
ExitEditMode,
NoteAppend,
NoteSet,
NoteCursorSet(usize),
NoteLengthSet(usize),
NoteScrollSet(usize),
TimeCursorSet(usize),
TimeScrollSet(usize),
TimeZoomSet(usize),
Go(Direction),
}
impl Handle<Tui> for PhraseEditor<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
PhraseEditorCommand::execute_with_state(self, from)
}
}
impl InputToCommand<Tui, PhraseEditor<Tui>> for PhraseEditorCommand {
fn input_to_command (_: &PhraseEditor<Tui>, from: &TuiInput) -> Option<Self> {
match from.event() {
key!(KeyCode::Char('`')) => Some(Self::ToggleDirection),
key!(KeyCode::Enter) => Some(Self::EnterEditMode),
key!(KeyCode::Esc) => Some(Self::ExitEditMode),
key!(KeyCode::Char('[')) => Some(Self::NoteLengthDec),
key!(KeyCode::Char(']')) => Some(Self::NoteLengthInc),
key!(KeyCode::Char('a')) => Some(Self::NoteAppend),
key!(KeyCode::Char('s')) => Some(Self::NoteSet),
key!(KeyCode::Char('-')) => Some(Self::TimeZoomOut),
key!(KeyCode::Char('_')) => Some(Self::TimeZoomOut),
key!(KeyCode::Char('=')) => Some(Self::TimeZoomIn),
key!(KeyCode::Char('+')) => Some(Self::TimeZoomIn),
key!(KeyCode::PageUp) => Some(Self::NotePageUp),
key!(KeyCode::PageDown) => Some(Self::NotePageDown),
key!(KeyCode::Up) => Some(Self::GoUp),
key!(KeyCode::Down) => Some(Self::GoDown),
key!(KeyCode::Left) => Some(Self::GoLeft),
key!(KeyCode::Right) => Some(Self::GoRight),
_ => None
}
}
}
impl<E: Engine> Command<PhraseEditor<E>> for PhraseEditorCommand {
fn translate (self, state: &PhraseEditor<E>) -> Self {
use PhraseEditorCommand::*;
match self {
GoUp => match state.entered { true => NoteCursorInc, false => NoteScrollInc, },
GoDown => match state.entered { true => NoteCursorDec, false => NoteScrollDec, },
GoLeft => match state.entered { true => TimeCursorDec, false => TimeScrollDec, },
GoRight => match state.entered { true => TimeCursorInc, false => TimeScrollInc, },
_ => self
}
}
fn execute (self, state: &mut PhraseEditor<E>) -> Perhaps<Self> {
use PhraseEditorCommand::*;
match self.translate(state) {
ToggleDirection => { state.mode = !state.mode; },
EnterEditMode => { state.entered = true; },
ExitEditMode => { state.entered = false; },
TimeZoomOut => { state.time_zoom_out() },
TimeZoomIn => { state.time_zoom_in() },
TimeCursorDec => { state.time_cursor_dec() },
TimeCursorInc => { state.time_cursor_inc() },
TimeScrollDec => { state.time_scroll_dec() },
TimeScrollInc => { state.time_scroll_inc() },
NoteCursorDec => { state.note_cursor_dec() },
NoteCursorInc => { state.note_cursor_inc() },
NoteScrollDec => { state.note_scroll_dec() },
NoteScrollInc => { state.note_scroll_inc() },
NoteLengthDec => { state.note_length_dec() },
NoteLengthInc => { state.note_length_inc() },
NotePageUp => { state.note_page_up() },
NotePageDown => { state.note_page_down() },
NoteAppend => {
if state.entered {
state.put();
state.time_cursor_advance();
}
},
NoteSet => {
if state.entered { state.put(); }
},
_ => unreachable!()
}
Ok(None)
}
}