zynaddsubfx

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

commit 94fde6bb0aa0ae991279ce9b969d8d027f5d4b05
parent 03cd0d702af8cde117f8b6adf03700d1c84801ba
Author: fundamental <[email protected]>
Date:   Sun,  1 Mar 2015 10:38:15 -0500

Preset WIP

Diffstat:
Msrc/Effects/EffectMgr.cpp | 12++++++++++++
Msrc/Effects/EffectMgr.h | 1+
Msrc/Misc/Allocator.cpp | 3+++
Msrc/Misc/Allocator.h | 2++
Msrc/Misc/PresetExtractor.cpp | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Msrc/Synth/OscilGen.cpp | 28+++++++++++++++++++++++++++-
Msrc/Synth/OscilGen.h | 1+
Msrc/Synth/Resonance.cpp | 7+++++++
Msrc/Synth/Resonance.h | 1+
Msrc/UI/OscilGenUI.fl | 6++----
10 files changed, 126 insertions(+), 13 deletions(-)

diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp @@ -38,7 +38,10 @@ #include "../Misc/Allocator.h" +#define rObject EffectMgr rtosc::Ports EffectMgr::ports = { + rSelf(EffectMgr), + rPaste(), RECURP(EffectMgr, FilterParams, Filter, filterpars, "Filter Parameter for Dynamic Filter"), {"parameter#64::i", rProp(alias) rDoc("Parameter Accessor"), NULL, [](const char *msg, rtosc::RtData &d) @@ -361,6 +364,15 @@ void EffectMgr::setdryonly(bool value) dryonly = value; } +void EffectMgr::paste(EffectMgr &e) +{ + changeeffectrt(e.nefx); + changepresetrt(e.preset); + for(int i=0;i<128;++i){ + seteffectparrt(e.settings[i], i); + } +} + void EffectMgr::add2XML(XMLwrapper *xml) { xml->addpar("type", geteffect()); diff --git a/src/Effects/EffectMgr.h b/src/Effects/EffectMgr.h @@ -46,6 +46,7 @@ class EffectMgr:public Presets EffectMgr(Allocator &alloc, const bool insertion_); ~EffectMgr(); + void paste(EffectMgr &e); void add2XML(XMLwrapper *xml); void defaults(void) REALTIME; void getfromXML(XMLwrapper *xml); diff --git a/src/Misc/Allocator.cpp b/src/Misc/Allocator.cpp @@ -6,6 +6,9 @@ #include "../../tlsf/tlsf.h" #include "Allocator.h" +//Used for dummy allocations +Allocator DummyAlloc; + //recursive type class to avoid void *v = *(void**)v style casting struct next_t { diff --git a/src/Misc/Allocator.h b/src/Misc/Allocator.h @@ -79,6 +79,8 @@ class Allocator struct AllocatorImpl *impl; }; +extern Allocator DummyAlloc; + /** * General notes on Memory Allocation Within ZynAddSubFX * ----------------------------------------------------- diff --git a/src/Misc/PresetExtractor.cpp b/src/Misc/PresetExtractor.cpp @@ -6,6 +6,10 @@ #include "../Misc/Master.h" #include "../Misc/Util.h" +#include "../Misc/Allocator.h" +#include "../Effects/EffectMgr.h" +#include "../Synth/OscilGen.h" +#include "../Synth/Resonance.h" #include "../Params/ADnoteParameters.h" #include "../Params/EnvelopeParams.h" #include "../Params/FilterParams.h" @@ -86,46 +90,85 @@ std::string doCopy(MiddleWare &mw, string url) return xml.getXMLdata(); } -template<class T> -void doPaste(MiddleWare &mw, string url, string data) +template<class T, typename... Ts> +void doPaste(MiddleWare &mw, string url, string data, Ts&&... args) { (void) data; if(clip.length() < 20) return; //Generate a new object - T *t = new T(); + T *t = new T(std::forward<Ts>(args)...); XMLwrapper xml; xml.putXMLdata(clip.data()); t->getfromXML(&xml); //Send the pointer + string path = url+"paste"; char buffer[1024]; - rtosc_message(buffer, 1024, (url+"paste").c_str(), "b", sizeof(void*), &t); + rtosc_message(buffer, 1024, path.c_str(), "b", sizeof(void*), &t); + if(!Master::ports.apropos(path.c_str())) + fprintf(stderr, "Warning: Missing Paste URL: '%s'\n", path.c_str()); printf("Sending info to '%s'\n", buffer); mw.transmitMsg(buffer); //Let the pointer be reclaimed later } +//../Synth/OscilGen.h +//../Params/ADnoteParameters.h +//../Params/Controller.h +//../Params/EnvelopeParams.h +//../Params/FilterParams.h +//../Params/LFOParams.h +//../Params/PADnoteParameters.h +//../Params/Presets.h +//../Params/PresetsArray.h +//../Params/PresetsStore.h +//../Params/SUBnoteParameters.h +//../Effects/Effect.h void doClassPaste(std::string type, MiddleWare &mw, string url, string data) { if(type == "EnvelopeParams") doPaste<EnvelopeParams>(mw, url, data); - if(type == "LFOParams") + else if(type == "LFOParams") doPaste<LFOParams>(mw, url, data); - if(type == "FilterParams") + else if(type == "FilterParams") doPaste<FilterParams>(mw, url, data); + else if(type == "ADnoteParameters") + doPaste<ADnoteParameters>(mw, url, data, (FFTwrapper*)NULL); + else if(type == "PADnoteParameters") + doPaste<PADnoteParameters>(mw, url, data, (FFTwrapper*)NULL); + else if(type == "SUBnoteParameters") + doPaste<SUBnoteParameters>(mw, url, data); + else if(type == "OscilGen") + doPaste<OscilGen>(mw, url, data, (FFTwrapper*)NULL, (Resonance*)NULL); + else if(type == "Resonance") + doPaste<Resonance>(mw, url, data); + else if(type == "EffectMgr") + doPaste<EffectMgr>(mw, url, data, DummyAlloc, false); } std::string doClassCopy(std::string type, MiddleWare &mw, string url) { if(type == "EnvelopeParams") return doCopy<EnvelopeParams>(mw, url); - if(type == "LFOParams") + else if(type == "LFOParams") return doCopy<LFOParams>(mw, url); - if(type == "FilterParams") + else if(type == "FilterParams") return doCopy<FilterParams>(mw, url); + else if(type == "ADnoteParameters") + return doCopy<ADnoteParameters>(mw, url); + else if(type == "PADnoteParameters") + return doCopy<PADnoteParameters>(mw, url); + else if(type == "SUBnoteParameters") + return doCopy<SUBnoteParameters>(mw, url); + else if(type == "OscilGen") + return doCopy<OscilGen>(mw, url); + else if(type == "Resonance") + return doCopy<Resonance>(mw, url); + else if(type == "EffectMgr") + doCopy<EffectMgr>(mw, url); return "UNDEF"; } @@ -133,12 +176,31 @@ std::string getUrlType(std::string url) { printf("Searching for '%s'\n", (url+"self").c_str()); auto self = Master::ports.apropos((url+"self").c_str()); + if(!self) + fprintf(stderr, "Warning: URL Metadata Not Found For '%s'\n", url.c_str()); + if(self) return self->meta()["class"]; else return ""; } +void doClassArrayPaste(std::string type, MiddleWare &mw, string url, string data, int idx) +{ + if(type == "ADnoteVoiceParam") + ; + else if(type == "FilterParams") + ; +} + +std::string doClassArrayCopy(std::string type, MiddleWare &mw, string url, int idx) +{ + if(type == "ADnoteVoiceParam") + return "UNDEF"; + else if(type == "FilterParams") + return "UNDEF"; + return "UNDEF"; +} /***************************************************************************** diff --git a/src/Synth/OscilGen.cpp b/src/Synth/OscilGen.cpp @@ -42,6 +42,8 @@ pthread_t main_thread; #define rObject OscilGen static rtosc::Ports localPorts = { + rSelf(OscilGen), + rPaste(), PC(hmagtype), PC(currentbasefunc), PC(basefuncpar), @@ -238,7 +240,7 @@ void rmsNormalize(fft_t *freqs) OscilGen::OscilGen(FFTwrapper *fft_, Resonance *res_):Presets() { - assert(fft_); + //assert(fft_); setpresettype("Poscilgen"); fft = fft_; @@ -1114,6 +1116,30 @@ void OscilGen::getcurrentbasefunction(float *smps) getbasefunction(smps); //the sine case } +#define PRESERVE(x) decltype(this->x) x = this->x +#define RESTORE(x) this->x = x +void OscilGen::paste(OscilGen &o) +{ + //XXX Figure out a better implementation of this sensitive to RT issues... + //Preserve Pointer Elements + PRESERVE(oscilFFTfreqs); + PRESERVE(pendingfreqs); + PRESERVE(tmpsmps); + PRESERVE(outoscilFFTfreqs); + PRESERVE(fft); + PRESERVE(basefuncFFTfreqs); + PRESERVE(res); + memcpy((char*)this, (char*)&o, sizeof(*this)); + RESTORE(oscilFFTfreqs); + RESTORE(pendingfreqs); + RESTORE(tmpsmps); + RESTORE(outoscilFFTfreqs); + RESTORE(fft); + RESTORE(basefuncFFTfreqs); + RESTORE(res); + this->prepare(); +} + void OscilGen::add2XML(XMLwrapper *xml) { xml->addpar("harmonic_mag_type", Phmagtype); diff --git a/src/Synth/OscilGen.h b/src/Synth/OscilGen.h @@ -50,6 +50,7 @@ class OscilGen:public Presets /**convert oscil to base function*/ void useasbase(); + void paste(OscilGen &o); void add2XML(XMLwrapper *xml); void defaults(); void getfromXML(XMLwrapper *xml); diff --git a/src/Synth/Resonance.cpp b/src/Synth/Resonance.cpp @@ -31,6 +31,8 @@ using namespace rtosc; rtosc::Ports Resonance::ports = { + rSelf(Resonance), + rPaste(), rToggle(Penabled, "resonance enable"), rToggle(Pprotectthefundamental, "Disable resonance filter on first harmonic"), rParams(Prespoints, N_RES_POINTS, "Resonance data points"), @@ -249,6 +251,11 @@ void Resonance::sendcontroller(MidiControllers ctl, float par) ctlbw = par; } +void Resonance::paste(Resonance &r) +{ + memcpy((char*)this, (char*)&r, sizeof(r)); +} + void Resonance::add2XML(XMLwrapper *xml) { xml->addparbool("enabled", Penabled); diff --git a/src/Synth/Resonance.h b/src/Synth/Resonance.h @@ -42,6 +42,7 @@ class Resonance:public Presets void randomize(int type); void zero(void); + void paste(Resonance &r); void add2XML(XMLwrapper *xml); void defaults(void); void getfromXML(XMLwrapper *xml); diff --git a/src/UI/OscilGenUI.fl b/src/UI/OscilGenUI.fl @@ -897,14 +897,12 @@ refresh();} } Fl_Button {} { label C - callback {//presetsui->copy(oscil); -//TODO FIXME} + callback {presetsui->copy(dummy->loc());} xywh {675 550 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55 } Fl_Button {} { label P - callback {//presetsui->paste(oscil,this); -//TODO FIXME} + callback {presetsui->paste(dummy->loc(), this);} xywh {705 550 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55 } Fl_Scroll _this_has_to_be_the_last {