mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
80 lines
3.4 KiB
Rust
80 lines
3.4 KiB
Rust
include!("./lib.rs");
|
|
pub fn main () -> Usually<()> { GrooveboxCli::parse().run() }
|
|
#[derive(Debug, Parser)]
|
|
#[command(version, about, long_about = None)]
|
|
pub struct GrooveboxCli {
|
|
/// Name of JACK client
|
|
#[arg(short, long)]
|
|
name: Option<String>,
|
|
/// Whether to include a transport toolbar (default: true)
|
|
#[arg(short, long, default_value_t = true)]
|
|
transport: bool,
|
|
/// Whether to attempt to become transport master
|
|
#[arg(short, long, default_value_t = true)]
|
|
sync: bool,
|
|
/// MIDI outs to connect to MIDI input
|
|
#[arg(short='i', long)]
|
|
midi_from: Vec<String>,
|
|
/// MIDI ins to connect from MIDI output
|
|
#[arg(short='o', long)]
|
|
midi_to: Vec<String>,
|
|
/// Audio outs to connect to left input
|
|
#[arg(short='l', long)]
|
|
l_from: Vec<String>,
|
|
/// Audio outs to connect to right input
|
|
#[arg(short='r', long)]
|
|
r_from: Vec<String>,
|
|
/// Audio ins to connect from left output
|
|
#[arg(short='L', long)]
|
|
l_to: Vec<String>,
|
|
/// Audio ins to connect from right output
|
|
#[arg(short='R', long)]
|
|
r_to: Vec<String>,
|
|
}
|
|
impl GrooveboxCli {
|
|
fn run (&self) -> Usually<()> {
|
|
Tui::run(JackClient::new("tek_groovebox")?.activate_with(|jack|{
|
|
let app = tek::GrooveboxTui::try_from(jack)?;
|
|
jack.read().unwrap().client().connect_ports(&app.player.midi_outs[0], &app.sampler.midi_in)?;
|
|
jack.connect_midi_from(&app.player.midi_ins[0], &self.midi_from)?;
|
|
jack.connect_midi_from(&app.sampler.midi_in, &self.midi_from)?;
|
|
jack.connect_midi_to(&app.player.midi_outs[0], &self.midi_to)?;
|
|
jack.connect_audio_from(&app.sampler.audio_ins[0], &self.l_from)?;
|
|
jack.connect_audio_from(&app.sampler.audio_ins[1], &self.r_from)?;
|
|
jack.connect_audio_to(&app.sampler.audio_outs[0], &self.l_to)?;
|
|
jack.connect_audio_to(&app.sampler.audio_outs[1], &self.r_to)?;
|
|
if self.sync {
|
|
jack.read().unwrap().client().register_timebase_callback(false, |state|{
|
|
let ::jack::contrib::TimebaseInfo { state, new_pos, nframes, mut position } = state;
|
|
if new_pos {
|
|
app.clock().playhead.update_from_sample(position.frame() as f64)
|
|
} else {
|
|
println!("\n\r{state:?} {new_pos} {nframes} {position:?}");
|
|
let pulse = app.clock().playhead.pulse.get() as i32;
|
|
let ppq = app.clock().timebase.ppq.get() as i32;
|
|
let bpm = app.clock().timebase.bpm.get();
|
|
position.bbt = Some(::jack::contrib::PositionBBT {
|
|
bar: 1 + (pulse / ppq) / 4,
|
|
beat: 1 + (pulse / ppq) % 4,
|
|
tick: (pulse % ppq),
|
|
bar_start_tick: 0.,
|
|
beat_type: 4.,
|
|
beats_per_bar: 4.,
|
|
beats_per_minute: bpm,
|
|
ticks_per_beat: ppq as f64
|
|
});
|
|
println!("\n\r{:?}", position.bbt);
|
|
}
|
|
position
|
|
})?
|
|
}
|
|
Ok(app)
|
|
})?)?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[test] fn verify_groovebox_cli () {
|
|
use clap::CommandFactory;
|
|
GrooveboxCli::command().debug_assert();
|
|
}
|