diff options
author | Damien Zammit <damien@zamaudio.com> | 2019-01-29 06:46:37 +1000 |
---|---|---|
committer | Filipe Coelho <falktx@falktx.com> | 2019-01-28 21:46:37 +0100 |
commit | b6ccc269662529ce1bfd869b249c6045f5df5960 (patch) | |
tree | 477637e655c045243996975728a250199f43d8c0 | |
parent | 4ff5ef7a7619c4353dca5b08f4c53b6b2d251056 (diff) |
Add gain example plugin (#119)
* Add gain example plugin
* Add missing overridden methods
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | examples/Gain/DistrhoPluginInfo.h | 30 | ||||
-rw-r--r-- | examples/Gain/GainExamplePlugin.cpp | 210 | ||||
-rw-r--r-- | examples/Gain/Makefile | 36 | ||||
-rw-r--r-- | examples/Gain/README.md | 7 |
5 files changed, 284 insertions, 0 deletions
@@ -14,6 +14,7 @@ dgl: $(MAKE) -C dgl examples: dgl + $(MAKE) all -C examples/Gain $(MAKE) all -C examples/Info $(MAKE) all -C examples/Latency $(MAKE) all -C examples/Meters diff --git a/examples/Gain/DistrhoPluginInfo.h b/examples/Gain/DistrhoPluginInfo.h new file mode 100644 index 00000000..76d45f85 --- /dev/null +++ b/examples/Gain/DistrhoPluginInfo.h @@ -0,0 +1,30 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> + * + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED +#define DISTRHO_PLUGIN_INFO_H_INCLUDED + +#define DISTRHO_PLUGIN_BRAND "DISTRHO" +#define DISTRHO_PLUGIN_NAME "Gain" +#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/Gain" + +#define DISTRHO_PLUGIN_HAS_UI 0 +#define DISTRHO_PLUGIN_IS_RT_SAFE 1 +#define DISTRHO_PLUGIN_NUM_INPUTS 1 +#define DISTRHO_PLUGIN_NUM_OUTPUTS 1 +#define DISTRHO_PLUGIN_WANT_LATENCY 0 + +#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED diff --git a/examples/Gain/GainExamplePlugin.cpp b/examples/Gain/GainExamplePlugin.cpp new file mode 100644 index 00000000..bfd06ed6 --- /dev/null +++ b/examples/Gain/GainExamplePlugin.cpp @@ -0,0 +1,210 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com> + * + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "DistrhoPlugin.hpp" + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------------------------------------------- + +/** + Plugin that demonstrates the basic API in DPF. + */ +class GainExamplePlugin : public Plugin +{ +public: + GainExamplePlugin() + : Plugin(1, 0, 0), // 1 parameter + fGain(1.0) + { + } + + ~GainExamplePlugin() override + { + } + +protected: + /* -------------------------------------------------------------------------------------------------------- + * Information */ + + /** + Get the plugin label. + This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters. + */ + const char* getLabel() const override + { + return "Gain"; + } + + /** + Get an extensive comment/description about the plugin. + */ + const char* getDescription() const override + { + return "Plugin that demonstrates the basic API in DPF."; + } + + /** + Get the plugin author/maker. + */ + const char* getMaker() const override + { + return "DISTRHO"; + } + + /** + Get the plugin homepage. + */ + const char* getHomePage() const override + { + return "https://github.com/DISTRHO/DPF"; + } + + /** + Get the plugin license name (a single line of text). + For commercial plugins this should return some short copyright information. + */ + const char* getLicense() const override + { + return "ISC"; + } + + /** + Get the plugin version, in hexadecimal. + */ + uint32_t getVersion() const override + { + return d_version(1, 0, 0); + } + + /** + Get the plugin unique Id. + This value is used by LADSPA, DSSI and VST plugin formats. + */ + int64_t getUniqueId() const override + { + return d_cconst('d', 'G', 'a', 'i'); + } + + /* -------------------------------------------------------------------------------------------------------- + * Init */ + + /** + Initialize the parameter @a index. + This function will be called once, shortly after the plugin is created. + */ + void initParameter(uint32_t index, Parameter& parameter) override + { + if (index != 0) + return; + + parameter.hints = kParameterIsAutomable; + parameter.name = "Gain"; + parameter.symbol = "gain"; + parameter.unit = "dB"; + parameter.ranges.def = 1.0f; + parameter.ranges.min = 0.0f; + parameter.ranges.max = 1.0f; + } + + void initProgramName(uint32_t index, String& programName) override + { + if (index != 0) { + programName = ""; + return; + } + + programName = "Default"; + } + + void loadProgram(uint32_t index) override + { + if (index != 0) + return; + + fGain = 1.0; + } + + /* -------------------------------------------------------------------------------------------------------- + * Internal data */ + + /** + Get the current value of a parameter. + The host may call this function from any context, including realtime processing. + */ + float getParameterValue(uint32_t index) const override + { + if (index != 0) + return 0.0f; + + return fGain; + } + + /** + Change a parameter value. + The host may call this function from any context, including realtime processing. + When a parameter is marked as automable, you must ensure no non-realtime operations are performed. + @note This function will only be called for parameter inputs. + */ + void setParameterValue(uint32_t index, float value) override + { + if (index != 0) + return; + + fGain = value; + } + + /* -------------------------------------------------------------------------------------------------------- + * Audio/MIDI Processing */ + + /** + Run/process function for plugins without MIDI input. + @note Some parameters might be null if there are no audio inputs or outputs. + */ + void run(const float** inputs, float** outputs, uint32_t frames) override + { + const float* const in = inputs[0]; + /* */ float* const out = outputs[0]; + uint32_t i; + + for (i = 0; i < frames; i++) { + out[i] = in[i] * fGain; + } + } + + // ------------------------------------------------------------------------------------------------------- + +private: + // Parameters + float fGain; + + /** + Set our plugin class as non-copyable and add a leak detector just in case. + */ + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GainExamplePlugin) +}; + +/* ------------------------------------------------------------------------------------------------------------ + * Plugin entry point, called by DPF to create a new plugin instance. */ + +Plugin* createPlugin() +{ + return new GainExamplePlugin(); +} + +// ----------------------------------------------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO diff --git a/examples/Gain/Makefile b/examples/Gain/Makefile new file mode 100644 index 00000000..4a93197a --- /dev/null +++ b/examples/Gain/Makefile @@ -0,0 +1,36 @@ +#!/usr/bin/make -f +# Makefile for DISTRHO Plugins # +# ---------------------------- # +# Created by falkTX +# + +# -------------------------------------------------------------- +# Project name, used for binaries + +NAME = d_gain + +# -------------------------------------------------------------- +# Files to build + +FILES_DSP = \ + GainExamplePlugin.cpp + +# -------------------------------------------------------------- +# Do some magic + +include ../../Makefile.plugins.mk + +# -------------------------------------------------------------- +# Enable all possible plugin types + +ifeq ($(LINUX),true) +TARGETS += ladspa +TARGETS += dssi +endif + +TARGETS += lv2_dsp +TARGETS += vst + +all: $(TARGETS) + +# -------------------------------------------------------------- diff --git a/examples/Gain/README.md b/examples/Gain/README.md new file mode 100644 index 00000000..3be0679b --- /dev/null +++ b/examples/Gain/README.md @@ -0,0 +1,7 @@ +# Gain example + +This example will show how to create a simple plugin in DPF with one parameter.<br/> + +The plugin will alter the gain by multiplying the input samples by a constant factor 0-1.<br/> + +The plugin has no UI because there's no need for one in this case.<br/> |