From 9b770c468fa9e93acf96858638e7c28ed1a62652 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 9 Nov 2024 01:17:41 +0100 Subject: [PATCH] wip: global enter --- crates/tek_core/src/focus.rs | 2 ++ crates/tek_sequencer/src/arranger.rs | 3 ++ crates/tek_sequencer/src/arranger_cmd.rs | 24 +++++++-------- crates/tek_sequencer/src/arranger_tui.rs | 36 ++++++++++++++--------- crates/tek_sequencer/src/sequencer_cmd.rs | 2 ++ crates/tek_sequencer/src/sequencer_tui.rs | 4 +-- 6 files changed, 43 insertions(+), 28 deletions(-) diff --git a/crates/tek_core/src/focus.rs b/crates/tek_core/src/focus.rs index f0a74607..203da85b 100644 --- a/crates/tek_core/src/focus.rs +++ b/crates/tek_core/src/focus.rs @@ -8,6 +8,8 @@ pub enum FocusCommand { Down, Left, Right, + Enter, + Exit } pub trait FocusGrid { diff --git a/crates/tek_sequencer/src/arranger.rs b/crates/tek_sequencer/src/arranger.rs index a9420955..a5d2b510 100644 --- a/crates/tek_sequencer/src/arranger.rs +++ b/crates/tek_sequencer/src/arranger.rs @@ -74,6 +74,8 @@ pub struct Arrangement { pub color: ItemColor, /// Width and height of arrangement area at last render pub size: Measure, + /// Whether this is currently in edit mode + pub entered: bool, } /// Represents a track in the arrangement pub struct ArrangementTrack { @@ -308,6 +310,7 @@ impl Arrangement { focused: false, color: Color::Rgb(28, 35, 25).into(), size: Measure::new(), + entered: false, } } fn is_stopped (&self) -> bool { diff --git a/crates/tek_sequencer/src/arranger_cmd.rs b/crates/tek_sequencer/src/arranger_cmd.rs index 6ea39c5f..287d63bd 100644 --- a/crates/tek_sequencer/src/arranger_cmd.rs +++ b/crates/tek_sequencer/src/arranger_cmd.rs @@ -2,12 +2,7 @@ use crate::*; #[derive(Clone, PartialEq)] pub enum ArrangerCommand { - FocusNext, - FocusPrev, - FocusUp, - FocusDown, - FocusLeft, - FocusRight, + Focus(FocusCommand), Transport(TransportCommand), Phrases(PhrasePoolCommand), Editor(PhraseEditorCommand), @@ -41,13 +36,18 @@ pub enum ArrangementCommand { impl Command> for ArrangerCommand { fn execute (self, state: &mut Arranger) -> Perhaps { use ArrangerCommand::*; + use FocusCommand::*; match self { - FocusNext => { state.focus_next(); }, - FocusPrev => { state.focus_prev(); }, - FocusUp => { state.focus_up(); }, - FocusDown => { state.focus_down(); }, - FocusLeft => { state.focus_left(); }, - FocusRight => { state.focus_right(); }, + Focus(command) => match command { + Next => { state.focus_next(); }, + Prev => { state.focus_prev(); }, + Up => { state.focus_up(); }, + Down => { state.focus_down(); }, + Left => { state.focus_left(); }, + Right => { state.focus_right(); }, + Enter => { unimplemented!() }, + Exit => { unimplemented!() }, + }, Transport(cmd) => if let Some(ref transport) = state.transport { return cmd.execute(&mut*transport.write().unwrap()).map(|x|x.map(Transport)) }, diff --git a/crates/tek_sequencer/src/arranger_tui.rs b/crates/tek_sequencer/src/arranger_tui.rs index 27f7fa66..50224259 100644 --- a/crates/tek_sequencer/src/arranger_tui.rs +++ b/crates/tek_sequencer/src/arranger_tui.rs @@ -23,7 +23,11 @@ impl Content for Arranger { lay!( widget(&self.arrangement).grow_y(1).border(border), widget(&self.arrangement.size), - widget(&"[ ] Arrangement").fg(title_color).push_x(1), + widget(&format!("[{}] Arrangement", if self.arrangement.entered { + "■" + } else { + " " + })).fg(title_color).push_x(1), ), Split::right( self.phrases_split, @@ -544,30 +548,34 @@ impl Handle for Arrangement { } impl MatchInput> for ArrangerCommand { fn match_input (state: &Arranger, input: &TuiInput) -> Option { + use FocusCommand::*; + use ArrangerCommand::*; match input.event() { - key!(KeyCode::Tab) => Some(Self::FocusNext), - key!(Shift-KeyCode::Tab) => Some(Self::FocusPrev), - key!(KeyCode::BackTab) => Some(Self::FocusPrev), - key!(Shift-KeyCode::BackTab) => Some(Self::FocusPrev), - key!(KeyCode::Up) => Some(Self::FocusUp), - key!(KeyCode::Down) => Some(Self::FocusDown), - key!(KeyCode::Left) => Some(Self::FocusLeft), - key!(KeyCode::Right) => Some(Self::FocusRight), - key!(KeyCode::Char(' ')) => Some(Self::Transport(TransportCommand::PlayToggle)), + key!(KeyCode::Tab) => Some(Focus(Next)), + key!(Shift-KeyCode::Tab) => Some(Focus(Prev)), + key!(KeyCode::BackTab) => Some(Focus(Prev)), + key!(Shift-KeyCode::BackTab) => Some(Focus(Prev)), + key!(KeyCode::Up) => Some(Focus(Up)), + key!(KeyCode::Down) => Some(Focus(Down)), + key!(KeyCode::Left) => Some(Focus(Left)), + key!(KeyCode::Right) => Some(Focus(Right)), + key!(KeyCode::Enter) => Some(Focus(Enter)), + key!(KeyCode::Esc) => Some(Focus(Exit)), + key!(KeyCode::Char(' ')) => Some(Transport(TransportCommand::PlayToggle)), _ => match state.focused() { ArrangerFocus::Transport => state.transport.as_ref() .map(|t|TransportCommand::match_input(&*t.read().unwrap(), input) - .map(Self::Transport)) + .map(Transport)) .flatten(), ArrangerFocus::PhrasePool => PhrasePoolCommand::match_input(&*state.phrases.read().unwrap(), input) - .map(Self::Phrases), + .map(Phrases), ArrangerFocus::PhraseEditor => PhraseEditorCommand::match_input(&state.editor, input) - .map(Self::Editor), + .map(Editor), ArrangerFocus::Arrangement => ArrangementCommand::match_input(&state.arrangement, &input) - .map(Self::Arrangement) + .map(Arrangement) } } } diff --git a/crates/tek_sequencer/src/sequencer_cmd.rs b/crates/tek_sequencer/src/sequencer_cmd.rs index 8a0084f0..ab3710eb 100644 --- a/crates/tek_sequencer/src/sequencer_cmd.rs +++ b/crates/tek_sequencer/src/sequencer_cmd.rs @@ -83,6 +83,8 @@ impl Command> for SequencerCommand { Down => { state.focus_down(); }, Left => { state.focus_left(); }, Right => { state.focus_right(); }, + Enter => { unimplemented!() }, + Exit => { unimplemented!() } }, Transport(command) => if let Some(ref transport) = state.transport { return command.execute(&mut*transport.write().unwrap()).map(|x|x.map(Transport)) diff --git a/crates/tek_sequencer/src/sequencer_tui.rs b/crates/tek_sequencer/src/sequencer_tui.rs index 609eaf02..0fd2eb68 100644 --- a/crates/tek_sequencer/src/sequencer_tui.rs +++ b/crates/tek_sequencer/src/sequencer_tui.rs @@ -79,7 +79,7 @@ impl Content for PhrasePool { let border = Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color)); let content = content.fill_xy().bg(Color::Rgb(28, 35, 25)).border(border); let title_color = if *focused {Color::Rgb(150, 160, 90)} else {Color::Rgb(120, 130, 100)}; - let title = format!("[ ] Phrases ({})", phrases.len()); + let title = format!("[{}] Phrases ({})", phrases.len(), " "); let title = TuiStyle::fg(title, title_color).push_x(1); Layers::new(move|add|{ add(&content)?; Ok(add(&title)?) }) } @@ -267,7 +267,7 @@ impl Content for PhraseEditor { let piano_roll = row!(keys, note_area).fill_x(); let content = piano_roll.bg(Color::Rgb(40, 50, 30)).border(border); let content = lay!(content, playhead); - let mut upper_left = format!("[ ] Sequencer"); + let mut upper_left = format!("[{}] Sequencer", if *entered {"■"} else {" "}); if let Some(phrase) = phrase { upper_left = format!("{upper_left}: {}", phrase.read().unwrap().name); }