mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
main_ -> _cli
This commit is contained in:
parent
9b8a14df0e
commit
323a8aeb5f
4 changed files with 15 additions and 15 deletions
180
crates/tek_sequencer/src/arranger_cli.rs
Normal file
180
crates/tek_sequencer/src/arranger_cli.rs
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
include!("lib.rs");
|
||||
use tek_core::clap::{self, Parser};
|
||||
|
||||
pub fn main () -> Usually<()> { ArrangerCli::parse().run() }
|
||||
|
||||
/// Parses CLI arguments to the `tek_arranger` invocation.
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct ArrangerCli {
|
||||
/// Name of JACK client
|
||||
#[arg(short, long)]
|
||||
name: Option<String>,
|
||||
/// Pulses per quarter note (arruencer resolution; default: 96)
|
||||
#[arg(short, long)]
|
||||
ppq: Option<usize>,
|
||||
/// Whether to include a transport toolbar (default: true)
|
||||
#[arg(short, long, default_value_t = true)]
|
||||
transport: bool,
|
||||
/// Number of tracks
|
||||
#[arg(short = 'x', long, default_value_t = 8)]
|
||||
tracks: usize,
|
||||
/// Number of scenes
|
||||
#[arg(short, long, default_value_t = 8)]
|
||||
scenes: usize,
|
||||
}
|
||||
|
||||
impl ArrangerCli {
|
||||
/// Run the arranger TUI from CLI arguments.
|
||||
fn run (&self) -> Usually<()> {
|
||||
let jack = JackClient::Inactive(
|
||||
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()))
|
||||
);
|
||||
if let Some(name) = self.name.as_ref() {
|
||||
*arranger.name.write().unwrap() = name.clone();
|
||||
}
|
||||
for _ in 0..self.tracks {
|
||||
let track = arranger.track_add(None)?;
|
||||
for _ in 0..self.scenes {
|
||||
track.phrases.push(
|
||||
Arc::new(RwLock::new(Phrase::new("", 96 * 4, None)))
|
||||
);
|
||||
}
|
||||
}
|
||||
for _ in 0..self.scenes {
|
||||
let _scene = arranger.scene_add(None)?;
|
||||
//for i in 0..self.tracks {
|
||||
//scene.clips[i] = Some(i);
|
||||
//}
|
||||
}
|
||||
transport.set_focused(true);
|
||||
Tui::run(Arc::new(RwLock::new(ArrangerStandalone {
|
||||
transport,
|
||||
show_sequencer: Some(tek_core::Direction::Down),
|
||||
arranger,
|
||||
focus: 0,
|
||||
sequencer_proxy: SequencerProxy(Default::default(), false)
|
||||
})))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
/// Root level object for standalone `tek_arranger`
|
||||
struct ArrangerStandalone<E: Engine> {
|
||||
/// Controls the JACK transport.
|
||||
transport: Option<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.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 }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue