Skip to main content

sim_lib_plugin_clap/
descriptor.rs

1use sim_kernel::Result;
2use sim_lib_audio_graph_core::{PortDecl, PortDir, PortMedia};
3use sim_lib_plugin_core::{
4    ParameterDescriptor, ParameterKind, PluginDescriptor, PluginFormat, PluginId,
5};
6
7/// Builds a CLAP-format audio-effect [`PluginDescriptor`].
8///
9/// Delegates to `PluginDescriptor::audio_effect` with `PluginFormat::Clap`,
10/// producing a symmetric `channels`-wide audio in/out effect identified by
11/// `stable_id` and presented as `name`.
12pub fn clap_audio_effect_descriptor(
13    stable_id: impl Into<String>,
14    name: impl Into<String>,
15    channels: u16,
16) -> Result<PluginDescriptor> {
17    PluginDescriptor::audio_effect(PluginFormat::Clap, stable_id, name, channels)
18}
19
20/// Builds the CLAP gain fixture descriptor.
21///
22/// A stereo audio effect (`org.sim.gain`, "SIM Gain") carrying a single
23/// floating-point "gain" parameter ranging 0.0 to 2.0 with a default of 1.0.
24pub fn clap_gain_descriptor() -> Result<PluginDescriptor> {
25    Ok(
26        clap_audio_effect_descriptor("org.sim.gain", "SIM Gain", 2)?.with_parameter(
27            ParameterDescriptor::new(0, "gain", "Gain", 0.0, 2.0, 1.0)?
28                .with_kind(ParameterKind::Float),
29        ),
30    )
31}
32
33/// Builds the CLAP subtractive-synth fixture descriptor.
34///
35/// An instrument (`org.sim.subtractive-synth`) with one event input port, a
36/// stereo audio output port, and an "output-gain" parameter ranging 0.0 to 1.0
37/// with a default of 0.25.
38pub fn clap_synth_descriptor() -> Result<PluginDescriptor> {
39    let mut descriptor = PluginDescriptor::new(
40        PluginId::new(PluginFormat::Clap, "org.sim.subtractive-synth")?,
41        "SIM Subtractive Synth",
42        "sim",
43        env!("CARGO_PKG_VERSION"),
44    )?;
45    descriptor
46        .ports
47        .push(PortDecl::new("events-in", PortMedia::Event, PortDir::In, 1));
48    descriptor.ports.push(PortDecl::new(
49        "audio-out",
50        PortMedia::Audio,
51        PortDir::Out,
52        2,
53    ));
54    descriptor.parameters.push(ParameterDescriptor::new(
55        0,
56        "output-gain",
57        "Output Gain",
58        0.0,
59        1.0,
60        0.25,
61    )?);
62    Ok(descriptor)
63}