Skip to main content

sim_lib_plugin_clap/
cookbook.rs

1//! Deterministic cookbook builders for CLAP plugin recipes.
2
3use sim_kernel::{Expr, NumberLiteral, Symbol};
4
5use crate::clap_gain_descriptor;
6
7/// Build the modeled CLAP gain descriptor used by the cookbook recipe.
8pub fn clap_gain_demo() -> Expr {
9    let descriptor = clap_gain_descriptor().expect("valid CLAP gain descriptor");
10    Expr::Map(vec![
11        (field("kind"), sym("plugin-clap", "descriptor")),
12        (
13            field("format"),
14            sym("plugin-format", descriptor.id.format.as_str()),
15        ),
16        (field("id"), Expr::String(descriptor.id.stable_id)),
17        (field("name"), Expr::String(descriptor.name)),
18        (field("ports"), number(descriptor.ports.len())),
19        (field("parameters"), number(descriptor.parameters.len())),
20    ])
21}
22
23fn field(name: &str) -> Expr {
24    Expr::Symbol(Symbol::qualified("plugin-clap", name))
25}
26
27fn sym(namespace: &str, name: &str) -> Expr {
28    Expr::Symbol(Symbol::qualified(namespace, name))
29}
30
31fn number(value: impl ToString) -> Expr {
32    Expr::Number(NumberLiteral {
33        domain: Symbol::qualified("numbers", "i64"),
34        canonical: value.to_string(),
35    })
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn clap_gain_demo_uses_clap_format() {
44        let Expr::Map(entries) = clap_gain_demo() else {
45            panic!("CLAP demo is a map")
46        };
47        assert!(entries.iter().any(|(_, value)| {
48            matches!(value, Expr::Symbol(symbol) if symbol.as_qualified_str() == "plugin-format/clap")
49        }));
50    }
51}