From 37d4a42a830dfbbae7c7547d6c20ba8b734235a3 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 30 Nov 2024 22:36:58 +0100 Subject: [PATCH] show time_point; wrap time; handle enter at top level --- .../tek_tui/src/tui_control_phrase_editor.rs | 75 ++++++------------- crates/tek_tui/src/tui_control_sequencer.rs | 43 +++++------ crates/tek_tui/src/tui_view_phrase_editor.rs | 3 +- 3 files changed, 47 insertions(+), 74 deletions(-) diff --git a/crates/tek_tui/src/tui_control_phrase_editor.rs b/crates/tek_tui/src/tui_control_phrase_editor.rs index 04556b70..71bd4510 100644 --- a/crates/tek_tui/src/tui_control_phrase_editor.rs +++ b/crates/tek_tui/src/tui_control_phrase_editor.rs @@ -19,68 +19,39 @@ pub enum PhraseCommand { impl InputToCommand for PhraseCommand { fn input_to_command (state: &PhraseEditorModel, from: &TuiInput) -> Option { use PhraseCommand::*; - use KeyCode::{Char, Enter, Esc, Up, Down, PageUp, PageDown, Left, Right}; + use KeyCode::{Char, Esc, Up, Down, PageUp, PageDown, Left, Right}; + let note_lo = state.note_lo.load(Ordering::Relaxed); + let note_point = state.note_point.load(Ordering::Relaxed); + let time_start = state.time_start.load(Ordering::Relaxed); + let time_point = state.time_point.load(Ordering::Relaxed); + let time_scale = state.time_scale.load(Ordering::Relaxed); + let length = state.phrase.as_ref().map(|p|p.read().unwrap().length).unwrap_or(1); Some(match from.event() { key!(Char('`')) => ToggleDirection, key!(Esc) => SetEditMode(PhraseEditMode::Scroll), - key!(Char('-')) => SetTimeZoom( - next_note_length(state.time_scale.load(Ordering::Relaxed)) - ), - key!(Char('_')) => SetTimeZoom( - next_note_length(state.time_scale.load(Ordering::Relaxed)) - ), - key!(Char('=')) => SetTimeZoom( - prev_note_length(state.time_scale.load(Ordering::Relaxed)) - ), - key!(Char('+')) => SetTimeZoom( - prev_note_length(state.time_scale.load(Ordering::Relaxed)) - ), + key!(Char('-')) => SetTimeZoom(next_note_length(time_scale)), + key!(Char('_')) => SetTimeZoom(next_note_length(time_scale)), + key!(Char('=')) => SetTimeZoom(prev_note_length(time_scale)), + key!(Char('+')) => SetTimeZoom(prev_note_length(time_scale)), _ => match state.edit_mode { PhraseEditMode::Scroll => match from.event() { key!(Char('e')) => SetEditMode(PhraseEditMode::Note), - key!(Up) => SetNoteCursor( - state.note_point.load(Ordering::Relaxed) + 1 - ), - key!(Down) => SetNoteCursor( - state.note_point.load(Ordering::Relaxed).saturating_sub(1) - ), - key!(PageUp) => SetNoteCursor( - state.note_point.load(Ordering::Relaxed) + 3 - ), - key!(PageDown) => SetNoteCursor( - state.note_point.load(Ordering::Relaxed).saturating_sub(3) - ), - key!(Left) => SetTimeCursor( - state.time_point.load(Ordering::Relaxed).saturating_sub( - state.time_scale.load(Ordering::Relaxed) - ) - ), - key!(Right) => SetTimeCursor( - state.time_point.load(Ordering::Relaxed) + - state.time_scale.load(Ordering::Relaxed) - ), + key!(Up) => SetNoteCursor(note_point + 1), + key!(Down) => SetNoteCursor(note_point.saturating_sub(1)), + key!(PageUp) => SetNoteCursor(note_point + 3), + key!(PageDown) => SetNoteCursor(note_point.saturating_sub(3)), + key!(Left) => SetTimeCursor(time_point.saturating_sub(time_scale)), + key!(Right) => SetTimeCursor((time_point + time_scale) % length), _ => return None }, PhraseEditMode::Note => match from.event() { key!(Char('e')) => SetEditMode(PhraseEditMode::Scroll), - key!(Up) => SetNoteScroll( - state.note_lo.load(Ordering::Relaxed) + 1 - ), - key!(Down) => SetNoteScroll( - state.note_lo.load(Ordering::Relaxed).saturating_sub(1) - ), - key!(PageUp) => SetNoteScroll( - state.note_lo.load(Ordering::Relaxed) + 3 - ), - key!(PageDown) => SetNoteScroll( - state.note_lo.load(Ordering::Relaxed).saturating_sub(3) - ), - key!(Left) => SetTimeScroll( - state.time_start.load(Ordering::Relaxed).saturating_sub(1) - ), - key!(Right) => SetTimeScroll( - state.time_start.load(Ordering::Relaxed) + 1 - ), + key!(Up) => SetNoteScroll(note_lo + 1), + key!(Down) => SetNoteScroll(note_lo.saturating_sub(1)), + key!(PageUp) => SetNoteScroll(note_lo + 3), + key!(PageDown) => SetNoteScroll(note_lo.saturating_sub(3)), + key!(Left) => SetTimeScroll(time_start.saturating_sub(1)), + key!(Right) => SetTimeScroll(time_start + 1), key!(Char('a')) => AppendNote, key!(Char('s')) => PutNote, key!(Char('[')) => SetNoteLength(prev_note_length(state.note_len)), diff --git a/crates/tek_tui/src/tui_control_sequencer.rs b/crates/tek_tui/src/tui_control_sequencer.rs index dc9a7d07..194678c8 100644 --- a/crates/tek_tui/src/tui_control_sequencer.rs +++ b/crates/tek_tui/src/tui_control_sequencer.rs @@ -39,8 +39,13 @@ impl Command for SequencerCommand { impl InputToCommand for SequencerCommand { fn input_to_command (state: &SequencerTui, input: &TuiInput) -> Option { - to_sequencer_command(state, input) - .or_else(||to_focus_command(input).map(SequencerCommand::Focus)) + if state.entered() { + to_sequencer_command(state, input) + .or_else(||to_focus_command(input).map(SequencerCommand::Focus)) + } else { + to_focus_command(input).map(SequencerCommand::Focus) + .or_else(||to_sequencer_command(state, input)) + } } } @@ -71,27 +76,23 @@ pub fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option return None, }, - _ => if state.entered() { - match state.focused() { - SequencerFocus::Transport(_) => match TransportCommand::input_to_command(state, input)? { - TransportCommand::Clock(command) => Clock(command), - _ => return None, - }, - SequencerFocus::PhraseEditor => Editor( - PhraseCommand::input_to_command(&state.editor, input)? + _ => match state.focused() { + SequencerFocus::Transport(_) => match TransportCommand::input_to_command(state, input)? { + TransportCommand::Clock(command) => Clock(command), + _ => return None, + }, + SequencerFocus::PhraseEditor => Editor( + PhraseCommand::input_to_command(&state.editor, input)? + ), + SequencerFocus::PhraseList => match input.event() { + key!(Enter) => Enqueue(Some( + state.phrases.phrases[state.phrases.phrase.load(Ordering::Relaxed)].clone() + )), + _ => Phrases( + PhrasesCommand::input_to_command(&state.phrases, input)? ), - SequencerFocus::PhraseList => match input.event() { - key!(Enter) => Enqueue(Some( - state.phrases.phrases[state.phrases.phrase.load(Ordering::Relaxed)].clone() - )), - _ => Phrases( - PhrasesCommand::input_to_command(&state.phrases, input)? - ), - } - _ => return None } - } else { - return None + _ => return None } }) } diff --git a/crates/tek_tui/src/tui_view_phrase_editor.rs b/crates/tek_tui/src/tui_view_phrase_editor.rs index 22405384..955ff694 100644 --- a/crates/tek_tui/src/tui_view_phrase_editor.rs +++ b/crates/tek_tui/src/tui_view_phrase_editor.rs @@ -212,7 +212,8 @@ impl<'a> Content for PhraseView<'a> { } let mut upper_right = format!("[{}]", if *entered {"■"} else {" "}); if let Some(phrase) = phrase { - upper_right = format!("┤Length: {}├─┤Zoom: {}├{upper_right}", + upper_right = format!("┤Time: {}/{} {}├{upper_right}", + time_point, phrase.read().unwrap().length, pulses_to_name(*time_scale), )