From f4a4b08c8a229402c8ee4595614b3fc5530af800 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 19 Nov 2024 23:05:17 +0100 Subject: [PATCH] wip: p.59, e=54 --- crates/tek_tui/src/tui_apis.rs | 39 +------------------------------ crates/tek_tui/src/tui_command.rs | 19 ++++++++------- crates/tek_tui/src/tui_input.rs | 36 ++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/crates/tek_tui/src/tui_apis.rs b/crates/tek_tui/src/tui_apis.rs index ae177ea2..9472eb80 100644 --- a/crates/tek_tui/src/tui_apis.rs +++ b/crates/tek_tui/src/tui_apis.rs @@ -25,7 +25,7 @@ impl PhraseTui { entered: false, mode: false, now: Arc::new(0.into()), - size: Measure::default(), + size: Measure::new(), //width: 0.into(), //height: 0.into(), note_axis: RwLock::new(FixedAxis { @@ -43,43 +43,6 @@ impl PhraseTui { } } - //pub fn track_next (&mut self, last_track: usize) { - //use ArrangerSelection::*; - //*self = match self { - //Mix => Track(0), - //Track(t) => Track(last_track.min(*t + 1)), - //Scene(s) => Clip(0, *s), - //Clip(t, s) => Clip(last_track.min(*t + 1), *s), - //} - //} - //pub fn track_prev (&mut self) { - //use ArrangerSelection::*; - //*self = match self { - //Mix => Mix, - //Scene(s) => Scene(*s), - //Track(t) => if *t == 0 { Mix } else { Track(*t - 1) }, - //Clip(t, s) => if *t == 0 { Scene(*s) } else { Clip(t.saturating_sub(1), *s) } - //} - //} - //pub fn scene_next (&mut self, last_scene: usize) { - //use ArrangerSelection::*; - //*self = match self { - //Mix => Scene(0), - //Track(t) => Clip(*t, 0), - //Scene(s) => Scene(last_scene.min(*s + 1)), - //Clip(t, s) => Clip(*t, last_scene.min(*s + 1)), - //} - //} - //pub fn scene_prev (&mut self) { - //use ArrangerSelection::*; - //*self = match self { - //Mix => Mix, - //Track(t) => Track(*t), - //Scene(s) => if *s == 0 { Mix } else { Scene(*s - 1) }, - //Clip(t, s) => if *s == 0 { Track(*t) } else { Clip(*t, s.saturating_sub(1)) } - //} - //} - //pub fn arranger_menu_bar () -> MenuBar { //use ArrangerCommand as Cmd; //use ArrangerCommand as Edit; diff --git a/crates/tek_tui/src/tui_command.rs b/crates/tek_tui/src/tui_command.rs index 279397b6..5b64429d 100644 --- a/crates/tek_tui/src/tui_command.rs +++ b/crates/tek_tui/src/tui_command.rs @@ -136,14 +136,12 @@ pub enum PhrasesCommand { impl Command for PhrasesCommand { fn execute (self, state: &mut T) -> Perhaps { - use PhraseRenameCommand as Rename; - use PhraseLengthCommand as Length; Ok(match self { Self::Phrase(command) => command.execute(state)?.map(Self::Phrase), Self::Rename(command) => command.execute(state)?.map(Self::Rename), Self::Length(command) => command.execute(state)?.map(Self::Length), Self::Select(phrase) => { - state.phrase = phrase; + *state.phrase_index_mut() = phrase; None }, }) @@ -165,10 +163,15 @@ impl Command for PhraseLengthCommand { fn execute (self, state: &mut T) -> Perhaps { use PhraseLengthFocus::*; use PhraseLengthCommand::*; - if let Some(PhrasesMode::Length(phrase, ref mut length, ref mut focus)) = state.mode { + let mode = state.phrases_mode_mut(); + if let Some(PhrasesMode::Length( + phrase, + ref mut length, + ref mut focus, + )) = mode { match self { Self::Cancel => { - state.mode = None; + *state.phrases_mode_mut() = None; }, Self::Prev => { focus.prev() @@ -190,7 +193,7 @@ impl Command for PhraseLengthCommand { let mut phrase = state.phrases[phrase].write().unwrap(); let old_length = phrase.length; phrase.length = length; - state.mode = None; + *mode = None; return Ok(Some(Self::Set(old_length))) }, _ => unreachable!() @@ -219,7 +222,7 @@ where { fn execute (self, state: &mut T) -> Perhaps { use PhraseRenameCommand::*; - if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = state.phrases_mode() { + if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = state.phrases_mode_mut() { match self { Set(s) => { state.phrases()[*phrase].write().unwrap().name = s.into(); @@ -279,7 +282,7 @@ where use PhraseCommand::*; Ok(match self { ToggleDirection => { - state.mode = !state.mode; + state.phrase_mode_mut() = !state.mode; None }, EnterEditMode => { diff --git a/crates/tek_tui/src/tui_input.rs b/crates/tek_tui/src/tui_input.rs index 0b8ea811..f4dfcdc7 100644 --- a/crates/tek_tui/src/tui_input.rs +++ b/crates/tek_tui/src/tui_input.rs @@ -147,8 +147,16 @@ where key!(KeyCode::Up) => match state.selected() { Select::Mix => return None, Select::Track(t) => return None, - Select::Scene(s) => Select(Select::Scene(s - 1)), - Select::Clip(t, s) => Select(Select::Clip(t, s - 1)), + Select::Scene(s) => if s > 0 { + Select(Select::Scene(s - 1)) + } else { + Select(Select::Mix) + }, + Select::Clip(t, s) => if s > 0 { + Select(Select::Clip(t, s - 1)) + } else { + Select(Select::Track(t)) + }, }, key!(KeyCode::Down) => match state.selected() { @@ -160,9 +168,17 @@ where key!(KeyCode::Left) => match state.selected() { Select::Mix => return None, - Select::Track(t) => Select(Select::Track(t - 1)), + Select::Track(t) => if t > 0 { + Select(Select::Track(t - 1)) + } else { + Select(Select::Mix) + }, Select::Scene(s) => return None, - Select::Clip(t, s) => Select(Select::Clip(t - 1, s)), + Select::Clip(t, s) => if t > 0 { + Select(Select::Clip(t - 1, s)) + } else { + Select(Select::Scene(s)) + }, }, key!(KeyCode::Right) => match state.selected() { @@ -256,31 +272,31 @@ impl InputToCommand for PhrasesCommand { use PhrasePoolCommand as Phrase; use PhraseRenameCommand as Rename; use PhraseLengthCommand as Length; - let index = state.phrase(); + let index = state.phrase_index(); let count = state.phrases().len(); match input.event() { key!(KeyCode::Up) => Some(Self::Select(0)), key!(KeyCode::Down) => Some(Self::Select(0)), key!(KeyCode::Char(',')) => { if index > 1 { + *state.phrase_index_mut() -= 1; Some(Self::Phrase(Phrase::Swap(index - 1, index))) - //index -= 1; } else { None } }, key!(KeyCode::Char('.')) => { if index < count.saturating_sub(1) { + *state.phrase_index_mut() += 1; Some(Self::Phrase(Phrase::Swap(index + 1, index))) - //index += 1; } else { None } }, key!(KeyCode::Delete) => { if index > 0 { - Some(Self::Delete(index)) - //index = index.min(count.saturating_sub(1)); + *state.phrase_index_mut() = index.min(count.saturating_sub(1)); + Some(Self::Phrase(Phrase::Delete(index))) } else { None } @@ -288,7 +304,7 @@ impl InputToCommand for PhrasesCommand { key!(KeyCode::Char('a')) => Some(Self::Phrase(Phrase::Add(count))), key!(KeyCode::Char('i')) => Some(Self::Phrase(Phrase::Add(index + 1))), key!(KeyCode::Char('d')) => Some(Self::Phrase(Phrase::Duplicate(index))), - key!(KeyCode::Char('c')) => Some(Self::Phrase(Phrase::RandomColor(index))), + key!(KeyCode::Char('c')) => Some(Self::Phrase(Phrase::Color(index, ItemColor::random()))), key!(KeyCode::Char('n')) => Some(Self::Rename(Rename::Begin)), key!(KeyCode::Char('t')) => Some(Self::Length(Length::Begin)), _ => match state.phrases_mode() {