Skip to main content

nice_plug/wrapper/clap/
features.rs

1//! Features a plugin supports. This is essentially the same thing as tags, keyword, or categories.
2//! Hosts may use these to organize plugins.
3
4/// A keyword for a CLAP plugin. See
5/// <https://github.com/free-audio/clap/blob/main/include/clap/plugin-features.h> for more
6/// information.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ClapFeature {
9    // These are the main categories, every plugin should have at least one of these
10    Instrument,
11    AudioEffect,
12    NoteDetector,
13    NoteEffect,
14    // These are optional
15    Analyzer,
16    Synthesizer,
17    Sampler,
18    Drum,
19    DrumMachine,
20    Filter,
21    Phaser,
22    Equalizer,
23    Deesser,
24    PhaseVocoder,
25    Granular,
26    FrequencyShifter,
27    PitchShifter,
28    Distortion,
29    TransientShaper,
30    Compressor,
31    Expander,
32    Gate,
33    Limiter,
34    Flanger,
35    Chorus,
36    Delay,
37    Reverb,
38    Tremolo,
39    Glitch,
40    Utility,
41    PitchCorrection,
42    Restoration,
43    MultiEffects,
44    Mixing,
45    Mastering,
46    Mono,
47    Stereo,
48    Surround,
49    Ambisonic,
50    /// A non-predefined feature. Hosts may display this among its plugin categories. Custom
51    /// features _must_ be prefixed by a namespace in the format `namespace:feature_name`.
52    Custom(&'static str),
53}
54
55impl ClapFeature {
56    pub fn as_str(&self) -> &'static str {
57        match self {
58            ClapFeature::Instrument => "instrument",
59            ClapFeature::AudioEffect => "audio-effect",
60            ClapFeature::NoteDetector => "note-detector",
61            ClapFeature::NoteEffect => "note-effect",
62            ClapFeature::Analyzer => "analyzer",
63            ClapFeature::Synthesizer => "synthesizer",
64            ClapFeature::Sampler => "sampler",
65            ClapFeature::Drum => "drum",
66            ClapFeature::DrumMachine => "drum-machine",
67            ClapFeature::Filter => "filter",
68            ClapFeature::Phaser => "phaser",
69            ClapFeature::Equalizer => "equalizer",
70            ClapFeature::Deesser => "de-esser",
71            ClapFeature::PhaseVocoder => "phase-vocoder",
72            ClapFeature::Granular => "granular",
73            ClapFeature::FrequencyShifter => "frequency-shifter",
74            ClapFeature::PitchShifter => "pitch-shifter",
75            ClapFeature::Distortion => "distortion",
76            ClapFeature::TransientShaper => "transient-shaper",
77            ClapFeature::Compressor => "compressor",
78            ClapFeature::Expander => "expander",
79            ClapFeature::Gate => "gate",
80            ClapFeature::Limiter => "limiter",
81            ClapFeature::Flanger => "flanger",
82            ClapFeature::Chorus => "chorus",
83            ClapFeature::Delay => "delay",
84            ClapFeature::Reverb => "reverb",
85            ClapFeature::Tremolo => "tremolo",
86            ClapFeature::Glitch => "glitch",
87            ClapFeature::Utility => "utility",
88            ClapFeature::PitchCorrection => "pitch-correction",
89            ClapFeature::Restoration => "restoration",
90            ClapFeature::MultiEffects => "multi-effects",
91            ClapFeature::Mixing => "mixing",
92            ClapFeature::Mastering => "mastering",
93            ClapFeature::Mono => "mono",
94            ClapFeature::Stereo => "stereo",
95            ClapFeature::Surround => "surround",
96            ClapFeature::Ambisonic => "ambisonic",
97            ClapFeature::Custom(s) => {
98                // Custom features must be prefixed with a namespace. We'll use `.split(':').all()`
99                // here instead of `.split_once()` in case the user for whatever reason uses more
100                // than one colon (which the docs don't say anything about, but uh yeah).
101                crate::nice_debug_assert!(
102                    s.contains(':') && s.split(':').all(|x| !x.is_empty()),
103                    "'{s}' is not a valid feature, custom features must be namespaced (e.g. \
104                     'nice:{s}')",
105                    s = s
106                );
107
108                s
109            }
110        }
111    }
112}