show time_point; wrap time; handle enter at top level

This commit is contained in:
🪞👃🪞 2024-11-30 22:36:58 +01:00
parent f7ae5fc8e0
commit 37d4a42a83
3 changed files with 47 additions and 74 deletions

View file

@ -19,68 +19,39 @@ pub enum PhraseCommand {
impl InputToCommand<Tui, PhraseEditorModel> for PhraseCommand { impl InputToCommand<Tui, PhraseEditorModel> for PhraseCommand {
fn input_to_command (state: &PhraseEditorModel, from: &TuiInput) -> Option<Self> { fn input_to_command (state: &PhraseEditorModel, from: &TuiInput) -> Option<Self> {
use PhraseCommand::*; 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() { Some(match from.event() {
key!(Char('`')) => ToggleDirection, key!(Char('`')) => ToggleDirection,
key!(Esc) => SetEditMode(PhraseEditMode::Scroll), key!(Esc) => SetEditMode(PhraseEditMode::Scroll),
key!(Char('-')) => SetTimeZoom( key!(Char('-')) => SetTimeZoom(next_note_length(time_scale)),
next_note_length(state.time_scale.load(Ordering::Relaxed)) key!(Char('_')) => SetTimeZoom(next_note_length(time_scale)),
), key!(Char('=')) => SetTimeZoom(prev_note_length(time_scale)),
key!(Char('_')) => SetTimeZoom( key!(Char('+')) => SetTimeZoom(prev_note_length(time_scale)),
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))
),
_ => match state.edit_mode { _ => match state.edit_mode {
PhraseEditMode::Scroll => match from.event() { PhraseEditMode::Scroll => match from.event() {
key!(Char('e')) => SetEditMode(PhraseEditMode::Note), key!(Char('e')) => SetEditMode(PhraseEditMode::Note),
key!(Up) => SetNoteCursor( key!(Up) => SetNoteCursor(note_point + 1),
state.note_point.load(Ordering::Relaxed) + 1 key!(Down) => SetNoteCursor(note_point.saturating_sub(1)),
), key!(PageUp) => SetNoteCursor(note_point + 3),
key!(Down) => SetNoteCursor( key!(PageDown) => SetNoteCursor(note_point.saturating_sub(3)),
state.note_point.load(Ordering::Relaxed).saturating_sub(1) key!(Left) => SetTimeCursor(time_point.saturating_sub(time_scale)),
), key!(Right) => SetTimeCursor((time_point + time_scale) % length),
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)
),
_ => return None _ => return None
}, },
PhraseEditMode::Note => match from.event() { PhraseEditMode::Note => match from.event() {
key!(Char('e')) => SetEditMode(PhraseEditMode::Scroll), key!(Char('e')) => SetEditMode(PhraseEditMode::Scroll),
key!(Up) => SetNoteScroll( key!(Up) => SetNoteScroll(note_lo + 1),
state.note_lo.load(Ordering::Relaxed) + 1 key!(Down) => SetNoteScroll(note_lo.saturating_sub(1)),
), key!(PageUp) => SetNoteScroll(note_lo + 3),
key!(Down) => SetNoteScroll( key!(PageDown) => SetNoteScroll(note_lo.saturating_sub(3)),
state.note_lo.load(Ordering::Relaxed).saturating_sub(1) key!(Left) => SetTimeScroll(time_start.saturating_sub(1)),
), key!(Right) => SetTimeScroll(time_start + 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!(Char('a')) => AppendNote, key!(Char('a')) => AppendNote,
key!(Char('s')) => PutNote, key!(Char('s')) => PutNote,
key!(Char('[')) => SetNoteLength(prev_note_length(state.note_len)), key!(Char('[')) => SetNoteLength(prev_note_length(state.note_len)),

View file

@ -39,8 +39,13 @@ impl Command<SequencerTui> for SequencerCommand {
impl InputToCommand<Tui, SequencerTui> for SequencerCommand { impl InputToCommand<Tui, SequencerTui> for SequencerCommand {
fn input_to_command (state: &SequencerTui, input: &TuiInput) -> Option<Self> { fn input_to_command (state: &SequencerTui, input: &TuiInput) -> Option<Self> {
to_sequencer_command(state, input) if state.entered() {
.or_else(||to_focus_command(input).map(SequencerCommand::Focus)) 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<S
)), )),
_ => return None, _ => return None,
}, },
_ => if state.entered() { _ => match state.focused() {
match state.focused() { SequencerFocus::Transport(_) => match TransportCommand::input_to_command(state, input)? {
SequencerFocus::Transport(_) => match TransportCommand::input_to_command(state, input)? { TransportCommand::Clock(command) => Clock(command),
TransportCommand::Clock(command) => Clock(command), _ => return None,
_ => return None, },
}, SequencerFocus::PhraseEditor => Editor(
SequencerFocus::PhraseEditor => Editor( PhraseCommand::input_to_command(&state.editor, input)?
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
} }
}) })
} }

View file

@ -212,7 +212,8 @@ impl<'a> Content for PhraseView<'a> {
} }
let mut upper_right = format!("[{}]", if *entered {""} else {" "}); let mut upper_right = format!("[{}]", if *entered {""} else {" "});
if let Some(phrase) = phrase { if let Some(phrase) = phrase {
upper_right = format!("┤Length: {}├─┤Zoom: {}{upper_right}", upper_right = format!("┤Time: {}/{} {}{upper_right}",
time_point,
phrase.read().unwrap().length, phrase.read().unwrap().length,
pulses_to_name(*time_scale), pulses_to_name(*time_scale),
) )