Skip to main content

sim_lib_plugin_clap/
runtime.rs

1use sim_kernel::{Cx, Lib, LibManifest, Linker, LoadCx, Result, Symbol};
2use sim_lib_core::{SurfaceField, SurfacePackLib, SurfacePackSpec, SurfaceValueSpec, install_once};
3
4const CLAP_PLUGIN_LIB_ID: &str = "plugin-clap";
5
6/// Host-registered lib exporting the CLAP adapter cards, built on the shared
7/// [`SurfacePackLib`] substrate.
8pub struct ClapPluginLib;
9
10impl Lib for ClapPluginLib {
11    fn manifest(&self) -> LibManifest {
12        clap_plugin_pack().manifest()
13    }
14
15    fn load(&self, cx: &mut LoadCx, linker: &mut Linker<'_>) -> Result<()> {
16        clap_plugin_pack().load(cx, linker)
17    }
18}
19
20/// Installs [`ClapPluginLib`] into `cx`, idempotently.
21///
22/// Repeated calls are a no-op via the shared `install_once` guard.
23pub fn install_clap_plugin_lib(cx: &mut Cx) -> Result<()> {
24    install_once(cx, &ClapPluginLib)?;
25    Ok(())
26}
27
28/// Returns the qualified [`Symbol`]s of the cards exported by the CLAP plugin
29/// lib (the event, parameter-map, host/export processor, and fixture cards).
30pub fn clap_plugin_symbols() -> Vec<Symbol> {
31    [
32        "ClapEvent",
33        "ClapParamMap",
34        "ClapHostProcessor",
35        "ClapExportedProcessor",
36        "ClapGainFixture",
37        "ClapSynthFixture",
38    ]
39    .into_iter()
40    .map(|name| Symbol::qualified(CLAP_PLUGIN_LIB_ID, name))
41    .collect()
42}
43
44fn clap_plugin_pack() -> SurfacePackLib {
45    SurfacePackLib {
46        spec: SurfacePackSpec {
47            lib_id: Symbol::new(CLAP_PLUGIN_LIB_ID),
48            values: clap_plugin_symbols()
49                .into_iter()
50                .map(|symbol| SurfaceValueSpec {
51                    symbol: symbol.clone(),
52                    fields: vec![
53                        (Symbol::new("symbol"), SurfaceField::Symbol(symbol)),
54                        (
55                            Symbol::new("layer"),
56                            SurfaceField::Str(CLAP_PLUGIN_LIB_ID.to_owned()),
57                        ),
58                        (
59                            Symbol::new("kind"),
60                            SurfaceField::Str("clap-plugin-adapter".to_owned()),
61                        ),
62                        (
63                            Symbol::new("role"),
64                            SurfaceField::Str("CLAP-shaped host and export adapter".to_owned()),
65                        ),
66                    ],
67                })
68                .collect(),
69        },
70    }
71}