zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 6db71d7d83cb0ba81547f4bee9eca6521add6978
parent 45d02bb00a182bb15ca2e1bedf2a3faf6fc6f051
Author: falkTX <[email protected]>
Date:   Sun, 13 Dec 2015 16:35:04 +0100

Initial code for zyn-fx plugins

Diffstat:
Asrc/Plugin/AbstractFX.hpp | 286+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/Plugin/AlienWah/AlienWah.cpp | 187+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/Plugin/AlienWah/DistrhoPluginInfo.h | 37+++++++++++++++++++++++++++++++++++++
3 files changed, 510 insertions(+), 0 deletions(-)

diff --git a/src/Plugin/AbstractFX.hpp b/src/Plugin/AbstractFX.hpp @@ -0,0 +1,286 @@ +/* + ZynAddSubFX - a software synthesizer + + AbstractFX.hpp - DPF Abstract Effect class + Copyright (C) 2015 Filipe Coelho + Author: Filipe Coelho + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2 or later) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef ZYNADDSUBFX_ABSTRACTFX_HPP_INCLUDED +#define ZYNADDSUBFX_ABSTRACTFX_HPP_INCLUDED + +// DPF includes +#include "DistrhoPlugin.hpp" + +// ZynAddSubFX includes +#include "Effects/Effect.h" +#include "Misc/Allocator.h" + +/* ------------------------------------------------------------------------------------------------------------ + * Abstract plugin class */ + +template<class ZynFX> +class AbstractPluginFX : public Plugin +{ +public: + AbstractPluginFX(const uint32_t params, const uint32_t programs) + : Plugin(params, programs, 0), + paramCount(params-2), // volume and pan handled by host + programCount(programs), + bufferSize(getBufferSize()), + sampleRate(getSampleRate()), + effect(nullptr), + efxoutl(nullptr), + efxoutr(nullptr) + { + efxoutl = new float[bufferSize]; + efxoutr = new float[bufferSize]; + std::memset(efxoutl, 0, sizeof(float)*bufferSize); + std::memset(efxoutr, 0, sizeof(float)*bufferSize); + + doReinit(true); + } + + ~AbstractPluginFX() override + { + if (efxoutl != nullptr) + { + delete[] efxoutl; + efxoutl = nullptr; + } + + if (efxoutr != nullptr) + { + delete[] efxoutr; + efxoutr = nullptr; + } + + if (effect != nullptr) + { + delete effect; + effect = nullptr; + } + } + +protected: + /* -------------------------------------------------------------------------------------------------------- + * Information */ + + /** + Get the plugin author/maker. + */ + const char* getMaker() const override + { + return ""; + } + + /** + Get the plugin homepage. + Optional, returns nothing by default. + */ + const char* getHomePage() const override + { + return "http://zynaddsubfx.sourceforge.net"; + } + + /** + Get the plugin license (a single line of text or a URL). + */ + const char* getLicense() const override + { + return "GPL v2"; + } + + /** + Get the plugin version, in hexadecimal. + */ + uint32_t getVersion() const override + { + // TODO: use config.h or globals.h + return d_version(2, 5, 3); + } + + /* -------------------------------------------------------------------------------------------------------- + * 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 + { + return static_cast<float>(effect->getpar(static_cast<int>(index+2))); + } + + /** + 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 + { + /* + TODO: check bounds and round to int without juce + + const int ivalue(roundToIntAccurate(carla_fixedValue(0.0f, 127.0f, value))); + + effect->changepar(static_cast<int>(index+2), static_cast<uchar>(ivalue)); + */ + } + + /** + Load a program. + The host may call this function from any context, including realtime processing. + Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled. + */ + void loadProgram(uint32_t index) override + { + effect->setpreset(static_cast<uchar>(index)); + + // reset volume and pan + effect->changepar(0, 127); + effect->changepar(1, 64); + } + + /* -------------------------------------------------------------------------------------------------------- + * Audio/MIDI Processing */ + + /** + Activate this plugin. + */ + void activate() override + { + effect->cleanup(); + } + + /** + 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 + { + /* + TODO: Replacement for juce functions + + if (outputs[0] != inputs[0]) + FloatVectorOperations::copyWithMultiply(outputs[0], inputs[0], 0.5f, frames); + else + FloatVectorOperations::multiply(outputs[0], 0.5f, frames); + + if (outputs[1] != inputs[1]) + FloatVectorOperations::copyWithMultiply(outputs[1], inputs[1], 0.5f, frames); + else + FloatVectorOperations::multiply(outputs[1], 0.5f, frames); + + effect->out(Stereo<float*>(inputs[0], inputs[1])); + + FloatVectorOperations::addWithMultiply(outputs[0], efxoutl, 0.5f, frames); + FloatVectorOperations::addWithMultiply(outputs[1], efxoutr, 0.5f, frames); + */ + } + + /* -------------------------------------------------------------------------------------------------------- + * Callbacks (optional) */ + + /** + Optional callback to inform the plugin about a buffer size change. + This function will only be called when the plugin is deactivated. + @note This value is only a hint! + Hosts might call run() with a higher or lower number of frames. + */ + void bufferSizeChanged(uint32_t newBufferSize) override + { + if (bufferSize == newBufferSize) + return; + + bufferSize = newBufferSize; + + delete[] efxoutl; + delete[] efxoutr; + efxoutl = new float[bufferSize]; + efxoutr = new float[bufferSize]; + std::memset(efxoutl, 0, sizeof(float)*bufferSize); + std::memset(efxoutr, 0, sizeof(float)*bufferSize); + + doReinit(false); + } + + /** + Optional callback to inform the plugin about a sample rate change. + This function will only be called when the plugin is deactivated. + */ + void sampleRateChanged(double newSampleRate) override + { + if (sampleRate == newSampleRate) + return; + + sampleRate = newSampleRate; + + doReinit(false); + } + + // ------------------------------------------------------------------------------------------------------- + +private: + const uint32_t paramCount; + const uint32_t programCount; + + uint32_t bufferSize; + double sampleRate; + + Effect* effect; + float* efxoutl; + float* efxoutr; + + AllocatorClass allocator; + + void doReinit(const bool firstInit) + { + // save current param values before recreating effect + uchar params[paramCount]; + + if (effect != nullptr) + { + for (int i=0, count=static_cast<int>(paramCount); i<count; ++i) + params[i] = effect->getpar(i+2); + + delete effect; + } + + EffectParams pars(allocator, false, efxoutl, efxoutr, 0, static_cast<uint>(sampleRate), static_cast<int>(bufferSize)); + effect = new ZynFX(pars); + + if (firstInit) + { + effect->setpreset(0); + } + else + { + for (int i=0, count=static_cast<int>(paramCount); i<count; ++i) + effect->changepar(i+2, params[i]); + } + + // reset volume and pan + effect->changepar(0, 127); + effect->changepar(1, 64); + } + + DISTRHO_DECLARE_NON_COPY_CLASS(AbstractPluginFX) +}; + +#endif // ZYNADDSUBFX_ABSTRACTFX_HPP_INCLUDED diff --git a/src/Plugin/AlienWah/AlienWah.cpp b/src/Plugin/AlienWah/AlienWah.cpp @@ -0,0 +1,187 @@ +/* + ZynAddSubFX - a software synthesizer + + AlienWah.cpp - DPF + Zyn Plugin for AlienWah + Copyright (C) 2015 Filipe Coelho + Author: Filipe Coelho + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2 or later) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +// DPF includes +#include "../AbstractFX.hpp" + +// ZynAddSubFX includes +#include "Effects/Alienwah.h" + +/* ------------------------------------------------------------------------------------------------------------ + * AlienWah plugin class */ + +class AlienWahPlugin : public AbstractPluginFX<Alienwah> +{ +public: + AlienWahPlugin() + : AbstractPluginFX(11, 4) {} + +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 "AlienWah"; + } + + /** + Get an extensive comment/description about the plugin. + */ + const char* getDescription() const override + { + // TODO + return ""; + } + + /** + Get the plugin unique Id. + This value is used by LADSPA, DSSI and VST plugin formats. + */ + int64_t getUniqueId() const override + { + return d_cconst('Z', 'X', 'a', 'w'); + } + + /* -------------------------------------------------------------------------------------------------------- + * 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 + { + parameter.hints = kParameterIsInteger; + parameter.name = ""; + parameter.unit = ""; + parameter.ranges.def = 1.0f; + parameter.ranges.min = 0.0f; + parameter.ranges.max = 127.0f; + + switch (index) + { + case 0: + parameter.hints |= kParameterIsAutomable; + parameter.name = "LFO Frequency"; + parameter.ranges.def = 70.0f; + break; + + case 1: + parameter.hints |= kParameterIsAutomable; + parameter.name = "LFO Randomness"; + parameter.ranges.def = 0.0f; + break; + + case 2: + parameter.hints |= kParameterIsAutomable|kParameterIsBoolean; + parameter.name = "LFO Type"; + parameter.ranges.def = 0.0f; + parameter.ranges.max = 1.0f; + /* + TODO: support for scalePoints in DPF + scalePoints[0].label = "Sine"; + scalePoints[1].label = "Triangle"; + scalePoints[0].value = 0.0f; + scalePoints[1].value = 1.0f; + */ + break; + + case 3: + parameter.hints |= kParameterIsAutomable; + parameter.name = "LFO Stereo"; + parameter.ranges.def = 62.0f; + break; + + case 4: + parameter.hints |= kParameterIsAutomable; + parameter.name = "Depth"; + parameter.ranges.def = 60.0f; + break; + + case 5: + parameter.hints |= kParameterIsAutomable; + parameter.name = "Feedback"; + parameter.ranges.def = 105.0f; + break; + + case 6: + parameter.name = "Delay"; + parameter.ranges.def = 25.0f; + parameter.ranges.min = 1.0f; + parameter.ranges.max = 100.0f; + break; + + case 7: + parameter.hints |= kParameterIsAutomable; + parameter.name = "L/R Cross"; + parameter.ranges.def = 0.0f; + break; + + case 8: + parameter.hints |= kParameterIsAutomable; + parameter.name = "Phase"; + parameter.ranges.def = 64.0f; + break; + } + } + + /** + Set the name of the program @a index. + This function will be called once, shortly after the plugin is created. + */ + void initProgramName(uint32_t index, String& programName) override + { + switch (index) + { + case 0: + programName = "AlienWah1"; + break; + case 1: + programName = "AlienWah2"; + break; + case 2: + programName = "AlienWah3"; + break; + case 3: + programName = "AlienWah4"; + break; + default: + programName = nullptr; + break; + } + } + + DISTRHO_DECLARE_NON_COPY_CLASS(AlienWahPlugin) +}; + +/* ------------------------------------------------------------------------------------------------------------ + * Create plugin, entry point */ + +Plugin* createPlugin() +{ + return new AlienWahPlugin(); +} diff --git a/src/Plugin/AlienWah/DistrhoPluginInfo.h b/src/Plugin/AlienWah/DistrhoPluginInfo.h @@ -0,0 +1,37 @@ +/* + ZynAddSubFX - a software synthesizer + + DistrhoPluginInfo.h - DPF information header + Copyright (C) 2015 Filipe Coelho + Author: Filipe Coelho + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2 or later) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED +#define DISTRHO_PLUGIN_INFO_H_INCLUDED + +#define DISTRHO_PLUGIN_BRAND "ZynAddSubFX" +#define DISTRHO_PLUGIN_NAME "AlienWah" +#define DISTRHO_PLUGIN_URI "http://zynaddsubfx.sourceforge.net/fx#AlienWah" + +#define DISTRHO_PLUGIN_HAS_UI 0 +#define DISTRHO_PLUGIN_IS_RT_SAFE 0 +#define DISTRHO_PLUGIN_IS_SYNTH 0 +#define DISTRHO_PLUGIN_NUM_INPUTS 2 +#define DISTRHO_PLUGIN_NUM_OUTPUTS 2 +#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 + +#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED