mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip: enabling standalone mixer
This commit is contained in:
parent
7685072e4c
commit
1d3d3875fe
11 changed files with 165 additions and 111 deletions
|
|
@ -4,6 +4,10 @@ pub(crate) use tek_core::crossterm::event::{KeyCode, KeyModifiers};
|
||||||
pub(crate) use tek_jack::{*, jack::*};
|
pub(crate) use tek_jack::{*, jack::*};
|
||||||
submod! {
|
submod! {
|
||||||
mixer
|
mixer
|
||||||
|
mixer_cli
|
||||||
|
mixer_handle
|
||||||
|
mixer_render
|
||||||
track
|
track
|
||||||
track_view
|
track_view
|
||||||
|
track_handle
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
//pub const ACTIONS: [(&'static str, &'static str);2] = [
|
|
||||||
//("+/-", "Adjust"),
|
|
||||||
//("Ins/Del", "Add/remove track"),
|
|
||||||
//];
|
|
||||||
|
|
||||||
pub struct Mixer {
|
pub struct Mixer {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub tracks: Vec<Track>,
|
pub tracks: Vec<Track>,
|
||||||
|
|
@ -12,10 +7,6 @@ pub struct Mixer {
|
||||||
pub selected_column: usize,
|
pub selected_column: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
render!(Mixer |self, buf, area| Ok(area));
|
|
||||||
handle!(Mixer = handle_mixer);
|
|
||||||
process!(Mixer = process);
|
|
||||||
|
|
||||||
impl Mixer {
|
impl Mixer {
|
||||||
pub fn new (name: &str) -> Usually<Self> {
|
pub fn new (name: &str) -> Usually<Self> {
|
||||||
let (client, _status) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
let (client, _status) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
||||||
|
|
@ -26,7 +17,7 @@ impl Mixer {
|
||||||
tracks: vec![],
|
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)?;
|
let track = Track::new(name)?;
|
||||||
self.tracks.push(track);
|
self.tracks.push(track);
|
||||||
Ok(self)
|
Ok(self)
|
||||||
|
|
@ -36,6 +27,8 @@ impl Mixer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process!(Mixer = process);
|
||||||
|
|
||||||
fn process (
|
fn process (
|
||||||
_: &mut Mixer,
|
_: &mut Mixer,
|
||||||
_: &Client,
|
_: &Client,
|
||||||
|
|
@ -43,51 +36,3 @@ fn process (
|
||||||
) -> Control {
|
) -> Control {
|
||||||
Control::Continue
|
Control::Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_mixer (state: &mut Mixer, event: &AppEvent) -> Usually<bool> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
28
crates/tek_mixer/src/mixer_cli.rs
Normal file
28
crates/tek_mixer/src/mixer_cli.rs
Normal file
|
|
@ -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<String>,
|
||||||
|
/// Number of tracks
|
||||||
|
#[arg(short, long)] channels: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Mixer {
|
||||||
|
pub fn from_args () -> Usually<Self> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
56
crates/tek_mixer/src/mixer_handle.rs
Normal file
56
crates/tek_mixer/src/mixer_handle.rs
Normal file
|
|
@ -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<bool> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
//! Multi-track mixer
|
//! Multi-track mixer
|
||||||
include!("lib.rs");
|
include!("lib.rs");
|
||||||
pub fn main () -> Usually<()> {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
crates/tek_mixer/src/mixer_render.rs
Normal file
17
crates/tek_mixer/src/mixer_render.rs
Normal file
|
|
@ -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)
|
||||||
|
});
|
||||||
|
|
@ -17,28 +17,6 @@ pub struct Track {
|
||||||
pub device: usize,
|
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<Port<AudioIn>>,
|
|
||||||
//pub pre_gain_meter: f64,
|
|
||||||
//pub gain: f64,
|
|
||||||
//pub insert_ports: Vec<Port<AudioOut>>,
|
|
||||||
//pub return_ports: Vec<Port<AudioIn>>,
|
|
||||||
//pub post_gain_meter: f64,
|
|
||||||
//pub post_insert_meter: f64,
|
|
||||||
//pub level: f64,
|
|
||||||
//pub pan: f64,
|
|
||||||
//pub output_ports: Vec<Port<AudioOut>>,
|
|
||||||
//pub post_fader_meter: f64,
|
|
||||||
//pub route: String,
|
|
||||||
}.render(buf, area));
|
|
||||||
|
|
||||||
impl Track {
|
impl Track {
|
||||||
|
|
||||||
pub fn new (name: &str) -> Usually<Self> {
|
pub fn new (name: &str) -> Usually<Self> {
|
||||||
|
|
@ -138,31 +116,3 @@ const SYM_NAME: &'static str = ":name";
|
||||||
const SYM_GAIN: &'static str = ":gain";
|
const SYM_GAIN: &'static str = ":gain";
|
||||||
const SYM_SAMPLER: &'static str = "sampler";
|
const SYM_SAMPLER: &'static str = "sampler";
|
||||||
const SYM_LV2: &'static str = "lv2";
|
const SYM_LV2: &'static str = "lv2";
|
||||||
|
|
||||||
/// Key bindings for chain section.
|
|
||||||
pub const KEYMAP_CHAIN: &'static [KeyBinding<Track>] = 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)
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
|
|
|
||||||
31
crates/tek_mixer/src/track_handle.rs
Normal file
31
crates/tek_mixer/src/track_handle.rs
Normal file
|
|
@ -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<Track>] = 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)
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
|
@ -1,6 +1,26 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use tek_core::Direction;
|
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<Port<AudioIn>>,
|
||||||
|
//pub pre_gain_meter: f64,
|
||||||
|
//pub gain: f64,
|
||||||
|
//pub insert_ports: Vec<Port<AudioOut>>,
|
||||||
|
//pub return_ports: Vec<Port<AudioIn>>,
|
||||||
|
//pub post_gain_meter: f64,
|
||||||
|
//pub post_insert_meter: f64,
|
||||||
|
//pub level: f64,
|
||||||
|
//pub pan: f64,
|
||||||
|
//pub output_ports: Vec<Port<AudioOut>>,
|
||||||
|
//pub post_fader_meter: f64,
|
||||||
|
//pub route: String,
|
||||||
|
}.render(buf, area));
|
||||||
|
|
||||||
pub struct TrackView<'a> {
|
pub struct TrackView<'a> {
|
||||||
pub chain: Option<&'a Track>,
|
pub chain: Option<&'a Track>,
|
||||||
pub direction: Direction,
|
pub direction: Direction,
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,11 @@ impl Arranger {
|
||||||
if let Some(tracks) = args.tracks {
|
if let Some(tracks) = args.tracks {
|
||||||
for track in 0..tracks {
|
for track in 0..tracks {
|
||||||
arr.track_add(None)?;
|
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)
|
Ok(arr)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue