remove SequencerFocus

This commit is contained in:
🪞👃🪞 2024-12-15 16:34:25 +01:00
parent 2198d14a40
commit 33259d1526

View file

@ -1,7 +1,6 @@
use crate::{*, api::ClockCommand::{Play, Pause}}; use crate::{*, api::ClockCommand::{Play, Pause}};
use KeyCode::{Tab, BackTab, Char}; use KeyCode::{Tab, BackTab, Char};
use SequencerCommand::*; use SequencerCommand::*;
use SequencerFocus::*;
use PhraseCommand::*; use PhraseCommand::*;
/// Create app state from JACK handle. /// Create app state from JACK handle.
@ -28,7 +27,6 @@ impl TryFrom<&Arc<RwLock<JackClient>>> for SequencerTui {
midi_buf: vec![vec![];65536], midi_buf: vec![vec![];65536],
note_buf: vec![], note_buf: vec![],
perf: PerfModel::default(), perf: PerfModel::default(),
focus: SequencerFocus::PhraseEditor
}) })
} }
@ -46,24 +44,11 @@ pub struct SequencerTui {
pub split: u16, pub split: u16,
pub note_buf: Vec<u8>, pub note_buf: Vec<u8>,
pub midi_buf: Vec<Vec<Vec<u8>>>, pub midi_buf: Vec<Vec<Vec<u8>>>,
pub focus: SequencerFocus,
pub perf: PerfModel, pub perf: PerfModel,
} }
/// Sections in the sequencer app that may be focused
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum SequencerFocus {
/// The transport (toolbar) is focused
Transport(TransportFocus),
/// The phrase list (pool) is focused
PhraseList,
/// The phrase editor (sequencer) is focused
PhraseEditor,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum SequencerCommand { pub enum SequencerCommand {
Focus(FocusCommand<SequencerFocus>),
Clock(ClockCommand), Clock(ClockCommand),
Phrases(PhrasesCommand), Phrases(PhrasesCommand),
Editor(PhraseCommand), Editor(PhraseCommand),
@ -73,7 +58,6 @@ pub enum SequencerCommand {
impl Command<SequencerTui> for SequencerCommand { impl Command<SequencerTui> for SequencerCommand {
fn execute (self, state: &mut SequencerTui) -> Perhaps<Self> { fn execute (self, state: &mut SequencerTui) -> Perhaps<Self> {
Ok(match self { Ok(match self {
Self::Focus(cmd) => cmd.execute(state)?.map(Focus),
Self::Phrases(cmd) => { Self::Phrases(cmd) => {
match cmd { match cmd {
// autoselect: automatically load selected phrase in editor // autoselect: automatically load selected phrase in editor
@ -95,25 +79,13 @@ impl Command<SequencerTui> for SequencerCommand {
} }
} }
impl Command<SequencerTui> for FocusCommand<SequencerFocus> {
fn execute (self, state: &mut SequencerTui) -> Perhaps<FocusCommand<SequencerFocus>> {
// Focus commands can be received but are ignored.
//if let FocusCommand::Set(to) = self {
//state.set_focused(to);
//}
Ok(None)
}
}
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) to_sequencer_command(state, input)
.or_else(||to_focus_command(input).map(Focus))
} }
} }
pub fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option<SequencerCommand> { pub fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option<SequencerCommand> {
use super::app_transport::TransportCommand;
Some(match input.event() { Some(match input.event() {
// Enqueue currently edited phrase // Enqueue currently edited phrase
@ -202,11 +174,7 @@ render!(|self: SequencerTui|lay!([self.size, Tui::split_n(false, 5,
Tui::fixed_y(2, TransportView::from(( Tui::fixed_y(2, TransportView::from((
self, self,
self.player.play_phrase().as_ref().map(|(_,p)|p.as_ref().map(|p|p.read().unwrap().color)).flatten().clone(), self.player.play_phrase().as_ref().map(|(_,p)|p.as_ref().map(|p|p.read().unwrap().color)).flatten().clone(),
if let SequencerFocus::Transport(_) = self.focus { true
true
} else {
false
}
))), ))),
Tui::fill_xy(&self.editor) Tui::fill_xy(&self.editor)
]), ]),
@ -280,15 +248,6 @@ impl PhraseSelector {
} }
} }
impl TransportControl<SequencerFocus> for SequencerTui {
fn transport_focused (&self) -> Option<TransportFocus> {
match self.focus {
SequencerFocus::Transport(focus) => Some(focus),
_ => None
}
}
}
has_clock!(|self:SequencerTui|&self.clock); has_clock!(|self:SequencerTui|&self.clock);
has_phrases!(|self:SequencerTui|self.phrases.phrases); has_phrases!(|self:SequencerTui|self.phrases.phrases);
has_editor!(|self:SequencerTui|self.editor); has_editor!(|self:SequencerTui|self.editor);
@ -308,25 +267,6 @@ impl HasPhraseList for SequencerTui {
} }
} }
impl Into<Option<TransportFocus>> for SequencerFocus {
fn into (self) -> Option<TransportFocus> {
if let Self::Transport(transport) = self {
Some(transport)
} else {
None
}
}
}
impl From<&SequencerTui> for Option<TransportFocus> {
fn from (state: &SequencerTui) -> Self {
match state.focus {
Transport(focus) => Some(focus),
_ => None
}
}
}
impl Handle<Tui> for SequencerTui { impl Handle<Tui> for SequencerTui {
fn handle (&mut self, i: &TuiInput) -> Perhaps<bool> { fn handle (&mut self, i: &TuiInput) -> Perhaps<bool> {
SequencerCommand::execute_with_state(self, i) SequencerCommand::execute_with_state(self, i)