mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
54 lines
2 KiB
Rust
54 lines
2 KiB
Rust
use crate::*;
|
|
|
|
const SYM_NAME: &'static str = ":name";
|
|
const SYM_GAIN: &'static str = ":gain";
|
|
const SYM_SAMPLER: &'static str = "sampler";
|
|
const SYM_LV2: &'static str = "lv2";
|
|
|
|
impl<E: Engine> Track<E> {
|
|
pub fn from_edn <'a, 'e> (jack: &Arc<RwLock<JackClient>>, args: &[Edn<'e>]) -> Usually<Self> {
|
|
let mut _gain = 0.0f64;
|
|
let mut track = Self::new("")?;
|
|
#[allow(unused_mut)]
|
|
let mut devices: Vec<JackDevice<E>> = 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)) => {
|
|
devices.push(Sampler::from_edn(jack, &args[1..])?);
|
|
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)) => {
|
|
devices.push(LV2Plugin::from_edn(jack, &args[1..])?);
|
|
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)
|
|
}
|
|
}
|