zynaddsubfx

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

commit a40a1cd827d51aa3eee61b1111c114b9ee17efab
parent 6b04e1b7f4795e8de74a62cb5faac539ec1de699
Author: fundamental <[email protected]>
Date:   Tue,  5 May 2015 22:50:42 -0400

Progress In Fixing Copy/Paste

Diffstat:
Msrc/Effects/EffectMgr.cpp | 2+-
Msrc/Misc/MiddleWare.cpp | 30+++++++++++++++++++++++++++---
Msrc/Misc/PresetExtractor.cpp | 55++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/Misc/PresetExtractor.h | 1+
Msrc/Misc/Util.h | 17++++++++++++++++-
Msrc/Params/ADnoteParameters.cpp | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/Params/ADnoteParameters.h | 6++++++
Msrc/Params/EnvelopeParams.cpp | 13+++++++------
Msrc/Params/EnvelopeParams.h | 2+-
Msrc/Params/FilterParams.cpp | 15++++++++++++++-
Msrc/Params/FilterParams.h | 3++-
Msrc/Params/LFOParams.cpp | 25+++++++++++++------------
Msrc/Params/LFOParams.h | 5+++--
Msrc/Params/Presets.cpp | 61++++++++++++++++++++++++-------------------------------------
Msrc/Params/Presets.h | 20++++++++------------
Msrc/Params/PresetsArray.cpp | 74++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/Params/PresetsArray.h | 20++++++--------------
Msrc/Params/PresetsStore.cpp | 56++++++++++++++++++++++++++------------------------------
Msrc/Params/PresetsStore.h | 22+++++++++-------------
Msrc/Params/SUBnoteParameters.cpp | 2+-
Msrc/Synth/OscilGen.cpp | 2+-
Msrc/Synth/Resonance.cpp | 2+-
Msrc/globals.h | 2++
23 files changed, 387 insertions(+), 182 deletions(-)

diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp @@ -41,7 +41,7 @@ #define rObject EffectMgr static const rtosc::Ports local_ports = { rSelf(EffectMgr), - rPaste(), + rPaste, rRecurp(filterpars, "Filter Parameter for Dynamic Filter"), {"parameter#64::i", rProp(alias) rDoc("Parameter Accessor"), NULL, [](const char *msg, rtosc::RtData &d) diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp @@ -21,6 +21,8 @@ #include "Util.h" #include "Master.h" #include "Part.h" +#include "PresetExtractor.h" +#include "../Params/PresetsStore.h" #include "../Params/ADnoteParameters.h" #include "../Params/SUBnoteParameters.h" #include "../Params/PADnoteParameters.h" @@ -703,6 +705,26 @@ public: return true; } + void handlePresets(const char *msg) + { + char buffer[1024]; + memset(buffer, 0, sizeof(buffer)); + DummyDataObj d(buffer, 1024, (void*)&presetsstore, this, uToB); + strcpy(buffer, "/presets/"); + + //012345678 + ///presets/ + real_preset_ports.dispatch(msg+9, d); + printf("Something <%s>\n", msg+9); + + if(!d.matches) { + fprintf(stderr, "%c[%d;%d;%dm", 0x1B, 1, 7 + 30, 0 + 40); + fprintf(stderr, "Unknown location '%s'<%s>\n", + msg, rtosc_argument_string(msg)); + fprintf(stderr, "%c[%d;%d;%dm", 0x1B, 0, 7 + 30, 0 + 40); + } + } + void handleConfig(const char *msg) { char buffer[1024]; @@ -820,7 +842,7 @@ MiddleWareImpl::MiddleWareImpl(MiddleWare *mw, int prefered_port) handleMsg(buf); }); } - + void DummyDataObj::reply(const char *msg) { mwi->bToUhandle(msg); @@ -1139,6 +1161,8 @@ void MiddleWareImpl::handleMsg(const char *msg) clearBankSlot(rtosc_argument(msg,0).i, master, osc); } else if(strstr(msg, "/config/")) { handleConfig(msg); + } else if(strstr(msg, "/presets/")) { + handlePresets(msg); } else if(strstr(msg, "Padenabled") || strstr(msg, "Ppadenabled") || strstr(msg, "Psubenabled")) { kitEnable(msg); uToB->raw_write(msg); @@ -1214,12 +1238,12 @@ void MiddleWare::setIdleCallback(void(*cb)(void)) { impl->idle = cb; } - + void MiddleWare::transmitMsg(const char *msg) { impl->handleMsg(msg); } - + void MiddleWare::transmitMsg(const char *path, const char *args, ...) { char buffer[1024]; diff --git a/src/Misc/PresetExtractor.cpp b/src/Misc/PresetExtractor.cpp @@ -26,13 +26,39 @@ #include <string> using std::string; +static void dummy(const char *, rtosc::RtData&) {} -const rtosc::Ports preset_ports +const rtosc::Ports real_preset_ports = { - {"find-presets:s", rDoc("Find associated presets with a given type"), 0, + {"scan-for-presets:", 0, 0, + [](const char *msg, rtosc::RtData &d) { + presetsstore.scanforpresets(); + auto &pre = presetsstore.presets; + for(unsigned i=0; i<pre.size();++i) + d.reply(d.loc, "isss", i, + pre[i].file.c_str(), + pre[i].name.c_str(), + pre[i].type.c_str()); + + }}, + {"copy:s", 0, 0, [](const char *msg, rtosc::RtData &d) { - d.reply(d.loc, "s", "No Presets Found..."); + presetCopy(rtosc_argument(msg, 0).s, ""); + d.reply(d.loc, "s", "clipboard copy..."); }}, + {"paste:s", 0, 0, + [](const char *msg, rtosc::RtData &d) { + presetPaste(rtosc_argument(msg, 0).s, ""); + d.reply(d.loc, "s", "clipboard paste..."); + }}, +}; + + +const rtosc::Ports preset_ports +{ + {"scan-for-presets:", rDoc("Scan For Presets"), 0, dummy}, + {"copy:s", rDoc("Copy URL To Clipboard"), 0, dummy}, + {"paste:s", rDoc("Copy URL To Clipboard"), 0, dummy}, {"add-preset:ss", rDoc("Add a preset <1> with associated name <2>"), 0, [](const char *msg, rtosc::RtData &d) { d.reply("/alert", "s", "Preset Could Not Be added..."); @@ -59,6 +85,24 @@ const rtosc::Ports preset_ports }}, }; +//Relevant types to keep in mind +//Effects/EffectMgr.cpp: setpresettype("Peffect"); +//Params/ADnoteParameters.cpp: setpresettype("Padsynth"); +//Params/EnvelopeParams.cpp: //setpresettype("Penvamplitude"); +//Params/EnvelopeParams.cpp: //setpresettype("Penvamplitude"); +//Params/EnvelopeParams.cpp: //setpresettype("Penvfrequency"); +//Params/EnvelopeParams.cpp: //setpresettype("Penvfilter"); +//Params/EnvelopeParams.cpp: //setpresettype("Penvbandwidth"); +//Params/FilterParams.cpp: //setpresettype("Pfilter"); +//Params/LFOParams.cpp: // setpresettype("Plfofrequency"); +//Params/LFOParams.cpp: // setpresettype("Plfoamplitude"); +//Params/LFOParams.cpp: // setpresettype("Plfofilter"); +//Params/PADnoteParameters.cpp: setpresettype("Ppadsynth"); +//Params/SUBnoteParameters.cpp: setpresettype("Psubsynth"); +//Synth/OscilGen.cpp: setpresettype("Poscilgen"); +//Synth/Resonance.cpp: setpresettype("Presonance"); + + //Translate newer symbols to old preset types std::vector<string> translate_preset_types(std::string metatype) { @@ -126,10 +170,11 @@ std::string doCopy(MiddleWare &mw, string url) //Get the pointer T *t = (T*)capture<void*>(m, url+"self"); //Extract Via mxml - t->add2XML(&xml); + //t->add2XML(&xml); + t->copy(presetsstore, NULL); }); - return xml.getXMLdata(); + return "";//xml.getXMLdata(); } template<class T, typename... Ts> diff --git a/src/Misc/PresetExtractor.h b/src/Misc/PresetExtractor.h @@ -2,6 +2,7 @@ #include <string> #include <rtosc/ports.h> +extern const rtosc::Ports real_preset_ports; extern const rtosc::Ports preset_ports; struct Clipboard { std::string data; diff --git a/src/Misc/Util.h b/src/Misc/Util.h @@ -164,7 +164,13 @@ static inline void arrayNullify(T &t) {delete [] t; t = NULL; } [](const char *, rtosc::RtData &d){ \ d.reply(d.loc, "b", sizeof(d.obj), &d.obj);}}\ -#define rPaste() \ +#define rPresetType \ +{"preset-type", rProp(internal), 0, \ + [](const char *, rtosc::RtData &d){ \ + rObject *obj = (rObject*)d.obj; \ + d.reply(d.loc, "s", obj->type);}} + +#define rPaste \ {"paste:b", rProp(internal) rDoc("paste port"), 0, \ [](const char *m, rtosc::RtData &d){ \ printf("rPaste...\n"); \ @@ -172,4 +178,13 @@ static inline void arrayNullify(T &t) {delete [] t; t = NULL; } rObject &o = *(rObject*)d.obj;\ o.paste(paste);}} +#define rArrayPaste \ +{"array-paste:ib", rProp(internal) rDoc("array paste port"), 0, \ + [](const char *m, rtosc::RtData &d){ \ + printf("rArrayPaste...\n"); \ + rObject &paste = **(rObject **)rtosc_argument(m,0).b.data; \ + int field = rtosc_argument(m,1).d; \ + rObject &o = *(rObject*)d.obj;\ + o.pasteArray(paste,field);}} + #endif diff --git a/src/Params/ADnoteParameters.cpp b/src/Params/ADnoteParameters.cpp @@ -262,6 +262,9 @@ static const Ports globalPorts = { #undef rObject #define rObject ADnoteParameters static const Ports adPorts = {//XXX 16 should not be hard coded + rSelf(ADnoteParameters), + rPaste, + rArrayPaste, rRecurs(VoicePar, NUM_VOICES), rRecur(GlobalPar, "Adnote Parameters"), }; @@ -893,6 +896,137 @@ void ADnoteParameters::getfromXMLsection(XMLwrapper *xml, int n) VoicePar[nvoice].getfromXML(xml, nvoice); } +void ADnoteParameters::paste(ADnoteParameters &a) +{ + this->GlobalPar.paste(a.GlobalPar); + for(int i=0; i<NUM_VOICES; ++i) + this->VoicePar[i].paste(a.VoicePar[i]); +} + +void ADnoteParameters::pasteArray(ADnoteParameters &a, int nvoice) +{ + if(nvoice >= NUM_VOICES) + return; + + VoicePar[nvoice].paste(a.VoicePar[0]); +} + +#define copy(x) this->x = a.x +#define RCopy(x) this->x->paste(*a.x) +void ADnoteVoiceParam::paste(ADnoteVoiceParam &a) +{ + //Come on C++ get some darn reflection, this is horrible + + copy(Enabled); + copy(Unison_size); + copy(Unison_frequency_spread); + copy(Unison_stereo_spread); + copy(Unison_vibratto); + copy(Unison_vibratto_speed); + copy(Unison_invert_phase); + copy(Unison_phase_randomness); + copy(Type); + copy(PDelay); + copy(Presonance); + copy(Pextoscil); + copy(PextFMoscil); + copy(Poscilphase); + copy(PFMoscilphase); + copy(PFilterEnabled); + copy(Pfilterbypass); + copy(PFMEnabled); + + RCopy(OscilSmp); + + + copy(PPanning); + copy(PVolume); + copy(PVolumeminus); + copy(PAmpVelocityScaleFunction); + copy(PAmpEnvelopeEnabled); + + RCopy(AmpEnvelope); + + copy(PAmpLfoEnabled); + + RCopy(AmpLfo); + + copy(Pfixedfreq); + copy(PfixedfreqET); + copy(PDetune); + copy(PCoarseDetune); + copy(PDetuneType); + copy(PFreqEnvelopeEnabled); + + RCopy(FreqEnvelope); + + copy(PFreqLfoEnabled); + + RCopy(FreqLfo); + + RCopy(VoiceFilter); + + copy(PFilterEnvelopeEnabled); + + RCopy(FilterEnvelope); + + copy(PFilterLfoEnabled); + + RCopy(FilterLfo); + + copy(PFMVoice); + copy(PFMVolume); + copy(PFMVolumeDamp); + copy(PFMVelocityScaleFunction); + + copy(PFMAmpEnvelopeEnabled); + + RCopy(FMAmpEnvelope); + + copy(PFMDetune); + copy(PFMCoarseDetune); + copy(PFMDetuneType); + copy(PFMFreqEnvelopeEnabled); + + + RCopy(FMFreqEnvelope); + + RCopy(FMSmp); +} + +void ADnoteGlobalParam::paste(ADnoteGlobalParam &a) +{ + copy(PStereo); + + copy(PVolume); + copy(PPanning); + copy(PAmpVelocityScaleFunction); + + copy(PPunchStrength); + copy(PPunchTime); + copy(PPunchStretch); + copy(PPunchVelocitySensing); + copy(Hrandgrouping); + + RCopy(AmpEnvelope); + RCopy(AmpLfo); + + copy(PDetune); + copy(PCoarseDetune); + copy(PDetuneType); + copy(PBandwidth); + + RCopy(FreqEnvelope); + RCopy(FreqLfo); + + copy(PFilterVelocityScale); + copy(PFilterVelocityScaleFunction); + + RCopy(GlobalFilter); + RCopy(FilterEnvelope); + RCopy(FilterLfo); + RCopy(Reson); +} void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice) { diff --git a/src/Params/ADnoteParameters.h b/src/Params/ADnoteParameters.h @@ -41,6 +41,7 @@ struct ADnoteGlobalParam { void defaults(); void add2XML(XMLwrapper *xml); void getfromXML(XMLwrapper *xml); + void paste(ADnoteGlobalParam &a); /* The instrument type - MONO/STEREO If the mode is MONO, the panning of voices are not used Stereo=1, Mono=0. */ @@ -114,6 +115,7 @@ struct ADnoteGlobalParam { struct ADnoteVoiceParam { void getfromXML(XMLwrapper *xml, unsigned nvoice); void add2XML(XMLwrapper *xml, bool fmoscilused); + void paste(ADnoteVoiceParam &p); void defaults(void); void enable(FFTwrapper *fft, Resonance *Reson); void kill(void); @@ -297,6 +299,10 @@ class ADnoteParameters:public PresetsArray void add2XML(XMLwrapper *xml); void getfromXML(XMLwrapper *xml); + void paste(ADnoteParameters &a); + void pasteArray(ADnoteParameters &a, int section); + + float getBandwidthDetuneMultiplier() const; float getUnisonFrequencySpreadCents(int nvoice) const; int get_unison_size_index(int nvoice) const; diff --git a/src/Params/EnvelopeParams.cpp b/src/Params/EnvelopeParams.cpp @@ -33,7 +33,8 @@ using namespace rtosc; static const rtosc::Ports localPorts = { rSelf(EnvelopeParams), - rPaste(), + rPresetType, + rPaste, rToggle(Pfreemode, "Complex Envelope Definitions"), rParamZyn(Penvpoints, rProp(internal), "Number of points in complex definition"), rParamZyn(Penvsustain, rProp(internal), "Location of the sustain point"), @@ -146,7 +147,7 @@ float EnvelopeParams::dt(char val) */ void EnvelopeParams::ADSRinit(char A_dt, char D_dt, char S_val, char R_dt) { - //setpresettype("Penvamplitude"); + setpresettype("Penvamplitude"); Envmode = 1; PA_dt = A_dt; PD_dt = D_dt; @@ -160,7 +161,7 @@ void EnvelopeParams::ADSRinit(char A_dt, char D_dt, char S_val, char R_dt) void EnvelopeParams::ADSRinit_dB(char A_dt, char D_dt, char S_val, char R_dt) { - //setpresettype("Penvamplitude"); + setpresettype("Penvamplitude"); Envmode = 2; PA_dt = A_dt; PD_dt = D_dt; @@ -174,7 +175,7 @@ void EnvelopeParams::ADSRinit_dB(char A_dt, char D_dt, char S_val, char R_dt) void EnvelopeParams::ASRinit(char A_val, char A_dt, char R_val, char R_dt) { - //setpresettype("Penvfrequency"); + setpresettype("Penvfrequency"); Envmode = 3; PA_val = A_val; PA_dt = A_dt; @@ -193,7 +194,7 @@ void EnvelopeParams::ADSRinit_filter(char A_val, char R_dt, char R_val) { - //setpresettype("Penvfilter"); + setpresettype("Penvfilter"); Envmode = 4; PA_val = A_val; PA_dt = A_dt; @@ -208,7 +209,7 @@ void EnvelopeParams::ADSRinit_filter(char A_val, void EnvelopeParams::ASRinit_bw(char A_val, char A_dt, char R_val, char R_dt) { - //setpresettype("Penvbandwidth"); + setpresettype("Penvbandwidth"); Envmode = 5; PA_val = A_val; PA_dt = A_dt; diff --git a/src/Params/EnvelopeParams.h b/src/Params/EnvelopeParams.h @@ -27,7 +27,7 @@ #include "../Misc/XMLwrapper.h" #include "Presets.h" -class EnvelopeParams +class EnvelopeParams:public Presets { public: EnvelopeParams(unsigned char Penvstretch_=64, diff --git a/src/Params/FilterParams.cpp b/src/Params/FilterParams.cpp @@ -62,7 +62,9 @@ static const rtosc::Ports subports = { #define rChangeCb obj->changed = true; const rtosc::Ports FilterParams::ports = { rSelf(FilterParams), - rPaste(), + rPresetType, + rPaste, + rArrayPaste, rParamZyn(Pcategory, "Class of filter"), rParamZyn(Ptype, "Filter Type"), rParamZyn(Pfreq, "Center Freq"), @@ -502,3 +504,14 @@ void FilterParams::paste(FilterParams &x) return; memcpy((char*)this, (const char*)&x, sizeof(*this)); } + +void FilterParams::pasteArray(FilterParams &x, int nvowel) +{ + for(int nformant = 0; nformant < FF_MAX_FORMANTS; ++nformant) { + auto &self = Pvowels[nvowel].formants[nformant]; + auto &update = x.Pvowels[nvowel].formants[nformant]; + self.freq = update.freq; + self.amp = update.amp; + self.q = update.q; + } +} diff --git a/src/Params/FilterParams.h b/src/Params/FilterParams.h @@ -27,7 +27,7 @@ #include "../Misc/XMLwrapper.h" #include "PresetsArray.h" -class FilterParams +class FilterParams:public PresetsArray { public: FilterParams(); @@ -42,6 +42,7 @@ class FilterParams void getfromXML(XMLwrapper *xml); void getfromXMLsection(XMLwrapper *xml, int n); void paste(FilterParams &); + void pasteArray(FilterParams &, int section); void getfromFilterParams(FilterParams *pars); diff --git a/src/Params/LFOParams.cpp b/src/Params/LFOParams.cpp @@ -35,7 +35,8 @@ using namespace rtosc; #define rObject LFOParams static const rtosc::Ports _ports = { rSelf(LFOParams), - rPaste(), + rPresetType, + rPaste, rParamF(Pfreq, "frequency of LFO"), rParamZyn(Pintensity, "Intensity of LFO"), rParamZyn(Pstartphase, rSpecial(random), "Starting Phase"), @@ -75,17 +76,17 @@ LFOParams::LFOParams(char Pfreq_, char Pcontinous_, char fel_) { - //switch(fel_) { - // case 0: - // setpresettype("Plfofrequency"); - // break; - // case 1: - // setpresettype("Plfoamplitude"); - // break; - // case 2: - // setpresettype("Plfofilter"); - // break; - //} + switch(fel_) { + case 0: + setpresettype("Plfofrequency"); + break; + case 1: + setpresettype("Plfoamplitude"); + break; + case 2: + setpresettype("Plfofilter"); + break; + } Dfreq = Pfreq_; Dintensity = Pintensity_; Dstartphase = Pstartphase_; diff --git a/src/Params/LFOParams.h b/src/Params/LFOParams.h @@ -23,10 +23,12 @@ #ifndef LFO_PARAMS_H #define LFO_PARAMS_H +#include <rtosc/ports.h> #include "Presets.h" + class XMLwrapper; -class LFOParams +class LFOParams:public Presets { public: LFOParams(); @@ -61,7 +63,6 @@ class LFOParams static int time; //is used by Pcontinous parameter static const rtosc::Ports &ports; - private: /* Default parameters */ unsigned char Dfreq; diff --git a/src/Params/Presets.cpp b/src/Params/Presets.cpp @@ -21,6 +21,8 @@ */ #include "Presets.h" +#include "../Misc/XMLwrapper.h" +#include "PresetsStore.h" #include <string.h> @@ -37,13 +39,13 @@ void Presets::setpresettype(const char *type) strcpy(this->type, type); } -void Presets::copy(const char *name) +void Presets::copy(PresetsStore &ps, const char *name) { - XMLwrapper *xml = new XMLwrapper(); + XMLwrapper xml; //used only for the clipboard if(name == NULL) - xml->minimal = false; + xml.minimal = false; char type[MAX_PRESETTYPE_SIZE]; strcpy(type, this->type); @@ -52,19 +54,18 @@ void Presets::copy(const char *name) if(strstr(type, "Plfo") != NULL) strcpy(type, "Plfo"); - xml->beginbranch(type); - add2XML(xml); - xml->endbranch(); + xml.beginbranch(type); + add2XML(&xml); + xml.endbranch(); if(name == NULL) - presetsstore.copyclipboard(xml, type); + ps.copyclipboard(xml, type); else - presetsstore.copypreset(xml, type, name); - - delete (xml); + ps.copypreset(xml, type, name); } -void Presets::paste(int npreset) +#if 0 +void Presets::paste(PresetsStore &ps, int npreset) { char type[MAX_PRESETTYPE_SIZE]; strcpy(type, this->type); @@ -74,46 +75,32 @@ void Presets::paste(int npreset) if(strstr(type, "Plfo") != NULL) strcpy(type, "Plfo"); - XMLwrapper *xml = new XMLwrapper(); + XMLwrapper xml; if(npreset == 0) { - if(!checkclipboardtype()) { - delete (xml); + if(!checkclipboardtype(ps)) return; - } - if(!presetsstore.pasteclipboard(xml)) { - delete (xml); + if(!ps.pasteclipboard(xml)) return; - } - } - else - if(!presetsstore.pastepreset(xml, npreset)) { - delete (xml); + } else if(!ps.pastepreset(xml, npreset)) return; - } - if(xml->enterbranch(type) == 0) + if(xml.enterbranch(type) == 0) return; defaults(); - getfromXML(xml); - - xml->exitbranch(); + getfromXML(&xml); - delete (xml); -} - -bool Presets::checkclipboardtype() -{ - return presetsstore.checkclipboardtype(type); + xml.exitbranch(); } +#endif -void Presets::rescanforpresets() +bool Presets::checkclipboardtype(PresetsStore &ps) { - presetsstore.rescanforpresets(type); + return ps.checkclipboardtype(type); } -void Presets::deletepreset(int npreset) +void Presets::deletepreset(PresetsStore &ps, int npreset) { - presetsstore.deletepreset(npreset); + ps.deletepreset(npreset); } diff --git a/src/Params/Presets.h b/src/Params/Presets.h @@ -23,9 +23,8 @@ #ifndef PRESETS_H #define PRESETS_H -#include "../Misc/XMLwrapper.h" - -#include "PresetsStore.h" +#include "../globals.h" +class PresetsStore; /**Presets and Clipboard management*/ class Presets @@ -35,22 +34,19 @@ class Presets Presets(); virtual ~Presets(); - virtual void copy(const char *name); /**<if name==NULL, the clipboard is used*/ - virtual void paste(int npreset); //npreset==0 for clipboard - virtual bool checkclipboardtype(); - void deletepreset(int npreset); + virtual void copy(PresetsStore &ps, const char *name); /**<if name==NULL, the clipboard is used*/ + //virtual void paste(PresetsStore &ps, int npreset); //npreset==0 for clipboard + virtual bool checkclipboardtype(PresetsStore &ps); + void deletepreset(PresetsStore &ps, int npreset); char type[MAX_PRESETTYPE_SIZE]; //void setelement(int n); - - void rescanforpresets(); - protected: void setpresettype(const char *type); private: virtual void add2XML(XMLwrapper *xml) = 0; - virtual void getfromXML(XMLwrapper *xml) = 0; - virtual void defaults() = 0; + //virtual void getfromXML(XMLwrapper *xml) = 0; + //virtual void defaults() = 0; }; #endif diff --git a/src/Params/PresetsArray.cpp b/src/Params/PresetsArray.cpp @@ -20,6 +20,7 @@ */ +#include "PresetsStore.h" #include "PresetsArray.h" #include <string.h> @@ -38,13 +39,13 @@ void PresetsArray::setpresettype(const char *type) strcpy(this->type, type); } -void PresetsArray::copy(const char *name) +void PresetsArray::copy(PresetsStore &ps, const char *name) { - XMLwrapper *xml = new XMLwrapper(); + XMLwrapper xml; //used only for the clipboard if(name == NULL) - xml->minimal = false; + xml.minimal = false; char type[MAX_PRESETTYPE_SIZE]; strcpy(type, this->type); @@ -53,25 +54,24 @@ void PresetsArray::copy(const char *name) if(name == NULL) if(strstr(type, "Plfo") != NULL) strcpy(type, "Plfo"); - ; - xml->beginbranch(type); + xml.beginbranch(type); if(nelement == -1) - add2XML(xml); + add2XML(&xml); else - add2XMLsection(xml, nelement); - xml->endbranch(); + add2XMLsection(&xml, nelement); + xml.endbranch(); if(name == NULL) - presetsstore.copyclipboard(xml, type); + ps.copyclipboard(xml, type); else - presetsstore.copypreset(xml, type, name); + ps.copypreset(xml, type, name); - delete (xml); nelement = -1; } -void PresetsArray::paste(int npreset) +#if 0 +void PresetsArray::paste(PresetsStore &ps, int npreset) { char type[MAX_PRESETTYPE_SIZE]; strcpy(type, this->type); @@ -80,65 +80,59 @@ void PresetsArray::paste(int npreset) if(npreset == 0) if(strstr(type, "Plfo") != NULL) strcpy(type, "Plfo"); - ; - XMLwrapper *xml = new XMLwrapper(); + XMLwrapper xml; if(npreset == 0) { - if(!checkclipboardtype()) { + if(!checkclipboardtype(ps)) { nelement = -1; - delete (xml); return; } - if(!presetsstore.pasteclipboard(xml)) { - delete (xml); + if(!ps.pasteclipboard(xml)) { nelement = -1; return; } - } - else - if(!presetsstore.pastepreset(xml, npreset)) { - delete (xml); + } else if(!ps.pastepreset(xml, npreset)) { nelement = -1; return; } - if(xml->enterbranch(type) == 0) { + if(xml.enterbranch(type) == 0) { nelement = -1; return; } if(nelement == -1) { defaults(); - getfromXML(xml); - } - else { + getfromXML(&xml); + } else { defaults(nelement); - getfromXMLsection(xml, nelement); + getfromXMLsection(&xml, nelement); } - xml->exitbranch(); + xml.exitbranch(); - delete (xml); nelement = -1; } -bool PresetsArray::checkclipboardtype() -{ - char type[MAX_PRESETTYPE_SIZE]; - strcpy(type, this->type); - if(nelement != -1) - strcat(type, "n"); - - return presetsstore.checkclipboardtype(type); -} -void PresetsArray::rescanforpresets() +bool PresetsArray::checkclipboardtype(PresetsStore &ps) { char type[MAX_PRESETTYPE_SIZE]; strcpy(type, this->type); if(nelement != -1) strcat(type, "n"); - presetsstore.rescanforpresets(type); + return ps.checkclipboardtype(type); } +#endif + +//void PresetsArray::rescanforpresets() +//{ +// char type[MAX_PRESETTYPE_SIZE]; +// strcpy(type, this->type); +// if(nelement != -1) +// strcat(type, "n"); +// +// presetsstore.rescanforpresets(type); +//} void PresetsArray::setelement(int n) { diff --git a/src/Params/PresetsArray.h b/src/Params/PresetsArray.h @@ -34,25 +34,17 @@ class PresetsArray:public Presets PresetsArray(); virtual ~PresetsArray(); - void copy(const char *name); /**<if name==NULL, the clipboard is used*/ - void paste(int npreset); //npreset==0 for clipboard - bool checkclipboardtype(); - // INHERITED - void deletepreset(int npreset); - - // INHERITED - char type[MAX_PRESETTYPE_SIZE]; + void copy(PresetsStore &ps, const char *name); /**<if name==NULL, the clipboard is used*/ + //void paste(PresetsStore &ps, int npreset); //npreset==0 for clipboard + //bool checkclipboardtype(PresetsStore &ps); void setelement(int n); - - void rescanforpresets(); - protected: void setpresettype(const char *type); private: - virtual void add2XML(XMLwrapper *xml) = 0; - virtual void getfromXML(XMLwrapper *xml) = 0; - virtual void defaults() = 0; virtual void add2XMLsection(XMLwrapper *xml, int n) = 0; - virtual void getfromXMLsection(XMLwrapper *xml, int n) = 0; - virtual void defaults(int n) = 0; + //virtual void getfromXMLsection(XMLwrapper *xml, int n) = 0; + //virtual void defaults() = 0; + //virtual void defaults(int n) = 0; int nelement; }; diff --git a/src/Params/PresetsStore.cpp b/src/Params/PresetsStore.cpp @@ -28,51 +28,46 @@ #include <sys/stat.h> #include "PresetsStore.h" +#include "../Misc/XMLwrapper.h" #include "../Misc/Util.h" using namespace std; +//XXX to remove PresetsStore presetsstore; PresetsStore::PresetsStore() { - clipboard.data = NULL; - clipboard.type[0] = 0; } PresetsStore::~PresetsStore() { - if(clipboard.data != NULL) - free(clipboard.data); - clearpresets(); } //Clipboard management -void PresetsStore::copyclipboard(XMLwrapper *xml, char *type) +void PresetsStore::copyclipboard(XMLwrapper &xml, char *type) { - strcpy(clipboard.type, type); - if(clipboard.data != NULL) - free(clipboard.data); - clipboard.data = xml->getXMLdata(); + clipboard.type = type; + const char *tmp = xml.getXMLdata(); + clipboard.data = tmp; + free((void*)tmp); } -bool PresetsStore::pasteclipboard(XMLwrapper *xml) +bool PresetsStore::pasteclipboard(XMLwrapper &xml) { - if(clipboard.data != NULL) - xml->putXMLdata(clipboard.data); - else + if(clipboard.data.empty()) return false; + xml.putXMLdata(clipboard.data.c_str()); return true; } bool PresetsStore::checkclipboardtype(const char *type) { //makes LFO's compatible - if((strstr(type, - "Plfo") != NULL) && (strstr(clipboard.type, "Plfo") != NULL)) + if(strstr(type, "Plfo") && strstr(clipboard.type.c_str(), "Plfo")) return true; - return strcmp(type, clipboard.type) == 0; + return type == clipboard.type; } //Presets management @@ -87,14 +82,10 @@ bool PresetsStore::presetstruct::operator<(const presetstruct &b) const return name < b.name; } - -void PresetsStore::rescanforpresets(const string &type) +void PresetsStore::scanforpresets() { - //std::cout << "Scanning For Presets" << std::endl; - //std::cout << "Of Type: " << type << std::endl; - clearpresets(); - string ftype = "." + type.substr(1) + ".xpz"; + string ftype = ".xpz"; for(int i = 0; i < MAX_BANK_ROOT_DIRS; ++i) { if(config.cfg.presetsDirList[i].empty()) @@ -124,10 +115,16 @@ void PresetsStore::rescanforpresets(const string &type) string location = "" + dirname + tmps + filename; //trim file type off of name - string name = filename.substr(0, filename.find(ftype)); + string name_type = filename.substr(0, filename.find(ftype)); + + size_t tmp = name_type.find_last_of("."); + if(tmp == string::npos) + continue; + string type = name_type.substr(tmp+1); + string name = name_type.substr(0, tmp); //put on list - presets.push_back(presetstruct(location, name)); + presets.push_back(presetstruct{location, name, type}); } closedir(dir); @@ -138,7 +135,7 @@ void PresetsStore::rescanforpresets(const string &type) } -void PresetsStore::copypreset(XMLwrapper *xml, char *type, string name) +void PresetsStore::copypreset(XMLwrapper &xml, char *type, string name) { if(config.cfg.presetsDirList[0].empty()) return; @@ -157,10 +154,10 @@ void PresetsStore::copypreset(XMLwrapper *xml, char *type, string name) string filename("" + dirname + tmps + name + "." + &type[1] + ".xpz"); - xml->saveXMLfile(filename); + xml.saveXMLfile(filename); } -bool PresetsStore::pastepreset(XMLwrapper *xml, unsigned int npreset) +bool PresetsStore::pastepreset(XMLwrapper &xml, unsigned int npreset) { npreset--; if(npreset >= presets.size()) @@ -168,8 +165,7 @@ bool PresetsStore::pastepreset(XMLwrapper *xml, unsigned int npreset) string filename = presets[npreset].file; if(filename.empty()) return false; - bool result = (xml->loadXMLfile(filename) >= 0); - return result; + return xml.loadXMLfile(filename) >= 0; } void PresetsStore::deletepreset(unsigned int npreset) diff --git a/src/Params/PresetsStore.h b/src/Params/PresetsStore.h @@ -25,11 +25,8 @@ #include <string> #include <vector> -#include "../Misc/XMLwrapper.h" -#include "../Misc/Config.h" - -#define MAX_PRESETTYPE_SIZE 30 +class XMLwrapper; class PresetsStore { public: @@ -37,30 +34,29 @@ class PresetsStore ~PresetsStore(); //Clipboard stuff - void copyclipboard(XMLwrapper *xml, char *type); - bool pasteclipboard(XMLwrapper *xml); + void copyclipboard(XMLwrapper &xml, char *type); + bool pasteclipboard(XMLwrapper &xml); bool checkclipboardtype(const char *type); //presets stuff - void copypreset(XMLwrapper *xml, char *type, std::string name); - bool pastepreset(XMLwrapper *xml, unsigned int npreset); + void copypreset(XMLwrapper &xml, char *type, std::string name); + bool pastepreset(XMLwrapper &xml, unsigned int npreset); void deletepreset(unsigned int npreset); struct presetstruct { - presetstruct(std::string _file, std::string _name) - :file(_file), name(_name) {} bool operator<(const presetstruct &b) const; std::string file; std::string name; + std::string type; }; std::vector<presetstruct> presets; - void rescanforpresets(const std::string &type); + void scanforpresets(); private: struct { - char *data; - char type[MAX_PRESETTYPE_SIZE]; + std::string data; + std::string type; } clipboard; void clearpresets(); diff --git a/src/Params/SUBnoteParameters.cpp b/src/Params/SUBnoteParameters.cpp @@ -35,7 +35,7 @@ using namespace rtosc; static const rtosc::Ports localPorts = { rSelf(SUBnoteParameters), - rPaste(), + rPaste, rToggle(Pstereo, "Stereo Enable"), rParamZyn(PVolume, "Volume"), rParamZyn(PPanning, "Left Right Panning"), diff --git a/src/Synth/OscilGen.cpp b/src/Synth/OscilGen.cpp @@ -43,7 +43,7 @@ pthread_t main_thread; #define rObject OscilGen const rtosc::Ports OscilGen::ports = { rSelf(OscilGen), - rPaste(), + rPaste, PC(hmagtype), PC(currentbasefunc), PC(basefuncpar), diff --git a/src/Synth/Resonance.cpp b/src/Synth/Resonance.cpp @@ -32,7 +32,7 @@ using namespace rtosc; const rtosc::Ports Resonance::ports = { rSelf(Resonance), - rPaste(), + rPaste, rToggle(Penabled, "resonance enable"), rToggle(Pprotectthefundamental, "Disable resonance filter on first harmonic"), rParams(Prespoints, N_RES_POINTS, "Resonance data points"), diff --git a/src/globals.h b/src/globals.h @@ -163,6 +163,8 @@ typedef std::complex<fftw_real> fft_t; #define FF_MAX_FORMANTS 12 #define FF_MAX_SEQUENCE 8 +#define MAX_PRESETTYPE_SIZE 30 + #define LOG_2 0.693147181f #define PI 3.1415926536f #define LOG_10 2.302585093f