Skip to main content

sim_lib_plugin_vst3/
runtime.rs

1use sim_kernel::{Cx, Lib, LibManifest, Linker, LoadCx, Result, Symbol};
2use sim_lib_core::{SurfaceField, SurfacePackLib, SurfacePackSpec, SurfaceValueSpec, install_once};
3
4const VST3_PLUGIN_LIB_ID: &str = "plugin-vst3";
5
6/// Host-registered lib exporting the VST3 adapter cards, built on the shared
7/// [`SurfacePackLib`] substrate.
8pub struct Vst3PluginLib;
9
10impl Lib for Vst3PluginLib {
11    fn manifest(&self) -> LibManifest {
12        vst3_plugin_pack().manifest()
13    }
14
15    fn load(&self, cx: &mut LoadCx, linker: &mut Linker<'_>) -> Result<()> {
16        vst3_plugin_pack().load(cx, linker)
17    }
18}
19
20/// Installs the [`Vst3PluginLib`] into `cx`, registering its adapter cards once.
21///
22/// Idempotent: a second call with the same `cx` is a no-op.
23pub fn install_vst3_plugin_lib(cx: &mut Cx) -> Result<()> {
24    install_once(cx, &Vst3PluginLib)?;
25    Ok(())
26}
27
28/// Returns the qualified symbols this lib exports, one per VST3 adapter card.
29pub fn vst3_plugin_symbols() -> Vec<Symbol> {
30    [
31        "Vst3PluginDescriptor",
32        "Vst3ParamInfo",
33        "Vst3Event",
34        "Vst3ParamMap",
35        "Vst3ExportedProcessor",
36        "Vst3GainFixture",
37        "Vst3ScopeDecision",
38    ]
39    .into_iter()
40    .map(|name| Symbol::qualified(VST3_PLUGIN_LIB_ID, name))
41    .collect()
42}
43
44fn vst3_plugin_pack() -> SurfacePackLib {
45    SurfacePackLib {
46        spec: SurfacePackSpec {
47            lib_id: Symbol::new(VST3_PLUGIN_LIB_ID),
48            values: vst3_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(VST3_PLUGIN_LIB_ID.to_owned()),
57                        ),
58                        (
59                            Symbol::new("kind"),
60                            SurfaceField::Str("vst3-plugin-adapter".to_owned()),
61                        ),
62                        (
63                            Symbol::new("role"),
64                            SurfaceField::Str(
65                                "VST3-shaped export adapter and SDK scope record".to_owned(),
66                            ),
67                        ),
68                    ],
69                })
70                .collect(),
71        },
72    }
73}