Arranger -> Arrangement; ArrangerStandalone -> Arranger

This commit is contained in:
🪞👃🪞 2024-10-06 03:14:24 +03:00
parent 11a66ee415
commit a6b08a3249
5 changed files with 166 additions and 165 deletions

View file

@ -1,6 +1,5 @@
include!("lib.rs");
use tek_core::clap::{self, Parser};
pub fn main () -> Usually<()> { ArrangerCli::parse().run() }
/// Parses CLI arguments to the `tek_arranger` invocation.
@ -27,14 +26,14 @@ impl ArrangerCli {
let jack = JackClient::Inactive(
Client::new("tek_arranger", ClientOptions::NO_START_SERVER)?.0
);
let mut arranger = Arranger::new("");
let mut arrangement = Arrangement::new("");
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();
*arrangement.name.write().unwrap() = name.clone();
}
for _ in 0..self.tracks {
let track = arranger.track_add(None)?;
let track = arrangement.track_add(None)?;
for _ in 0..self.scenes {
track.phrases.push(
Arc::new(RwLock::new(Phrase::new("", true, PPQ * 4, None)))
@ -42,7 +41,7 @@ impl ArrangerCli {
}
}
for _ in 0..self.scenes {
let _scene = arranger.scene_add(None)?;
let _scene = arrangement.scene_add(None)?;
//for i in 0..self.tracks {
//scene.clips[i] = Some(i);
//}
@ -57,137 +56,14 @@ impl ArrangerCli {
}
)?
);
Tui::run(Arc::new(RwLock::new(ArrangerStandalone {
Tui::run(Arc::new(RwLock::new(Arranger {
transport: self.transport.then_some(transport),
show_sequencer: Some(tek_core::Direction::Down),
arranger,
arrangement,
focus: 0,
sequencer_proxy: SequencerProxy(Default::default(), false)
sequencer_proxy: SequencerProxy(Default::default(), false),
modal: None
})))?;
Ok(())
}
}
/// Root level object for standalone `tek_arranger`
struct ArrangerStandalone<E: Engine> {
/// Controls the JACK transport.
transport: Option<Arc<RwLock<TransportToolbar<E>>>>,
/// Contains all the sequencers.
arranger: Arranger<E>,
/// This allows the sequencer view to be moved or hidden.
show_sequencer: Option<tek_core::Direction>,
/// Index of currently focused component
focus: usize,
/// 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;
fn content (&self) -> impl Widget<Engine = Tui> {
Layers::new(move|add|{
add(&Stack::down(move|add|{
add(&self.transport)?;
if let (Some(direction), Some(sequencer)) = (
self.show_sequencer,
self.arranger.sequencer(),
) {
let arranger = &self.arranger as &dyn Widget<Engine = Tui>;
let sequencer = sequencer as &dyn Widget<Engine = Tui>;
add(&Split::new(direction, 20, arranger, sequencer.min_y(20)))
} else {
add(&self.arranger)
}
}))?;
if let Some(ref modal) = self.arranger.modal {
add(&Background(COLOR_BG1))?;
add(&Foreground(COLOR_BG2))?;
//add(modal as &dyn Widget<Engine = Tui>)?;
}
Ok(())
})
}
}
/// Handle top-level events in standalone arranger.
impl Handle<Tui> for ArrangerStandalone<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
let focus = self.focus;
let is_first_row = self.arranger.is_first_row();
let is_last_row = self.arranger.is_last_row();
let mut focused_handle = || {
if focus == 2 {
self.arranger.sequencer_mut().handle(from)
} else {
self.focused_mut().handle(from)
}
};
match from.event() {
key!(KeyCode::Char(' ')) => {
if let Some(ref mut transport) = self.transport {
transport.write().unwrap().toggle_play()?;
} else {
return Ok(None)
}
},
key!(KeyCode::Tab) => {
self.focus_next();
},
key!(KeyCode::BackTab) => {
self.focus_prev();
},
key!(KeyCode::Down) => {
if focus == 0 {
self.focus_next();
} else if focus == 1 && is_last_row {
self.focus_next();
} else {
return focused_handle()
}
},
key!(KeyCode::Up) => {
if focus == 1 && is_first_row {
self.focus_prev();
} else {
return focused_handle()
}
},
_ => return focused_handle()
}
Ok(Some(true))
}
}
/// Focusable items in standalone arranger.
impl Focus<3, Tui> for ArrangerStandalone<Tui> {
fn focus (&self) -> usize {
self.focus
}
fn focus_mut (&mut self) -> &mut usize {
&mut self.focus
}
fn focusable (&self) -> [&dyn Focusable<Tui>;3] {
focusables!(self.transport, self.arranger, self.sequencer_proxy)
}
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;3] {
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 }
}