reenable transport roll in arranger

This commit is contained in:
🪞👃🪞 2024-10-06 02:37:50 +03:00
parent 323a8aeb5f
commit 0da54db5e0
2 changed files with 31 additions and 6 deletions

View file

@ -54,6 +54,15 @@ impl<F: Focusable<E>, E: Engine> Focusable<E> for Option<F>
}
}
impl<F: Focusable<E>, E: Engine> Focusable<E> for Arc<RwLock<F>> {
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 => [

View file

@ -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<RwLock<TransportToolbar<Tui>>>, 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<E: Engine> {
/// Controls the JACK transport.
transport: Option<TransportToolbar<E>>,
transport: Option<Arc<RwLock<TransportToolbar<E>>>>,
/// Contains all the sequencers.
arranger: Arranger<E>,
/// This allows the sequencer view to be moved or hidden.
@ -75,6 +84,7 @@ struct ArrangerStandalone<E: Engine> {
/// Focus target that passes events down to sequencer
sequencer_proxy: SequencerProxy<E>,
}
/// The standalone arranger consists of transport, clip grid, and sequencer.
impl Content for ArrangerStandalone<Tui> {
type Engine = Tui;
@ -102,6 +112,7 @@ impl Content for ArrangerStandalone<Tui> {
})
}
}
/// Handle top-level events in standalone arranger.
impl Handle<Tui> for ArrangerStandalone<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
@ -118,7 +129,7 @@ impl Handle<Tui> for ArrangerStandalone<Tui> {
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<Tui> for ArrangerStandalone<Tui> {
Ok(Some(true))
}
}
/// Focusable items in standalone arranger.
impl Focus<3, Tui> for ArrangerStandalone<Tui> {
fn focus (&self) -> usize {
@ -165,15 +177,19 @@ impl Focus<3, Tui> for ArrangerStandalone<Tui> {
focusables_mut!(self.transport, self.arranger, self.sequencer_proxy)
}
}
#[derive(Default)]
struct SequencerProxy<E: Engine>(PhantomData<E>, bool);
impl Handle<Tui> for SequencerProxy<Tui> {
fn handle (&mut self, _: &TuiInput) -> Perhaps<bool> { unreachable!() }
}
impl Content for SequencerProxy<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { "" }
}
impl Focusable<Tui> for SequencerProxy<Tui> {
fn is_focused (&self) -> bool { self.1 }
fn set_focused (&mut self, focus: bool) { self.1 = focus }