diff --git a/crates/tek_sequencer/src/arranger_main.rs b/crates/tek_sequencer/src/arranger_main.rs index 3dff0276..dee5272f 100644 --- a/crates/tek_sequencer/src/arranger_main.rs +++ b/crates/tek_sequencer/src/arranger_main.rs @@ -7,9 +7,9 @@ pub fn main () -> Usually<()> { Ok(()) } -struct ArrangerStandalone { +struct ArrangerStandalone { /// Contains all the sequencers. - arranger: Arranger, + arranger: Arranger, /// Controls the JACK transport. transport: Option, /// This allows the sequencer view to be moved or hidden. @@ -18,8 +18,6 @@ struct ArrangerStandalone { focus: usize, } -focus!(ArrangerStandalone (focus) : 2 => [ transport, arranger ]); - #[derive(Debug, Parser)] #[command(version, about, long_about = None)] pub struct ArrangerCli { @@ -40,7 +38,7 @@ pub struct ArrangerCli { scenes: usize, } -impl ArrangerStandalone { +impl ArrangerStandalone { pub fn from_args () -> Usually { let args = ArrangerCli::parse(); let mut arranger = Arranger::new(""); @@ -75,7 +73,7 @@ impl ArrangerStandalone { } } -impl Render for ArrangerStandalone { +impl Render for ArrangerStandalone { fn render (&self, to: &mut Tui) -> Perhaps { let area = to.area(); let sequencer = self.arranger.sequencer(); @@ -94,55 +92,73 @@ impl Render for ArrangerStandalone { } } -impl Handle for ArrangerStandalone { - fn handle (&mut self, e: &AppEvent) -> Usually { - match e { - AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Char(' '), .. })) => { +impl Handle for ArrangerStandalone { + fn handle (&mut self, from: &Tui) -> Perhaps { + match from.event() { + key!(KeyCode::Char(' ')) => { if let Some(ref mut transport) = self.transport { transport.toggle_play()?; - Ok(true) + Ok(Some(true)) } else { - Ok(false) + Ok(None) } }, - AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Tab, .. })) => { - self.focus_next(); - Ok(true) + key!(KeyCode::Tab) => { + self.arranger.focus_next(); + Ok(Some(true)) }, - AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::BackTab, .. })) => { - self.focus_prev(); - Ok(true) + key!(KeyCode::BackTab) => { + self.arranger.focus_prev(); + Ok(Some(true)) }, - AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Down, .. })) => { + key!(KeyCode::Down) => { if self.focus == 0 || ( self.focus == 1 && self.arranger.is_last_row() ) { - self.focus_next(); - Ok(true) + self.arranger.focus_next(); + Ok(Some(true)) } else { - self.focused_mut().handle(e) + self.arranger.focused_mut().handle(from) } }, - AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Up, .. })) => { + key!(KeyCode::Up) => { if self.focus == 1 && self.arranger.is_first_row() { - self.focus_prev(); - Ok(true) + self.arranger.focus_prev(); + Ok(Some(true)) } else { - self.focused_mut().handle(e) + self.arranger.focused_mut().handle(from) } }, - _ => self.focused_mut().handle(e) + _ => self.arranger.focused_mut().handle(from) } } } -struct SequencerProxy(Arc>); +struct SequencerProxy(Arc>>); -impl Handle for SequencerProxy { - fn handle (&mut self, e: &AppEvent) -> Usually { - match self.0.write().unwrap().sequencer_mut() { - Some(sequencer) => sequencer.handle(e), - None => Ok(false) - } +impl Handle for SequencerProxy { + fn handle (&mut self, from: &Tui) -> Perhaps { + self.0.write().unwrap().handle(from) + } +} + +impl Focus<2, E: Engine> for ArrangerStandalone { + fn focus (&self) -> usize { + self.focus + } + fn focus_mut (&mut self) -> &mut usize { + &mut self.focus + } + fn focusable (&self) -> [&dyn Focusable;2] { + [ + &self.transport as &dyn Focusable, + &self.arranger as &dyn Focusable, + ] + } + fn focusable_mut (&mut self) -> [&mut dyn Focusable;2] { + [ + &mut self.transport as &mut dyn Focusable, + &mut self.arranger as &mut dyn Focusable, + ] } }