From 89b2d0a66cbf5fc299d302d8dc081c12200305d0 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 6 Jul 2022 13:55:53 +0200 Subject: [PATCH] Add a stub for poly_mod_synth This will serve as an example implementation for polyphonic modulation. --- Cargo.lock | 7 ++ Cargo.toml | 1 + README.md | 5 +- plugins/examples/poly_mod_synth/Cargo.toml | 12 ++++ plugins/examples/poly_mod_synth/src/lib.rs | 79 ++++++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 plugins/examples/poly_mod_synth/Cargo.toml create mode 100644 plugins/examples/poly_mod_synth/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 1df919e2..169faa58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2934,6 +2934,13 @@ dependencies = [ "winapi", ] +[[package]] +name = "poly_mod_synth" +version = "0.1.0" +dependencies = [ + "nih_plug", +] + [[package]] name = "ppv-lite86" version = "0.2.16" diff --git a/Cargo.toml b/Cargo.toml index 1cb02dd6..0d896caa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "plugins/examples/gain_gui_iced", "plugins/examples/gain_gui_vizia", "plugins/examples/midi_inverter", + "plugins/examples/poly_mod_synth", "plugins/examples/sine", "plugins/examples/stft", diff --git a/README.md b/README.md index 8630b6de..890c02ee 100644 --- a/README.md +++ b/README.md @@ -170,9 +170,12 @@ examples. [egui](plugins/examples/gain_gui_egui), [iced](plugins/examples/gain_gui_iced), and [VIZIA](plugins/examples/gain_gui_vizia). -- [**midi-inverter**](plugins/examples/midi-inverter) takes note/MIDI events and +- [**midi_inverter**](plugins/examples/midi_inverter) takes note/MIDI events and flips around the note, channel, expression, pressure, and CC values. This example demonstrates how to receive and output those events. +- [**poly_mod_synth**](plugins/examples/poly_mod_synth) is a simple polyphonic + synthesizer with support for polyphonic modulation in supported CLAP hosts. + This demonstrates how polyphonic modulation can be used in NIH-plug. - [**sine**](plugins/examples/sine) is a simple test tone generator plugin with frequency smoothing that can also make use of MIDI input instead of generating a static signal based on the plugin's parameters. diff --git a/plugins/examples/poly_mod_synth/Cargo.toml b/plugins/examples/poly_mod_synth/Cargo.toml new file mode 100644 index 00000000..b48ac13a --- /dev/null +++ b/plugins/examples/poly_mod_synth/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "poly_mod_synth" +version = "0.1.0" +edition = "2021" +authors = ["Robbert van der Helm "] +license = "ISC" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +nih_plug = { path = "../../../", features = ["assert_process_allocs"] } diff --git a/plugins/examples/poly_mod_synth/src/lib.rs b/plugins/examples/poly_mod_synth/src/lib.rs new file mode 100644 index 00000000..6650b0e1 --- /dev/null +++ b/plugins/examples/poly_mod_synth/src/lib.rs @@ -0,0 +1,79 @@ +use nih_plug::prelude::*; +use std::sync::Arc; + +/// A simple polyphonic synthesizer with support for CLAP's polyphonic modulation. See +/// `NoteEvent::PolyModulation` for another source of information on how to use this. +struct PolyModSynth { + params: Arc, +} + +#[derive(Default, Params)] +struct PolyModSynthParams {} + +impl Default for PolyModSynth { + fn default() -> Self { + Self { + params: Arc::new(PolyModSynthParams::default()), + } + } +} + +impl Plugin for PolyModSynth { + const NAME: &'static str = "Poly Mod Synth"; + const VENDOR: &'static str = "Moist Plugins GmbH"; + const URL: &'static str = "https://youtu.be/dQw4w9WgXcQ"; + const EMAIL: &'static str = "info@example.com"; + + const VERSION: &'static str = "0.0.1"; + + const DEFAULT_NUM_INPUTS: u32 = 2; + const DEFAULT_NUM_OUTPUTS: u32 = 2; + + // We won't need any MIDI CCs here, we just want notes and polyphonic modulation + const MIDI_INPUT: MidiConfig = MidiConfig::Basic; + const MIDI_OUTPUT: MidiConfig = MidiConfig::Basic; + const SAMPLE_ACCURATE_AUTOMATION: bool = true; + + fn params(&self) -> Arc { + self.params.clone() + } + + fn process( + &mut self, + _buffer: &mut Buffer, + _aux: &mut AuxiliaryBuffers, + context: &mut impl ProcessContext, + ) -> ProcessStatus { + // TODO: Split blocks, so something cool + while let Some(event) = context.next_event() { + match event { + _ => (), + } + } + + ProcessStatus::Normal + } +} + +impl ClapPlugin for PolyModSynth { + const CLAP_ID: &'static str = "com.moist-plugins-gmbh.poly-mod-synth"; + const CLAP_DESCRIPTION: Option<&'static str> = + Some("A simple polyphonic synthesizer with support for polyphonic modulation"); + const CLAP_MANUAL_URL: Option<&'static str> = Some(Self::URL); + const CLAP_SUPPORT_URL: Option<&'static str> = None; + const CLAP_FEATURES: &'static [ClapFeature] = &[ + ClapFeature::Instrument, + ClapFeature::Synthesizer, + ClapFeature::Stereo, + ]; +} + +// The VST3 verison of this plugin isn't too interesting as it will not support polyphonic +// modulation +impl Vst3Plugin for PolyModSynth { + const VST3_CLASS_ID: [u8; 16] = *b"PolyM0dSynth1337"; + const VST3_CATEGORIES: &'static str = "Instrument|Synth"; +} + +nih_export_clap!(PolyModSynth); +nih_export_vst3!(PolyModSynth);