From 0da54db5e0f3310f32e1a61abde154dfa76740cd Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 6 Oct 2024 02:37:50 +0300 Subject: [PATCH] reenable transport roll in arranger --- crates/tek_core/src/focus.rs | 9 ++++++++ crates/tek_sequencer/src/arranger_cli.rs | 28 +++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/tek_core/src/focus.rs b/crates/tek_core/src/focus.rs index 103f1ced..42da8ce5 100644 --- a/crates/tek_core/src/focus.rs +++ b/crates/tek_core/src/focus.rs @@ -54,6 +54,15 @@ impl, E: Engine> Focusable for Option } } +impl, E: Engine> Focusable for Arc> { + fn is_focused (&self) -> bool { + self.read().unwrap().is_focused() + } + fn set_focused (&mut self, focused: bool) { + self.write().unwrap().set_focused(focused) + } +} + /// Implement the [Focus] trait for a component. #[macro_export] macro_rules! focus { ($struct:ident ($focus:ident) : $count:expr => [ diff --git a/crates/tek_sequencer/src/arranger_cli.rs b/crates/tek_sequencer/src/arranger_cli.rs index 467ab125..1cc4a841 100644 --- a/crates/tek_sequencer/src/arranger_cli.rs +++ b/crates/tek_sequencer/src/arranger_cli.rs @@ -31,9 +31,8 @@ impl ArrangerCli { Client::new("tek_arranger", ClientOptions::NO_START_SERVER)?.0 ); let mut arranger = Arranger::new(""); - let mut transport = self.transport.then_some( - TransportToolbar::new(Some(jack.transport())) - ); + let jack_transport = jack.transport(); + let mut transport = TransportToolbar::new(Some(jack_transport)); if let Some(name) = self.name.as_ref() { *arranger.name.write().unwrap() = name.clone(); } @@ -52,8 +51,17 @@ impl ArrangerCli { //} } transport.set_focused(true); + let transport = Arc::new(RwLock::new(transport)); + transport.write().unwrap().jack = Some( + jack.activate( + &transport.clone(), + |state: &Arc>>, client, scope| { + state.write().unwrap().process(client, scope) + } + )? + ); Tui::run(Arc::new(RwLock::new(ArrangerStandalone { - transport, + transport: self.transport.then_some(transport), show_sequencer: Some(tek_core::Direction::Down), arranger, focus: 0, @@ -62,10 +70,11 @@ impl ArrangerCli { Ok(()) } } + /// Root level object for standalone `tek_arranger` struct ArrangerStandalone { /// Controls the JACK transport. - transport: Option>, + transport: Option>>>, /// Contains all the sequencers. arranger: Arranger, /// This allows the sequencer view to be moved or hidden. @@ -75,6 +84,7 @@ struct ArrangerStandalone { /// Focus target that passes events down to sequencer sequencer_proxy: SequencerProxy, } + /// The standalone arranger consists of transport, clip grid, and sequencer. impl Content for ArrangerStandalone { type Engine = Tui; @@ -102,6 +112,7 @@ impl Content for ArrangerStandalone { }) } } + /// Handle top-level events in standalone arranger. impl Handle for ArrangerStandalone { fn handle (&mut self, from: &TuiInput) -> Perhaps { @@ -118,7 +129,7 @@ impl Handle for ArrangerStandalone { match from.event() { key!(KeyCode::Char(' ')) => { if let Some(ref mut transport) = self.transport { - transport.toggle_play()?; + transport.write().unwrap().toggle_play()?; } else { return Ok(None) } @@ -150,6 +161,7 @@ impl Handle for ArrangerStandalone { Ok(Some(true)) } } + /// Focusable items in standalone arranger. impl Focus<3, Tui> for ArrangerStandalone { fn focus (&self) -> usize { @@ -165,15 +177,19 @@ impl Focus<3, Tui> for ArrangerStandalone { focusables_mut!(self.transport, self.arranger, self.sequencer_proxy) } } + #[derive(Default)] struct SequencerProxy(PhantomData, bool); + impl Handle for SequencerProxy { fn handle (&mut self, _: &TuiInput) -> Perhaps { unreachable!() } } + impl Content for SequencerProxy { type Engine = Tui; fn content (&self) -> impl Widget { "" } } + impl Focusable for SequencerProxy { fn is_focused (&self) -> bool { self.1 } fn set_focused (&mut self, focus: bool) { self.1 = focus }