wip: adding edn parsing to mixer track

This commit is contained in:
🪞👃🪞 2024-08-09 11:23:12 +03:00
parent 10f191282e
commit a819e042c7
9 changed files with 89 additions and 74 deletions

View file

@ -0,0 +1,12 @@
(mixer
(track
(name "Drums")
(sampler
(dir "/home/user/Lab/Music/pak")
(sample (midi 34) (name "808 D") (file "808.wav"))))
(track
(name "Lead")
(lv2
(name "Odin2")
(path "file:///home/user/.lv2/Odin2.lv2"))
(gain 0.0)))

View file

@ -1,4 +1,5 @@
use crate::*;
use tek_core::edn;
/// TODO: A track in the mixer. (Integrate with [crate::model::Track]?)
pub struct MixerTrack {
@ -52,6 +53,44 @@ impl MixerTrack {
}
}
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;
let mut _gain = 0.0f64;
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::Double(g)) = map.get(&Edn::Key(":gain")) {
_gain = f64::from(*g)
}
},
Edn::List(args) => match args.get(0) {
Some(Edn::Symbol("sampler")) => {
devices.push(Sampler::load_edn(&args[1..])?)
},
Some(Edn::Symbol("lv2")) => {
devices.push(LV2Plugin::load_edn(&args[1..])?)
},
None => panic!("empty list track {}",
name.unwrap_or("")
),
_ => panic!("unexpected in track {}: {:?}",
name.unwrap_or(""),
args.get(0).unwrap()
)
},
_ => {}
});
let track = app.arranger.track_add(name)?;
for device in devices { track.add_device(device)?; }
Ok(track)
}
}
//impl<W: Write> Input<TUI<W>, bool> for Mixer {
//fn handle (&mut self, engine: &mut TUI<W>) -> Result<Option<bool>> {
//Ok(None)