Skip to main content

sim_lib_plugin_lv2/
runtime.rs

1use sim_kernel::{Cx, Result, Symbol};
2use sim_lib_core::{SurfaceField, SurfacePackLib, SurfacePackSpec, SurfaceValueSpec, install_once};
3
4const LV2_PLUGIN_LIB_ID: &str = "plugin-lv2";
5
6/// Installs the `plugin-lv2` surface pack into `cx`, idempotently.
7///
8/// Registers one adapter card per export symbol so the LV2 host and export
9/// adapters are discoverable from the runtime. Repeated calls are a no-op.
10///
11/// # Errors
12///
13/// Returns an error when registration into the context fails.
14pub fn install_lv2_plugin_lib(cx: &mut Cx) -> Result<()> {
15    install_once(cx, &lv2_plugin_pack())?;
16    Ok(())
17}
18
19/// Returns the qualified [`Symbol`] for each `plugin-lv2` runtime export.
20pub fn lv2_plugin_symbols() -> Vec<Symbol> {
21    [
22        "Lv2Port",
23        "Lv2PluginDescriptor",
24        "Lv2StatePatch",
25        "Lv2HostProcessor",
26        "Lv2ExportedProcessor",
27        "Lv2GainFixture",
28    ]
29    .into_iter()
30    .map(|name| Symbol::qualified(LV2_PLUGIN_LIB_ID, name))
31    .collect()
32}
33
34/// The plugin-lv2 surface pack: one uniform adapter card per export symbol.
35fn lv2_plugin_pack() -> SurfacePackLib {
36    SurfacePackLib {
37        spec: SurfacePackSpec {
38            lib_id: Symbol::new(LV2_PLUGIN_LIB_ID),
39            values: lv2_plugin_symbols()
40                .into_iter()
41                .map(|symbol| SurfaceValueSpec {
42                    symbol: symbol.clone(),
43                    fields: vec![
44                        (Symbol::new("symbol"), SurfaceField::Symbol(symbol)),
45                        (
46                            Symbol::new("layer"),
47                            SurfaceField::Str(LV2_PLUGIN_LIB_ID.to_owned()),
48                        ),
49                        (
50                            Symbol::new("kind"),
51                            SurfaceField::Str("lv2-plugin-adapter".to_owned()),
52                        ),
53                        (
54                            Symbol::new("role"),
55                            SurfaceField::Str("LV2-shaped host and export adapter".to_owned()),
56                        ),
57                    ],
58                })
59                .collect(),
60        },
61    }
62}