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 {
fn input_to_command (state: &PhraseEditorModel, from: &TuiInput) -> Option<Self> {
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)),

View file

@ -39,8 +39,13 @@ impl Command<SequencerTui> for SequencerCommand {
impl InputToCommand<Tui, SequencerTui> for SequencerCommand {
fn input_to_command (state: &SequencerTui, input: &TuiInput) -> Option<Self> {
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<S
)),
_ => 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
}
})
}

View file

@ -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),
)