mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
put all of arranger/sequencer/transport in 1 file
This commit is contained in:
parent
3042e9e3a8
commit
6f988e5072
12 changed files with 1877 additions and 1847 deletions
|
|
@ -1,152 +0,0 @@
|
|||
include!("lib.rs");
|
||||
|
||||
use tek_core::clap::{self, Parser};
|
||||
|
||||
pub fn main () -> Usually<()> {
|
||||
Tui::run(Arc::new(RwLock::new(crate::ArrangerStandalone::from_args()?)))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct ArrangerStandalone<E: Engine> {
|
||||
/// Contains all the sequencers.
|
||||
arranger: Arranger<E>,
|
||||
/// Controls the JACK transport.
|
||||
transport: Option<TransportToolbar<E>>,
|
||||
/// This allows the sequencer view to be moved or hidden.
|
||||
show_sequencer: Option<tek_core::Direction>,
|
||||
///
|
||||
focus: usize,
|
||||
}
|
||||
|
||||
#[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)]
|
||||
transport: Option<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 ArrangerStandalone<Tui> {
|
||||
pub fn from_args () -> Usually<Self> {
|
||||
let args = ArrangerCli::parse();
|
||||
let mut arranger = Arranger::new("");
|
||||
let mut transport = match args.transport {
|
||||
Some(true) => Some(TransportToolbar::new(None)),
|
||||
_ => None
|
||||
};
|
||||
if let Some(name) = args.name {
|
||||
*arranger.name.write().unwrap() = name.clone();
|
||||
}
|
||||
for _ in 0..args.tracks {
|
||||
let track = arranger.track_add(None)?;
|
||||
for _ in 0..args.scenes {
|
||||
track.phrases.push(
|
||||
Arc::new(RwLock::new(Phrase::new("", 96 * 4, None)))
|
||||
);
|
||||
}
|
||||
}
|
||||
for _ in 0..args.scenes {
|
||||
let _scene = arranger.scene_add(None)?;
|
||||
//for i in 0..args.tracks {
|
||||
//scene.clips[i] = Some(i);
|
||||
//}
|
||||
}
|
||||
transport.set_focused(true);
|
||||
Ok(ArrangerStandalone {
|
||||
transport,
|
||||
show_sequencer: Some(tek_core::Direction::Down),
|
||||
arranger,
|
||||
focus: 0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Content for ArrangerStandalone<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
Split::down(|add|{
|
||||
add(&self.transport)?;
|
||||
add(&self.arranger)?;
|
||||
if let Some(sequencer) = self.arranger.sequencer() {
|
||||
add(sequencer)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
//if let Some(ref modal) = self.arranger.modal {
|
||||
//to.fill_bg(area, Nord::bg_lo(false, false));
|
||||
//to.fill_fg(area, Nord::bg_hi(false, false));
|
||||
//modal.render(to)?;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for ArrangerStandalone<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
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 self.focus == 0 || (
|
||||
self.focus == 1 && self.arranger.is_last_row()
|
||||
) {
|
||||
self.focus_next();
|
||||
} else {
|
||||
return self.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
key!(KeyCode::Up) => {
|
||||
if self.focus == 1 && self.arranger.is_first_row() {
|
||||
self.focus_prev();
|
||||
} else {
|
||||
return self.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
_ => return self.focused_mut().handle(from)
|
||||
}
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
|
||||
impl Focus<2, 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>;2] {
|
||||
[
|
||||
&self.transport as &dyn Focusable<Tui>,
|
||||
&self.arranger as &dyn Focusable<Tui>,
|
||||
]
|
||||
}
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;2] {
|
||||
[
|
||||
&mut self.transport as &mut dyn Focusable<Tui>,
|
||||
&mut self.arranger as &mut dyn Focusable<Tui>,
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue