and it once again compiles

This commit is contained in:
🪞👃🪞 2024-08-09 21:59:14 +03:00
parent 6dd4caeb42
commit 430c51e305
31 changed files with 466 additions and 694 deletions

View file

@ -6,16 +6,21 @@ version = "0.1.0"
[dependencies]
tek_core = { path = "../tek_core" }
tek_jack = { path = "../tek_jack" }
tek_chain = { path = "../tek_chain" }
tek_sampler = { path = "../tek_sampler", optional = true }
tek_plugin = { path = "../tek_plugin", optional = true }
[features]
standalone_devices = [ "tek_sampler", "tek_plugin" ]
standalone_devices = [ "sampler", "plugin" ]
sampler = [ "tek_sampler" ]
plugin = [ "tek_plugin" ]
[lib]
path = "src/lib.rs"
[[bin]]
name = "tek_mixer"
path = "src/main.rs"
path = "src/mixer_main.rs"
[[bin]]
name = "tek_track"
path = "src/track_main.rs"

View file

@ -1,7 +1,6 @@
# `tek_mixer`
# `tek_mixer` and `tek_track`
// TODO:
// - Meters: propagate clipping:
// - If one stage clips, all stages after it are marked red
// - If one track clips, all tracks that feed from it are marked red?

View file

@ -4,5 +4,6 @@ pub(crate) use tek_core::crossterm::event::{KeyCode, KeyModifiers};
pub(crate) use tek_jack::{*, jack::*};
submod! {
mixer
mixer_track
track
track_view
}

View file

@ -1,6 +0,0 @@
//! Multi-track mixer
include!("lib.rs");
pub fn main () -> Usually<()> {
tek_core::run(Arc::new(RwLock::new(crate::Mixer::new("")?)))?;
Ok(())
}

View file

@ -7,7 +7,7 @@ use crate::*;
pub struct Mixer {
pub name: String,
pub tracks: Vec<MixerTrack>,
pub tracks: Vec<Track>,
pub selected_track: usize,
pub selected_column: usize,
}
@ -27,10 +27,13 @@ impl Mixer {
})
}
pub fn add_track (&mut self, name: &str, channels: usize) -> Usually<&mut Self> {
let track = MixerTrack::new(name, channels)?;
let track = Track::new(name)?;
self.tracks.push(track);
Ok(self)
}
pub fn track (&self) -> Option<&Track> {
self.tracks.get(self.selected_track)
}
}
fn process (

View file

@ -0,0 +1,6 @@
//! Multi-track mixer
include!("lib.rs");
pub fn main () -> Usually<()> {
tek_core::run(Arc::new(RwLock::new(crate::Mixer::new("")?)))?;
Ok(())
}

View file

@ -1,160 +0,0 @@
use crate::*;
use tek_core::edn;
#[cfg(feature = "standalone_devices")]
use tek_sampler::*;
#[cfg(feature = "standalone_devices")]
use tek_plugin::*;
/// A track in the mixer.
pub struct MixerTrack {
pub name: String,
pub ports: JackPorts,
pub devices: Vec<JackDevice>,
//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,
}
impl MixerTrack {
const SYM_NAME: &'static str = ":name";
const SYM_GAIN: &'static str = ":gain";
const SYM_SAMPLER: &'static str = "sampler";
const SYM_LV2: &'static str = "lv2";
pub fn from_edn <'a, 'e> (args: &[Edn<'e>]) -> Usually<Self> {
let mut _gain = 0.0f64;
let mut track = MixerTrack::new("", 0)?;
#[allow(unused_mut)]
let mut devices: Vec<JackDevice> = vec![];
edn!(edn in args {
Edn::Map(map) => {
if let Some(Edn::Str(n)) = map.get(&Edn::Key(Self::SYM_NAME)) {
track.name = n.to_string();
}
if let Some(Edn::Double(g)) = map.get(&Edn::Key(Self::SYM_GAIN)) {
_gain = f64::from(*g);
}
},
Edn::List(args) => match args.get(0) {
// Add a sampler device to the track
Some(Edn::Symbol(Self::SYM_SAMPLER)) => {
#[cfg(feature = "standalone_devices")]
devices.push(Sampler::from_edn(&args[1..])?);
#[cfg(not(feature = "standalone_devices"))]
panic!(
"unsupported in track {}: {:?}; tek_mixer not compiled with feature \"sampler\"",
&track.name,
args.get(0).unwrap()
)
},
// Add a LV2 plugin to the track.
Some(Edn::Symbol(Self::SYM_LV2)) => {
#[cfg(feature = "standalone_devices")]
devices.push(LV2Plugin::from_edn(&args[1..])?);
#[cfg(not(feature = "standalone_devices"))]
panic!(
"unsupported in track {}: {:?}; tek_mixer not compiled with feature \"plugin\"",
&track.name,
args.get(0).unwrap()
)
},
None =>
panic!("empty list track {}", &track.name),
_ =>
panic!("unexpected in track {}: {:?}", &track.name, args.get(0).unwrap())
},
_ => {}
});
for device in devices {
track.add_device(device);
}
Ok(track)
}
pub fn new (name: &str, channels: usize) -> Usually<Self> {
Ok(Self {
name: name.into(),
ports: JackPorts::default(),
devices: vec![],
//channels,
//input_ports,
//pre_gain_meter: 0.0,
//gain: 0.0,
//post_gain_meter: 0.0,
//insert_ports,
//return_ports,
//post_insert_meter: 0.0,
//level: 0.0,
//pan: 0.0,
//post_fader_meter: 0.0,
//route: "---".into(),
//output_ports,
})
//let mut input_ports = vec![];
//let mut insert_ports = vec![];
//let mut return_ports = vec![];
//let mut output_ports = vec![];
//for channel in 1..=channels {
//input_ports.push(jack.register_port(&format!("{name} [input {channel}]"), AudioIn::default())?);
//output_ports.push(jack.register_port(&format!("{name} [out {channel}]"), AudioOut::default())?);
//let insert_port = jack.register_port(&format!("{name} [pre {channel}]"), AudioOut::default())?;
//let return_port = jack.register_port(&format!("{name} [insert {channel}]"), AudioIn::default())?;
//jack.connect_ports(&insert_port, &return_port)?;
//insert_ports.push(insert_port);
//return_ports.push(return_port);
//}
}
pub fn add_device (&mut self, device: JackDevice) {
self.devices.push(device);
}
}
//impl<W: Write> Input<TUI<W>, bool> for Mixer {
//fn handle (&mut self, engine: &mut TUI<W>) -> Result<Option<bool>> {
//Ok(None)
//}
//
//impl<W: Write> Output<TUI<W>, [u16;2]> for Mixer {
//fn render (&self, envine: &mut TUI<W>) -> Result<Option<[u16;2]>> {
//let tracks_table = Columns::new()
//.add(titles)
//.add(input_meters)
//.add(gains)
//.add(gain_meters)
//.add(pres)
//.add(pre_meters)
//.add(levels)
//.add(pans)
//.add(pan_meters)
//.add(posts)
//.add(routes)
//Rows::new()
//.add(Columns::new()
//.add(Rows::new()
//.add("[Arrows]".bold())
//.add("Navigate"))
//.add(Rows::new()
//.add("[+/-]".bold())
//.add("Adjust"))
//.add(Rows::new()
//.add("[Ins/Del]".bold())
//.add("Add/remove track")))
//.add(tracks_table)
//.render(engine)
//}
//}

View file

@ -0,0 +1,168 @@
use crate::*;
use tek_core::edn;
#[cfg(feature = "standalone_devices")]
use tek_sampler::*;
#[cfg(feature = "standalone_devices")]
use tek_plugin::*;
/// A sequencer track.
#[derive(Debug)]
pub struct Track {
pub name: String,
/// Inputs and outputs of 1st and last device
pub ports: JackPorts,
/// Device chain
pub devices: Vec<JackDevice>,
/// Device selector
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 {
pub fn new (name: &str) -> Usually<Self> {
Ok(Self {
name: name.to_string(),
ports: JackPorts::default(),
devices: vec![],
device: 0,
})
}
fn get_device_mut (&self, i: usize) -> Option<RwLockWriteGuard<Box<dyn Device>>> {
self.devices.get(i).map(|d|d.state.write().unwrap())
}
pub fn device_mut (&self) -> Option<RwLockWriteGuard<Box<dyn Device>>> {
self.get_device_mut(self.device)
}
/// Add a device to the end of the chain.
pub fn append_device (&mut self, device: JackDevice) -> Usually<&mut JackDevice> {
self.devices.push(device);
let index = self.devices.len() - 1;
Ok(&mut self.devices[index])
}
//pub fn connect_first_device (&self) -> Usually<()> {
//if let (Some(port), Some(device)) = (&self.midi_out, self.devices.get(0)) {
//device.client.as_client().connect_ports(&port, &device.midi_ins()?[0])?;
//}
//Ok(())
//}
//pub fn connect_last_device (&self, app: &Track) -> Usually<()> {
//Ok(match self.devices.get(self.devices.len().saturating_sub(1)) {
//Some(device) => {
//app.audio_out(0).map(|left|device.connect_audio_out(0, &left)).transpose()?;
//app.audio_out(1).map(|right|device.connect_audio_out(1, &right)).transpose()?;
//()
//},
//None => ()
//})
//}
pub fn from_edn <'a, 'e> (args: &[Edn<'e>]) -> Usually<Self> {
let mut _gain = 0.0f64;
let mut track = Self::new("")?;
#[allow(unused_mut)]
let mut devices: Vec<JackDevice> = vec![];
edn!(edn in args {
Edn::Map(map) => {
if let Some(Edn::Str(n)) = map.get(&Edn::Key(SYM_NAME)) {
track.name = n.to_string();
}
if let Some(Edn::Double(g)) = map.get(&Edn::Key(SYM_GAIN)) {
_gain = f64::from(*g);
}
},
Edn::List(args) => match args.get(0) {
// Add a sampler device to the track
Some(Edn::Symbol(SYM_SAMPLER)) => {
#[cfg(feature = "standalone_devices")]
devices.push(Sampler::from_edn(&args[1..])?);
#[cfg(not(feature = "standalone_devices"))]
panic!(
"unsupported in track {}: {:?}; tek_mixer not compiled with feature \"sampler\"",
&track.name,
args.get(0).unwrap()
)
},
// Add a LV2 plugin to the track.
Some(Edn::Symbol(SYM_LV2)) => {
#[cfg(feature = "standalone_devices")]
devices.push(LV2Plugin::from_edn(&args[1..])?);
#[cfg(not(feature = "standalone_devices"))]
panic!(
"unsupported in track {}: {:?}; tek_mixer not compiled with feature \"plugin\"",
&track.name,
args.get(0).unwrap()
)
},
None =>
panic!("empty list track {}", &track.name),
_ =>
panic!("unexpected in track {}: {:?}", &track.name, args.get(0).unwrap())
},
_ => {}
});
for device in devices {
track.add_device(device);
}
Ok(track)
}
pub fn add_device (&mut self, device: JackDevice) {
self.devices.push(device);
}
}
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<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)
}],
});

View file

@ -0,0 +1,6 @@
//! Multi-track mixer
include!("lib.rs");
pub fn main () -> Usually<()> {
tek_core::run(Arc::new(RwLock::new(crate::Track::new("")?)))?;
Ok(())
}

View file

@ -0,0 +1,43 @@
use crate::*;
use tek_core::Direction;
pub struct TrackView<'a> {
pub chain: Option<&'a Track>,
pub direction: Direction,
pub focused: bool,
pub entered: bool,
}
impl<'a> Render for TrackView<'a> {
fn render (&self, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
if let Some(chain) = self.chain {
match self.direction {
Direction::Down => area.width = area.width.min(40),
Direction::Right => area.width = area.width.min(10),
}
fill_bg(buf, area, Nord::bg_lo(self.focused, self.entered));
let devices: Vec<&(dyn Render + Send + Sync)> = chain.devices.as_slice()
.iter()
.map(|d|d as &(dyn Render + Send + Sync))
.collect();
let (area, areas) = self.direction
.split_focus(0, devices.as_slice(), if self.focused {
Style::default().green().dim()
} else {
Style::default().dim()
})
.render_areas(buf, area)?;
if self.focused && self.entered && areas.len() > 0 {
Corners(Style::default().green().not_dim()).draw(buf, areas[0])?;
}
Ok(area)
} else {
let Rect { x, y, width, height } = area;
let label = "No chain selected";
let x = x + (width - label.len() as u16) / 2;
let y = y + height / 2;
label.blit(buf, x, y, Some(Style::default().dim().bold()))?;
Ok(area)
}
}
}