mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: optional dependency from mixer to sampler and plugin
This commit is contained in:
parent
a819e042c7
commit
6dd4caeb42
18 changed files with 330 additions and 316 deletions
|
|
@ -7,6 +7,11 @@ version = "0.1.0"
|
|||
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" ]
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
|
|
|||
|
|
@ -23,18 +23,14 @@ impl Mixer {
|
|||
name: name.into(),
|
||||
selected_column: 0,
|
||||
selected_track: 1,
|
||||
tracks: vec![
|
||||
MixerTrack::new(&client, 1, "Mono 1")?,
|
||||
MixerTrack::new(&client, 1, "Mono 2")?,
|
||||
MixerTrack::new(&client, 2, "Stereo 1")?,
|
||||
MixerTrack::new(&client, 2, "Stereo 2")?,
|
||||
MixerTrack::new(&client, 2, "Stereo 3")?,
|
||||
MixerTrack::new(&client, 2, "Bus 1")?,
|
||||
MixerTrack::new(&client, 2, "Bus 2")?,
|
||||
MixerTrack::new(&client, 2, "Mix")?,
|
||||
],
|
||||
tracks: vec![],
|
||||
})
|
||||
}
|
||||
pub fn add_track (&mut self, name: &str, channels: usize) -> Usually<&mut Self> {
|
||||
let track = MixerTrack::new(name, channels)?;
|
||||
self.tracks.push(track);
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn process (
|
||||
|
|
|
|||
|
|
@ -1,94 +1,124 @@
|
|||
use crate::*;
|
||||
use tek_core::edn;
|
||||
#[cfg(feature = "standalone_devices")]
|
||||
use tek_sampler::*;
|
||||
#[cfg(feature = "standalone_devices")]
|
||||
use tek_plugin::*;
|
||||
|
||||
/// TODO: A track in the mixer. (Integrate with [crate::model::Track]?)
|
||||
/// A track in the mixer.
|
||||
pub struct MixerTrack {
|
||||
pub name: String,
|
||||
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,
|
||||
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 {
|
||||
pub fn new (jack: &Client, channels: u8, name: &str) -> Usually<Self> {
|
||||
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);
|
||||
}
|
||||
Ok(Self {
|
||||
name: name.into(),
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl MixerTrack {
|
||||
fn load_edn <'a, 'e> (app: &'a mut App, args: &[Edn<'e>]) -> Usually<&'a mut Self> {
|
||||
let ppq = app.transport.ppq();
|
||||
let mut name = None;
|
||||
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(":name")) {
|
||||
name = Some(*n);
|
||||
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(":gain")) {
|
||||
_gain = f64::from(*g)
|
||||
if let Some(Edn::Double(g)) = map.get(&Edn::Key(Self::SYM_GAIN)) {
|
||||
_gain = f64::from(*g);
|
||||
}
|
||||
},
|
||||
Edn::List(args) => match args.get(0) {
|
||||
Some(Edn::Symbol("sampler")) => {
|
||||
devices.push(Sampler::load_edn(&args[1..])?)
|
||||
// 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()
|
||||
)
|
||||
},
|
||||
Some(Edn::Symbol("lv2")) => {
|
||||
devices.push(LV2Plugin::load_edn(&args[1..])?)
|
||||
// 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 {}",
|
||||
name.unwrap_or("")
|
||||
),
|
||||
_ => panic!("unexpected in track {}: {:?}",
|
||||
name.unwrap_or(""),
|
||||
args.get(0).unwrap()
|
||||
)
|
||||
None =>
|
||||
panic!("empty list track {}", &track.name),
|
||||
_ =>
|
||||
panic!("unexpected in track {}: {:?}", &track.name, args.get(0).unwrap())
|
||||
},
|
||||
_ => {}
|
||||
});
|
||||
let track = app.arranger.track_add(name)?;
|
||||
for device in devices { track.add_device(device)?; }
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue