mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
wip: split edn parsers
This commit is contained in:
parent
b7d7864792
commit
a54798994b
15 changed files with 275 additions and 140 deletions
45
crates/tek_chain/src/chain_edn.rs
Normal file
45
crates/tek_chain/src/chain_edn.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use crate::*;
|
||||
|
||||
impl Track {
|
||||
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![];
|
||||
let mut phrases: Vec<Phrase> = 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("phrase")) => {
|
||||
phrases.push(Phrase::load_edn(ppq, &args[1..])?)
|
||||
},
|
||||
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 phrase in phrases { track.phrases.push(Arc::new(RwLock::new(phrase))); }
|
||||
for device in devices { track.add_device(device)?; }
|
||||
Ok(track)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue