zynaddsubfx

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

commit 266cb4e34fe5b27ff3e5a76d9ea8e367ef4fcd28
parent a0feed301acae30c28a64fadd1e1763f0efa8256
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Sun,  9 Oct 2016 12:31:32 -0400

Fix Loading Dynamic Filter Based Patches

Diffstat:
Msrc/Effects/DynamicFilter.cpp | 56+++++++++++++++++++++++++++++++-------------------------
Msrc/Effects/DynamicFilter.h | 4+++-
Msrc/Effects/Effect.cpp | 6++++--
Msrc/Effects/Effect.h | 4+++-
Msrc/Effects/EffectMgr.cpp | 30+++++++++++++++++++-----------
Msrc/Plugin/AbstractFX.hpp | 6+++++-
6 files changed, 65 insertions(+), 41 deletions(-)

diff --git a/src/Effects/DynamicFilter.cpp b/src/Effects/DynamicFilter.cpp @@ -11,6 +11,7 @@ of the License, or (at your option) any later version. */ +#include <cassert> #include <cmath> #include <iostream> #include "DynamicFilter.h" @@ -59,14 +60,13 @@ DynamicFilter::DynamicFilter(EffectParams pars, const AbsTime *time) filterl(NULL), filterr(NULL) { - filterpars = memory.alloc<FilterParams>(0,0,0,time); - setpreset(Ppreset); + filterpars = pars.filterpars; + setpreset(Ppreset, pars.filterprotect); cleanup(); } DynamicFilter::~DynamicFilter() { - memory.dealloc(filterpars); memory.dealloc(filterl); memory.dealloc(filterr); } @@ -170,28 +170,8 @@ void DynamicFilter::reinitfilter(void) } } -void DynamicFilter::setpreset(unsigned char npreset) +void DynamicFilter::setfilterpreset(unsigned char npreset) { - const int PRESET_SIZE = 10; - const int NUM_PRESETS = 5; - unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { - //WahWah - {110, 64, 80, 0, 0, 64, 0, 90, 0, 60}, - //AutoWah - {110, 64, 70, 0, 0, 80, 70, 0, 0, 60}, - //Sweep - {100, 64, 30, 0, 0, 50, 80, 0, 0, 60}, - //VocalMorph1 - {110, 64, 80, 0, 0, 64, 0, 64, 0, 60}, - //VocalMorph1 - {127, 64, 50, 0, 0, 96, 64, 0, 0, 60} - }; - - if(npreset >= NUM_PRESETS) - npreset = NUM_PRESETS - 1; - for(int n = 0; n < PRESET_SIZE; ++n) - changepar(n, presets[npreset][n]); - filterpars->defaults(); switch(npreset) { @@ -280,10 +260,36 @@ void DynamicFilter::setpreset(unsigned char npreset) // for (int i=0;i<5;i++){ // printf("freq=%d amp=%d q=%d\n",filterpars->Pvowels[0].formants[i].freq,filterpars->Pvowels[0].formants[i].amp,filterpars->Pvowels[0].formants[i].q); // }; + reinitfilter(); +} + +void DynamicFilter::setpreset(unsigned char npreset, bool protect) +{ + const int PRESET_SIZE = 10; + const int NUM_PRESETS = 5; + unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { + //WahWah + {110, 64, 80, 0, 0, 64, 0, 90, 0, 60}, + //AutoWah + {110, 64, 70, 0, 0, 80, 70, 0, 0, 60}, + //Sweep + {100, 64, 30, 0, 0, 50, 80, 0, 0, 60}, + //VocalMorph1 + {110, 64, 80, 0, 0, 64, 0, 64, 0, 60}, + //VocalMorph1 + {127, 64, 50, 0, 0, 96, 64, 0, 0, 60} + }; + + if(npreset >= NUM_PRESETS) + npreset = NUM_PRESETS - 1; + for(int n = 0; n < PRESET_SIZE; ++n) + changepar(n, presets[npreset][n]); + if(insertion == 0) //lower the volume if this is system effect changepar(0, presets[npreset][0] * 0.5f); Ppreset = npreset; - reinitfilter(); + if(!protect) + setfilterpreset(npreset); } diff --git a/src/Effects/DynamicFilter.h b/src/Effects/DynamicFilter.h @@ -25,7 +25,8 @@ class DynamicFilter:public Effect ~DynamicFilter(); void out(const Stereo<float *> &smp); - void setpreset(unsigned char npreset); + void setpreset(unsigned char npreset) { setpreset(npreset, false); }; + void setpreset(unsigned char npreset, bool protect); void changepar(int npar, unsigned char value); unsigned char getpar(int npar) const; void cleanup(void); @@ -45,6 +46,7 @@ class DynamicFilter:public Effect void setdepth(unsigned char _Pdepth); void setampsns(unsigned char _Pampsns); + void setfilterpreset(unsigned char npreset); void reinitfilter(void); //Internal Values diff --git a/src/Effects/Effect.cpp b/src/Effects/Effect.cpp @@ -18,9 +18,11 @@ #include <cmath> EffectParams::EffectParams(Allocator &alloc_, bool insertion_, float *efxoutl_, float *efxoutr_, - unsigned char Ppreset_, unsigned int srate_, int bufsize_, FilterParams *filterpars_) + unsigned char Ppreset_, unsigned int srate_, int bufsize_, FilterParams *filterpars_, + bool filterprotect_) :alloc(alloc_), insertion(insertion_), efxoutl(efxoutl_), efxoutr(efxoutr_), - Ppreset(Ppreset_), srate(srate_), bufsize(bufsize_), filterpars(filterpars_) + Ppreset(Ppreset_), srate(srate_), bufsize(bufsize_), filterpars(filterpars_), + filterprotect(filterprotect_) {} Effect::Effect(EffectParams pars) :Ppreset(pars.Ppreset), diff --git a/src/Effects/Effect.h b/src/Effects/Effect.h @@ -55,7 +55,8 @@ struct EffectParams * @param Ppreset_ chosen preset * @return Initialized Effect Parameter object*/ EffectParams(Allocator &alloc_, bool insertion_, float *efxoutl_, float *efxoutr_, - unsigned char Ppreset_, unsigned int srate, int bufsize, FilterParams *filterpars_=0); + unsigned char Ppreset_, unsigned int srate, int bufsize, FilterParams *filterpars_, + bool filterprotect=false); Allocator &alloc; @@ -66,6 +67,7 @@ struct EffectParams unsigned int srate; int bufsize; FilterParams *filterpars; + bool filterprotect; }; /**this class is inherited by the all effects(Reverb, Echo, ..)*/ diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp @@ -14,6 +14,7 @@ #include <rtosc/ports.h> #include <rtosc/port-sugar.h> #include <iostream> +#include <cassert> #include "EffectMgr.h" @@ -174,7 +175,7 @@ EffectMgr::EffectMgr(Allocator &alloc, const SYNTH_T &synth_, :insertion(insertion_), efxoutl(new float[synth_.buffersize]), efxoutr(new float[synth_.buffersize]), - filterpars(NULL), + filterpars(new FilterParams(time_)), nefx(0), efx(NULL), time(time_), @@ -193,6 +194,7 @@ EffectMgr::EffectMgr(Allocator &alloc, const SYNTH_T &synth_, EffectMgr::~EffectMgr() { memory.dealloc(efx); + delete filterpars; delete [] efxoutl; delete [] efxoutr; } @@ -214,7 +216,7 @@ void EffectMgr::changeeffectrt(int _nefx, bool avoidSmash) memset(efxoutr, 0, synth.bufferbytes); memory.dealloc(efx); EffectParams pars(memory, insertion, efxoutl, efxoutr, 0, - synth.samplerate, synth.buffersize); + synth.samplerate, synth.buffersize, filterpars, avoidSmash); try { switch (nefx) { case 1: @@ -251,9 +253,6 @@ void EffectMgr::changeeffectrt(int _nefx, bool avoidSmash) return; } - if(efx) - filterpars = efx->filterpars; - if(!avoidSmash) for(int i=0; i<128; ++i) settings[i] = geteffectparrt(i); @@ -316,6 +315,10 @@ void EffectMgr::changepreset(unsigned char npreset) void EffectMgr::changepresetrt(unsigned char npreset, bool avoidSmash) { preset = npreset; + if(avoidSmash && dynamic_cast<DynamicFilter*>(efx)) { + efx->Ppreset = npreset; + return; + } if(efx) efx->setpreset(npreset); if(!avoidSmash) @@ -452,6 +455,10 @@ void EffectMgr::paste(EffectMgr &e) changepresetrt(e.preset, true); for(int i=0;i<128;++i) seteffectparrt(i, e.settings[i]); + if(dynamic_cast<DynamicFilter*>(efx)) { + std::swap(filterpars, e.filterpars); + efx->filterpars = filterpars; + } } void EffectMgr::add2XML(XMLwrapper& xml) @@ -471,7 +478,8 @@ void EffectMgr::add2XML(XMLwrapper& xml) xml.addpar("par", par); xml.endbranch(); } - if(filterpars) { + assert(filterpars); + if(nefx == 8) { xml.beginbranch("FILTER"); filterpars->add2XML(xml); xml.endbranch(); @@ -497,11 +505,11 @@ void EffectMgr::getfromXML(XMLwrapper& xml) seteffectpar(n, xml.getpar127("par", par)); xml.exitbranch(); } - if(filterpars) - if(xml.enterbranch("FILTER")) { - filterpars->getfromXML(xml); - xml.exitbranch(); - } + assert(filterpars); + if(xml.enterbranch("FILTER")) { + filterpars->getfromXML(xml); + xml.exitbranch(); + } xml.exitbranch(); } cleanup(); diff --git a/src/Plugin/AbstractFX.hpp b/src/Plugin/AbstractFX.hpp @@ -27,6 +27,7 @@ #include "DistrhoPlugin.hpp" // ZynAddSubFX includes +#include "Params/FilterParams.h" #include "Effects/Effect.h" #include "Misc/Allocator.h" #include "zyn-version.h" @@ -50,6 +51,7 @@ public: { efxoutl = new float[bufferSize]; efxoutr = new float[bufferSize]; + filterpar = new FilterParams(); std::memset(efxoutl, 0, sizeof(float)*bufferSize); std::memset(efxoutr, 0, sizeof(float)*bufferSize); @@ -61,6 +63,7 @@ public: delete[] efxoutl; delete[] efxoutr; delete effect; + delete filterpar; } protected: @@ -234,6 +237,7 @@ private: Effect* effect; float* efxoutl; float* efxoutr; + FilterParams* filterpar; AllocatorClass allocator; @@ -250,7 +254,7 @@ private: delete effect; } - EffectParams pars(allocator, false, efxoutl, efxoutr, 0, static_cast<uint>(sampleRate), static_cast<int>(bufferSize)); + EffectParams pars(allocator, false, efxoutl, efxoutr, 0, static_cast<uint>(sampleRate), static_cast<int>(bufferSize), filterpar); effect = new ZynFX(pars); if (firstInit)