sim_lib_plugin_lv2/
cookbook.rs1use sim_kernel::{Expr, NumberLiteral, Symbol};
4
5use crate::lv2_gain_lv2_descriptor;
6
7pub fn lv2_gain_demo() -> Expr {
9 let descriptor = lv2_gain_lv2_descriptor().expect("valid LV2 gain descriptor");
10 let plugin = descriptor
11 .to_plugin_descriptor()
12 .expect("LV2 gain lowers to plugin-core descriptor");
13 Expr::Map(vec![
14 (field("kind"), sym("plugin-lv2", "descriptor")),
15 (field("uri"), Expr::String(descriptor.uri)),
16 (field("name"), Expr::String(descriptor.name)),
17 (field("ports"), number(plugin.ports.len())),
18 (field("parameters"), number(plugin.parameters.len())),
19 (
20 field("format"),
21 sym("plugin-format", plugin.id.format.as_str()),
22 ),
23 ])
24}
25
26fn field(name: &str) -> Expr {
27 Expr::Symbol(Symbol::qualified("plugin-lv2", name))
28}
29
30fn sym(namespace: &str, name: &str) -> Expr {
31 Expr::Symbol(Symbol::qualified(namespace, name))
32}
33
34fn number(value: impl ToString) -> Expr {
35 Expr::Number(NumberLiteral {
36 domain: Symbol::qualified("numbers", "i64"),
37 canonical: value.to_string(),
38 })
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn lv2_gain_demo_lowers_to_core_plugin_descriptor() {
47 let Expr::Map(entries) = lv2_gain_demo() else {
48 panic!("LV2 demo is a map")
49 };
50 assert!(entries.iter().any(|(_, value)| {
51 matches!(value, Expr::Symbol(symbol) if symbol.as_qualified_str() == "plugin-format/lv2")
52 }));
53 }
54}