From 1d3d3875fe162de0bf6510f2b54728731e114d4e Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 10 Aug 2024 20:13:02 +0300 Subject: [PATCH] wip: enabling standalone mixer --- crates/tek_mixer/src/lib.rs | 4 ++ crates/tek_mixer/src/main.rs | 0 crates/tek_mixer/src/mixer.rs | 61 ++---------------------- crates/tek_mixer/src/mixer_cli.rs | 28 +++++++++++ crates/tek_mixer/src/mixer_handle.rs | 56 ++++++++++++++++++++++ crates/tek_mixer/src/mixer_main.rs | 2 +- crates/tek_mixer/src/mixer_render.rs | 17 +++++++ crates/tek_mixer/src/track.rs | 50 ------------------- crates/tek_mixer/src/track_handle.rs | 31 ++++++++++++ crates/tek_mixer/src/track_view.rs | 20 ++++++++ crates/tek_sequencer/src/arranger_cli.rs | 7 ++- 11 files changed, 165 insertions(+), 111 deletions(-) delete mode 100644 crates/tek_mixer/src/main.rs create mode 100644 crates/tek_mixer/src/mixer_cli.rs create mode 100644 crates/tek_mixer/src/mixer_handle.rs create mode 100644 crates/tek_mixer/src/mixer_render.rs create mode 100644 crates/tek_mixer/src/track_handle.rs diff --git a/crates/tek_mixer/src/lib.rs b/crates/tek_mixer/src/lib.rs index 8299026f..1601fe8b 100644 --- a/crates/tek_mixer/src/lib.rs +++ b/crates/tek_mixer/src/lib.rs @@ -4,6 +4,10 @@ pub(crate) use tek_core::crossterm::event::{KeyCode, KeyModifiers}; pub(crate) use tek_jack::{*, jack::*}; submod! { mixer + mixer_cli + mixer_handle + mixer_render track track_view + track_handle } diff --git a/crates/tek_mixer/src/main.rs b/crates/tek_mixer/src/main.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/crates/tek_mixer/src/mixer.rs b/crates/tek_mixer/src/mixer.rs index 7081a1f0..ebf2a209 100644 --- a/crates/tek_mixer/src/mixer.rs +++ b/crates/tek_mixer/src/mixer.rs @@ -1,10 +1,5 @@ use crate::*; -//pub const ACTIONS: [(&'static str, &'static str);2] = [ - //("+/-", "Adjust"), - //("Ins/Del", "Add/remove track"), -//]; - pub struct Mixer { pub name: String, pub tracks: Vec, @@ -12,10 +7,6 @@ pub struct Mixer { pub selected_column: usize, } -render!(Mixer |self, buf, area| Ok(area)); -handle!(Mixer = handle_mixer); -process!(Mixer = process); - impl Mixer { pub fn new (name: &str) -> Usually { let (client, _status) = Client::new(name, ClientOptions::NO_START_SERVER)?; @@ -26,7 +17,7 @@ impl Mixer { tracks: vec![], }) } - pub fn add_track (&mut self, name: &str, channels: usize) -> Usually<&mut Self> { + pub fn track_add (&mut self, name: &str, channels: usize) -> Usually<&mut Self> { let track = Track::new(name)?; self.tracks.push(track); Ok(self) @@ -36,6 +27,8 @@ impl Mixer { } } +process!(Mixer = process); + fn process ( _: &mut Mixer, _: &Client, @@ -43,51 +36,3 @@ fn process ( ) -> Control { Control::Continue } - -pub fn handle_mixer (state: &mut Mixer, event: &AppEvent) -> Usually { - if let AppEvent::Input(crossterm::event::Event::Key(event)) = event { - - match event.code { - //KeyCode::Char('c') => { - //if event.modifiers == KeyModifiers::CONTROL { - //state.exit(); - //} - //}, - KeyCode::Down => { - state.selected_track = (state.selected_track + 1) % state.tracks.len(); - println!("{}", state.selected_track); - return Ok(true) - }, - KeyCode::Up => { - if state.selected_track == 0 { - state.selected_track = state.tracks.len() - 1; - } else { - state.selected_track = state.selected_track - 1; - } - println!("{}", state.selected_track); - return Ok(true) - }, - KeyCode::Left => { - if state.selected_column == 0 { - state.selected_column = 6 - } else { - state.selected_column = state.selected_column - 1; - } - return Ok(true) - }, - KeyCode::Right => { - if state.selected_column == 6 { - state.selected_column = 0 - } else { - state.selected_column = state.selected_column + 1; - } - return Ok(true) - }, - _ => { - println!("\n{event:?}"); - } - } - - } - Ok(false) -} diff --git a/crates/tek_mixer/src/mixer_cli.rs b/crates/tek_mixer/src/mixer_cli.rs new file mode 100644 index 00000000..f08ea10a --- /dev/null +++ b/crates/tek_mixer/src/mixer_cli.rs @@ -0,0 +1,28 @@ +use tek_core::clap::{self, Parser}; +use crate::*; + +#[derive(Debug, Parser)] +#[command(version, about, long_about = None)] +pub struct MixerCli { + /// Name of JACK client + #[arg(short, long)] name: Option, + /// Number of tracks + #[arg(short, long)] channels: Option, +} + +impl Mixer { + pub fn from_args () -> Usually { + let args = MixerCli::parse(); + let mut mix = Self::new("")?; + if let Some(name) = args.name { + mix.name = name.clone(); + } + if let Some(channels) = args.channels { + for channel in 0..channels { + mix.track_add(&format!("Track {}", channel + 1), 1)?; + } + } + Ok(mix) + } +} + diff --git a/crates/tek_mixer/src/mixer_handle.rs b/crates/tek_mixer/src/mixer_handle.rs new file mode 100644 index 00000000..41510406 --- /dev/null +++ b/crates/tek_mixer/src/mixer_handle.rs @@ -0,0 +1,56 @@ +use crate::*; + +handle!(Mixer = handle_mixer); + +//pub const ACTIONS: [(&'static str, &'static str);2] = [ + //("+/-", "Adjust"), + //("Ins/Del", "Add/remove track"), +//]; + +pub fn handle_mixer (state: &mut Mixer, event: &AppEvent) -> Usually { + if let AppEvent::Input(crossterm::event::Event::Key(event)) = event { + + match event.code { + //KeyCode::Char('c') => { + //if event.modifiers == KeyModifiers::CONTROL { + //state.exit(); + //} + //}, + KeyCode::Down => { + state.selected_track = (state.selected_track + 1) % state.tracks.len(); + println!("{}", state.selected_track); + return Ok(true) + }, + KeyCode::Up => { + if state.selected_track == 0 { + state.selected_track = state.tracks.len() - 1; + } else { + state.selected_track = state.selected_track - 1; + } + println!("{}", state.selected_track); + return Ok(true) + }, + KeyCode::Left => { + if state.selected_column == 0 { + state.selected_column = 6 + } else { + state.selected_column = state.selected_column - 1; + } + return Ok(true) + }, + KeyCode::Right => { + if state.selected_column == 6 { + state.selected_column = 0 + } else { + state.selected_column = state.selected_column + 1; + } + return Ok(true) + }, + _ => { + println!("\n{event:?}"); + } + } + + } + Ok(false) +} diff --git a/crates/tek_mixer/src/mixer_main.rs b/crates/tek_mixer/src/mixer_main.rs index 643c2c6d..da46da48 100644 --- a/crates/tek_mixer/src/mixer_main.rs +++ b/crates/tek_mixer/src/mixer_main.rs @@ -1,6 +1,6 @@ //! Multi-track mixer include!("lib.rs"); pub fn main () -> Usually<()> { - tek_core::run(Arc::new(RwLock::new(crate::Mixer::new("")?)))?; + tek_core::run(Arc::new(RwLock::new(crate::Mixer::from_args()?)))?; Ok(()) } diff --git a/crates/tek_mixer/src/mixer_render.rs b/crates/tek_mixer/src/mixer_render.rs new file mode 100644 index 00000000..d75a9990 --- /dev/null +++ b/crates/tek_mixer/src/mixer_render.rs @@ -0,0 +1,17 @@ +use crate::*; + +render!(Mixer |self, buf, area| { + let mut x = 0; + for channel in self.tracks.iter() { + x = x + channel.render(buf, Rect { + x: area.x + x, + y: area.y, + width: area.width, + height: area.height + })?.width; + if x >= area.width { + break + } + } + Ok(area) +}); diff --git a/crates/tek_mixer/src/track.rs b/crates/tek_mixer/src/track.rs index 1d0790e3..48b7ceb4 100644 --- a/crates/tek_mixer/src/track.rs +++ b/crates/tek_mixer/src/track.rs @@ -17,28 +17,6 @@ pub struct Track { pub device: usize, } -handle!(Track |self, event| handle_keymap(self, event, KEYMAP_CHAIN)); - -render!(Track |self, buf, area| TrackView { - chain: Some(&self), - direction: tek_core::Direction::Right, - focused: true, - entered: true, - //pub channels: u8, - //pub input_ports: Vec>, - //pub pre_gain_meter: f64, - //pub gain: f64, - //pub insert_ports: Vec>, - //pub return_ports: Vec>, - //pub post_gain_meter: f64, - //pub post_insert_meter: f64, - //pub level: f64, - //pub pan: f64, - //pub output_ports: Vec>, - //pub post_fader_meter: f64, - //pub route: String, -}.render(buf, area)); - impl Track { pub fn new (name: &str) -> Usually { @@ -138,31 +116,3 @@ const SYM_NAME: &'static str = ":name"; const SYM_GAIN: &'static str = ":gain"; const SYM_SAMPLER: &'static str = "sampler"; const SYM_LV2: &'static str = "lv2"; - -/// Key bindings for chain section. -pub const KEYMAP_CHAIN: &'static [KeyBinding] = keymap!(Track { - [Up, NONE, "chain_cursor_up", "move cursor up", |_: &mut Track| { - Ok(true) - }], - [Down, NONE, "chain_cursor_down", "move cursor down", |_: &mut Track| { - Ok(true) - }], - [Left, NONE, "chain_cursor_left", "move cursor left", |app: &mut Track| { - //if let Some(track) = app.arranger.track_mut() { - //track.device = track.device.saturating_sub(1); - //return Ok(true) - //} - Ok(false) - }], - [Right, NONE, "chain_cursor_right", "move cursor right", |app: &mut Track| { - //if let Some(track) = app.arranger.track_mut() { - //track.device = (track.device + 1).min(track.devices.len().saturating_sub(1)); - //return Ok(true) - //} - Ok(false) - }], - [Char('`'), NONE, "chain_mode_switch", "switch the display mode", |app: &mut Track| { - //app.chain_mode = !app.chain_mode; - Ok(true) - }], -}); diff --git a/crates/tek_mixer/src/track_handle.rs b/crates/tek_mixer/src/track_handle.rs new file mode 100644 index 00000000..0fe87698 --- /dev/null +++ b/crates/tek_mixer/src/track_handle.rs @@ -0,0 +1,31 @@ +use crate::*; + +handle!(Track |self, event| handle_keymap(self, event, KEYMAP_TRACK)); + +/// Key bindings for chain section. +pub const KEYMAP_TRACK: &'static [KeyBinding] = keymap!(Track { + [Up, NONE, "chain_cursor_up", "move cursor up", |_: &mut Track| { + Ok(true) + }], + [Down, NONE, "chain_cursor_down", "move cursor down", |_: &mut Track| { + Ok(true) + }], + [Left, NONE, "chain_cursor_left", "move cursor left", |app: &mut Track| { + //if let Some(track) = app.arranger.track_mut() { + //track.device = track.device.saturating_sub(1); + //return Ok(true) + //} + Ok(false) + }], + [Right, NONE, "chain_cursor_right", "move cursor right", |app: &mut Track| { + //if let Some(track) = app.arranger.track_mut() { + //track.device = (track.device + 1).min(track.devices.len().saturating_sub(1)); + //return Ok(true) + //} + Ok(false) + }], + [Char('`'), NONE, "chain_mode_switch", "switch the display mode", |app: &mut Track| { + //app.chain_mode = !app.chain_mode; + Ok(true) + }], +}); diff --git a/crates/tek_mixer/src/track_view.rs b/crates/tek_mixer/src/track_view.rs index 19dd0623..387983d4 100644 --- a/crates/tek_mixer/src/track_view.rs +++ b/crates/tek_mixer/src/track_view.rs @@ -1,6 +1,26 @@ use crate::*; use tek_core::Direction; +render!(Track |self, buf, area| TrackView { + chain: Some(&self), + direction: tek_core::Direction::Right, + focused: true, + entered: true, + //pub channels: u8, + //pub input_ports: Vec>, + //pub pre_gain_meter: f64, + //pub gain: f64, + //pub insert_ports: Vec>, + //pub return_ports: Vec>, + //pub post_gain_meter: f64, + //pub post_insert_meter: f64, + //pub level: f64, + //pub pan: f64, + //pub output_ports: Vec>, + //pub post_fader_meter: f64, + //pub route: String, +}.render(buf, area)); + pub struct TrackView<'a> { pub chain: Option<&'a Track>, pub direction: Direction, diff --git a/crates/tek_sequencer/src/arranger_cli.rs b/crates/tek_sequencer/src/arranger_cli.rs index c3a32573..5989f7e4 100644 --- a/crates/tek_sequencer/src/arranger_cli.rs +++ b/crates/tek_sequencer/src/arranger_cli.rs @@ -30,8 +30,11 @@ impl Arranger { if let Some(tracks) = args.tracks { for track in 0..tracks { arr.track_add(None)?; - if let Some(scenes) = args.scenes { - } + } + } + if let Some(scenes) = args.scenes { + for scene in 0..scenes { + arr.scene_add(None)?; } } Ok(arr)