From d5d90e3e61af2f9ef199a540af890c4f694b066f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 28 Feb 2022 14:45:07 +0100 Subject: [PATCH] Add a ClapPlugin trait Just like the Vst3Plugin trait --- Cargo.lock | 6 ++++++ Cargo.toml | 2 ++ plugins/diopser/src/lib.rs | 5 ++++- plugins/examples/gain-gui/src/lib.rs | 6 ++++-- plugins/examples/gain/src/lib.rs | 6 ++++-- plugins/examples/sine/src/lib.rs | 6 ++++-- src/lib.rs | 4 ++-- src/plugin.rs | 5 +++++ 8 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a5445f5..5616d1e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,6 +101,11 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap-sys" +version = "0.1.0" +source = "git+https://github.com/glowcoil/clap-sys?rev=3ef7048e1d3b426a7c6b02b5d3ae18f14874d4e5#3ef7048e1d3b426a7c6b02b5d3ae18f14874d4e5" + [[package]] name = "clipboard-win" version = "3.1.1" @@ -530,6 +535,7 @@ dependencies = [ "assert_no_alloc", "atomic_float", "cfg-if", + "clap-sys", "crossbeam", "lazy_static", "nih_plug_derive", diff --git a/Cargo.toml b/Cargo.toml index 5b15d8d8..9e59f8fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,8 @@ nih_plug_derive = { path = "nih_plug_derive" } atomic_float = "0.1" cfg-if = "1.0" +# For CLAP 0.18 +clap-sys = { git = "https://github.com/glowcoil/clap-sys", rev = "3ef7048e1d3b426a7c6b02b5d3ae18f14874d4e5" } crossbeam = "0.8" lazy_static = "1.4" parking_lot = "0.12" diff --git a/plugins/diopser/src/lib.rs b/plugins/diopser/src/lib.rs index e2575dd0..d54369b4 100644 --- a/plugins/diopser/src/lib.rs +++ b/plugins/diopser/src/lib.rs @@ -18,7 +18,8 @@ extern crate nih_plug; use nih_plug::{ - formatters, Buffer, BufferConfig, BusConfig, Plugin, ProcessContext, ProcessStatus, Vst3Plugin, + formatters, Buffer, BufferConfig, BusConfig, ClapPlugin, Plugin, ProcessContext, ProcessStatus, + Vst3Plugin, }; use nih_plug::{BoolParam, FloatParam, IntParam, Params, Range, SmoothingStyle}; use nih_plug::{Enum, EnumParam}; @@ -409,6 +410,8 @@ fn unnormalize_automation_precision(normalized: f32) -> u32 { - (normalized * (MAX_AUTOMATION_STEP_SIZE - MIN_AUTOMATION_STEP_SIZE) as f32).round() as u32 } +impl ClapPlugin for Diopser {} + impl Vst3Plugin for Diopser { const VST3_CLASS_ID: [u8; 16] = *b"DiopserPlugRvdH."; const VST3_CATEGORIES: &'static str = "Fx|Filter"; diff --git a/plugins/examples/gain-gui/src/lib.rs b/plugins/examples/gain-gui/src/lib.rs index a78b2b94..2159d8b0 100644 --- a/plugins/examples/gain-gui/src/lib.rs +++ b/plugins/examples/gain-gui/src/lib.rs @@ -3,8 +3,8 @@ extern crate nih_plug; use atomic_float::AtomicF32; use nih_plug::{ - util, Buffer, BufferConfig, BusConfig, Editor, IntParam, Plugin, ProcessContext, ProcessStatus, - Vst3Plugin, + util, Buffer, BufferConfig, BusConfig, ClapPlugin, Editor, IntParam, Plugin, ProcessContext, + ProcessStatus, Vst3Plugin, }; use nih_plug::{FloatParam, Params, Range, SmoothingStyle}; use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState}; @@ -202,6 +202,8 @@ impl Plugin for Gain { } } +impl ClapPlugin for Gain {} + impl Vst3Plugin for Gain { const VST3_CLASS_ID: [u8; 16] = *b"GainGuiYeahBoyyy"; const VST3_CATEGORIES: &'static str = "Fx|Dynamics"; diff --git a/plugins/examples/gain/src/lib.rs b/plugins/examples/gain/src/lib.rs index befb3191..7380f30e 100644 --- a/plugins/examples/gain/src/lib.rs +++ b/plugins/examples/gain/src/lib.rs @@ -2,8 +2,8 @@ extern crate nih_plug; use nih_plug::{ - formatters, util, Buffer, BufferConfig, BusConfig, Plugin, ProcessContext, ProcessStatus, - Vst3Plugin, + formatters, util, Buffer, BufferConfig, BusConfig, ClapPlugin, Plugin, ProcessContext, + ProcessStatus, Vst3Plugin, }; use nih_plug::{BoolParam, FloatParam, Params, Range, Smoother, SmoothingStyle}; use parking_lot::RwLock; @@ -129,6 +129,8 @@ impl Plugin for Gain { } } +impl ClapPlugin for Gain {} + impl Vst3Plugin for Gain { const VST3_CLASS_ID: [u8; 16] = *b"GainMoistestPlug"; const VST3_CATEGORIES: &'static str = "Fx|Dynamics"; diff --git a/plugins/examples/sine/src/lib.rs b/plugins/examples/sine/src/lib.rs index a4dd317b..bfce93fa 100644 --- a/plugins/examples/sine/src/lib.rs +++ b/plugins/examples/sine/src/lib.rs @@ -2,8 +2,8 @@ extern crate nih_plug; use nih_plug::{ - formatters, util, Buffer, BufferConfig, BusConfig, Plugin, ProcessContext, ProcessStatus, - Vst3Plugin, + formatters, util, Buffer, BufferConfig, BusConfig, ClapPlugin, Plugin, ProcessContext, + ProcessStatus, Vst3Plugin, }; use nih_plug::{BoolParam, FloatParam, Params, Range, Smoother, SmoothingStyle}; use std::f32::consts; @@ -176,6 +176,8 @@ impl Plugin for Sine { } } +impl ClapPlugin for Sine {} + impl Vst3Plugin for Sine { const VST3_CLASS_ID: [u8; 16] = *b"SineMoistestPlug"; const VST3_CATEGORIES: &'static str = "Instrument|Synth|Tools"; diff --git a/src/lib.rs b/src/lib.rs index 2849b4ff..61f9a4df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,8 +19,8 @@ pub use param::range::Range; pub use param::smoothing::{Smoother, SmoothingStyle}; pub use param::{BoolParam, FloatParam, IntParam, Param}; pub use plugin::{ - BufferConfig, BusConfig, Editor, NoteEvent, ParentWindowHandle, Plugin, ProcessStatus, - Vst3Plugin, + BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, Plugin, + ProcessStatus, Vst3Plugin, }; // The rest is either internal or already re-exported diff --git a/src/plugin.rs b/src/plugin.rs index 92cb12c9..8d9ecce1 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -101,6 +101,11 @@ pub trait Plugin: Default + Send + Sync + 'static { fn process(&mut self, buffer: &mut Buffer, context: &mut impl ProcessContext) -> ProcessStatus; } +/// Provides auxiliary metadata needed for a CLAP plugin. +pub trait ClapPlugin: Plugin { + // TODO: Add the required fields, just like the [Vst3Plugin] trait +} + /// Provides auxiliary metadata needed for a VST3 plugin. pub trait Vst3Plugin: Plugin { /// The unique class ID that identifies this particular plugin. You can use the