simplify track construction

This commit is contained in:
🪞👃🪞 2025-05-10 18:49:03 +03:00
parent c78b2dc9de
commit c5586c3a35
2 changed files with 18 additions and 29 deletions

View file

@ -23,36 +23,23 @@ has_player!(|self: Track|self.player);
impl Track {
pub const MIN_WIDTH: usize = 9;
/// Create a new track containing a sequencer.
pub fn new_sequencer () -> Self {
let mut track = Self::default();
track.devices.push(Device::Sequencer(MidiPlayer::default()));
track
/// Create a new track with only the default [MidiPlayer].
pub fn new () -> Self {
Self::default()
}
/// Create a new track containing a sequencer and sampler.
pub fn new_groovebox (
/// Create a new track connecting the [MidiPlayer] to a [Sampler].
pub fn new_with_sampler (
jack: &Jack,
midi_from: &[PortConnect],
audio_from: &[&[PortConnect];2],
audio_to: &[&[PortConnect];2],
) -> Usually<Self> {
let mut track = Self::new_sequencer();
track.devices.push(Device::Sampler(
Sampler::new(jack, &"sampler", midi_from, audio_from, audio_to)?
));
Ok(track)
}
/// Create a new track containing a sampler.
pub fn new_sampler (
jack: &Jack,
midi_from: &[PortConnect],
audio_from: &[&[PortConnect];2],
audio_to: &[&[PortConnect];2],
) -> Usually<Self> {
let mut track = Self::default();
track.devices.push(Device::Sampler(
Sampler::new(jack, &"sampler", midi_from, audio_from, audio_to)?
));
let name = jack.with_client(|c|c.name().to_string());
let midi = track.player.midi_outs[0].name();
let port = PortConnect::exact(format!("{name}:{midi}"));
let sampler = Sampler::new(jack, &"sampler", &[port], audio_from, audio_to)?;
track.devices.push(Device::Sampler(sampler));
Ok(track)
}
pub fn width_inc (&mut self) {

View file

@ -136,13 +136,15 @@ impl Cli {
},
tracks: match mode {
LaunchMode::Sequencer => vec![
Track::new_sequencer()
Track::new()
],
LaunchMode::Groovebox => vec![
Track::new_groovebox(jack, midi_froms.as_slice(), audio_froms, audio_tos)?
],
LaunchMode::Sampler => vec![
Track::new_sampler(jack, midi_froms.as_slice(), audio_froms, audio_tos)?
LaunchMode::Groovebox | LaunchMode::Sampler => vec![
Track::new_with_sampler(
jack,
midi_froms.as_slice(),
audio_froms,
audio_tos,
)?
],
_ => vec![]
},