zynaddsubfx

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

commit 92c2a9016f1663d0ad48dac081f277baaed37701
parent b9745bd6a89f9b7c2a7aaa90801fbe2e1de9dbaf
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Thu, 10 Dec 2009 16:00:26 -0500

Cleanup: Separated Presets into Presets/PresetsArray

-Separated the Presets into two classes to reduce the g++ warnings about
 discarded arguments

-Note: looking at these classes, they need a bit more work to have them fit
 one good abstraction

Diffstat:
MChangeLog | 4++++
Msrc/Params/ADnoteParameters.cpp | 3++-
Msrc/Params/ADnoteParameters.h | 4++--
Msrc/Params/CMakeLists.txt | 1+
Msrc/Params/FilterParams.cpp | 3++-
Msrc/Params/FilterParams.h | 4++--
Msrc/Params/Makefile | 2+-
Msrc/Params/Presets.cpp | 39+++++++++------------------------------
Msrc/Params/Presets.h | 13+++++--------
Asrc/Params/PresetsArray.cpp | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/Params/PresetsArray.h | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/UI/PresetsUI.fl | 15+++++++++++----
12 files changed, 237 insertions(+), 49 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -969,3 +969,7 @@ 02 Dec 2009 (Paul Nasca) - Fixed a small typo on Virtual Keyboard +10 Dec 2009 (Mark McCurry) + - Separated out Presets and arrayed Presets to reduce warnings from + the Wextra flag + diff --git a/src/Params/ADnoteParameters.cpp b/src/Params/ADnoteParameters.cpp @@ -28,7 +28,8 @@ int ADnote_unison_sizes[] = {1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 25, 30, 40, 50, 0}; -ADnoteParameters::ADnoteParameters(FFTwrapper *fft_):Presets() +ADnoteParameters::ADnoteParameters(FFTwrapper *fft_) + :PresetsArray() { setpresettype("Padsyth"); fft = fft_; diff --git a/src/Params/ADnoteParameters.h b/src/Params/ADnoteParameters.h @@ -33,7 +33,7 @@ #include "../Misc/Util.h" #include "../Misc/XMLwrapper.h" #include "../DSP/FFTwrapper.h" -#include "Presets.h" +#include "PresetsArray.h" enum FMTYPE { NONE, MORPH, RING_MOD, PHASE_MOD, FREQ_MOD, PITCH_MOD @@ -275,7 +275,7 @@ struct ADnoteVoiceParam { EnvelopeParams *FMAmpEnvelope; }; -class ADnoteParameters:public Presets +class ADnoteParameters : public PresetsArray { public: ADnoteParameters(FFTwrapper *fft_); diff --git a/src/Params/CMakeLists.txt b/src/Params/CMakeLists.txt @@ -6,6 +6,7 @@ set(zynaddsubfx_params_SRCS LFOParams.cpp PADnoteParameters.cpp Presets.cpp + PresetsArray.cpp PresetsStore.cpp SUBnoteParameters.cpp diff --git a/src/Params/FilterParams.cpp b/src/Params/FilterParams.cpp @@ -27,7 +27,8 @@ FilterParams::FilterParams(unsigned char Ptype_, unsigned char Pfreq_, - unsigned char Pq_):Presets() + unsigned char Pq_) + : PresetsArray() { setpresettype("Pfilter"); Dtype = Ptype_; diff --git a/src/Params/FilterParams.h b/src/Params/FilterParams.h @@ -25,9 +25,9 @@ #include "../globals.h" #include "../Misc/XMLwrapper.h" -#include "Presets.h" +#include "PresetsArray.h" -class FilterParams:public Presets +class FilterParams : public PresetsArray { public: FilterParams(unsigned char Ptype_, diff --git a/src/Params/Makefile b/src/Params/Makefile @@ -1,7 +1,7 @@ include ../Makefile.inc objects=ADnoteParameters.o EnvelopeParams.o FilterParams.o \ - LFOParams.o SUBnoteParameters.o PADnoteParameters.o Controller.o Presets.o PresetsStore.o + LFOParams.o SUBnoteParameters.o PADnoteParameters.o Controller.o Presets.o PresetsArray.o PresetsStore.o all: $(objects) diff --git a/src/Params/Presets.cpp b/src/Params/Presets.cpp @@ -27,7 +27,6 @@ Presets::Presets() { type[0] = 0; - nelement = -1; } Presets::~Presets() @@ -48,18 +47,14 @@ void Presets::copy(const char *name) char type[MAX_PRESETTYPE_SIZE]; strcpy(type, this->type); - if(nelement != -1) - strcat(type, "n"); + strcat(type, "n"); if(name == NULL) if(strstr(type, "Plfo") != NULL) strcpy(type, "Plfo"); ; xml->beginbranch(type); - if(nelement == -1) - add2XML(xml); - else - add2XMLsection(xml, nelement); + add2XML(xml); xml->endbranch(); if(name == NULL) @@ -68,15 +63,14 @@ void Presets::copy(const char *name) presetsstore.copypreset(xml, type, name); delete (xml); - nelement = -1; } void Presets::paste(int npreset) { char type[MAX_PRESETTYPE_SIZE]; strcpy(type, this->type); - if(nelement != -1) - strcat(type, "n"); + strcat(type, "n"); + if(npreset == 0) if(strstr(type, "Plfo") != NULL) strcpy(type, "Plfo"); @@ -85,57 +79,42 @@ void Presets::paste(int npreset) XMLwrapper *xml = new XMLwrapper(); if(npreset == 0) { if(!checkclipboardtype()) { - nelement = -1; delete (xml); return; } if(!presetsstore.pasteclipboard(xml)) { delete (xml); - nelement = -1; return; } } else { if(!presetsstore.pastepreset(xml, npreset)) { delete (xml); - nelement = -1; return; } } if(xml->enterbranch(type) == 0) { - nelement = -1; return; } - if(nelement == -1) { - defaults(); - getfromXML(xml); - } - else { - defaults(nelement); - getfromXMLsection(xml, nelement); - } + + defaults(); + getfromXML(xml); + xml->exitbranch(); delete (xml); - nelement = -1; } bool Presets::checkclipboardtype() { char type[MAX_PRESETTYPE_SIZE]; strcpy(type, this->type); - if(nelement != -1) - strcat(type, "n"); + strcat(type, "n"); return presetsstore.checkclipboardtype(type); } -void Presets::setelement(int n) -{ - nelement = n; -} - void Presets::rescanforpresets() { presetsstore.rescanforpresets(type); diff --git a/src/Params/Presets.h b/src/Params/Presets.h @@ -30,17 +30,18 @@ /**Presets and Clipboard management*/ class Presets { + friend class PresetsArray; public: Presets(); virtual ~Presets(); - void copy(const char *name); /**<if name==NULL, the clipboard is used*/ - void paste(int npreset); //npreset==0 for clipboard - bool checkclipboardtype(); + 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); char type[MAX_PRESETTYPE_SIZE]; - void setelement(int n); + //void setelement(int n); void rescanforpresets(); @@ -50,10 +51,6 @@ class Presets virtual void add2XML(XMLwrapper *xml) = 0; virtual void getfromXML(XMLwrapper *xml) = 0; virtual void defaults() = 0; - virtual void add2XMLsection(XMLwrapper *xml, int n) {} - virtual void getfromXMLsection(XMLwrapper *xml, int n) {} - virtual void defaults(int n) {} - int nelement; }; #endif diff --git a/src/Params/PresetsArray.cpp b/src/Params/PresetsArray.cpp @@ -0,0 +1,138 @@ +/* + ZynAddSubFX - a software synthesizer + + PresetsArray.C - PresetsArray and Clipboard management + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + 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 + +*/ + +#include "PresetsArray.h" +#include <string.h> + + +PresetsArray::PresetsArray() +{ + type[0] = 0; + nelement = -1; +} + +PresetsArray::~PresetsArray() +{} + +void PresetsArray::setpresettype(const char *type) +{ + strcpy(this->type, type); +} + +void PresetsArray::copy(const char *name) +{ + XMLwrapper *xml = new XMLwrapper(); + + //used only for the clipboard + if(name == NULL) + xml->minimal = false; + + char type[MAX_PRESETTYPE_SIZE]; + strcpy(type, this->type); + if(nelement != -1) + strcat(type, "n"); + if(name == NULL) + if(strstr(type, "Plfo") != NULL) + strcpy(type, "Plfo"); + ; + + xml->beginbranch(type); + if(nelement == -1) + add2XML(xml); + else + add2XMLsection(xml, nelement); + xml->endbranch(); + + if(name == NULL) + presetsstore.copyclipboard(xml, type); + else + presetsstore.copypreset(xml, type, name); + + delete (xml); + nelement = -1; +} + +void PresetsArray::paste(int npreset) +{ + char type[MAX_PRESETTYPE_SIZE]; + strcpy(type, this->type); + if(nelement != -1) + strcat(type, "n"); + if(npreset == 0) + if(strstr(type, "Plfo") != NULL) + strcpy(type, "Plfo"); + ; + + XMLwrapper *xml = new XMLwrapper(); + if(npreset == 0) { + if(!checkclipboardtype()) { + nelement = -1; + delete (xml); + return; + } + if(!presetsstore.pasteclipboard(xml)) { + delete (xml); + nelement = -1; + return; + } + } + else { + if(!presetsstore.pastepreset(xml, npreset)) { + delete (xml); + nelement = -1; + return; + } + } + + if(xml->enterbranch(type) == 0) { + nelement = -1; + return; + } + if(nelement == -1) { + defaults(); + getfromXML(xml); + } + else { + defaults(nelement); + getfromXMLsection(xml, nelement); + } + 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::setelement(int n) +{ + nelement = n; +} + diff --git a/src/Params/PresetsArray.h b/src/Params/PresetsArray.h @@ -0,0 +1,60 @@ +/* + ZynAddSubFX - a software synthesizer + + PresetsArray.h - PresetsArray and Clipboard management + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + 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 PRESETSARRAY_H +#define PRESETSARRAY_H + +#include "../Misc/XMLwrapper.h" + +#include "Presets.h" + +/**PresetsArray and Clipboard management*/ +class PresetsArray : public Presets +{ + public: + 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(); + void deletepreset(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 add2XMLsection(XMLwrapper *xml, int n) = 0; + virtual void getfromXMLsection(XMLwrapper *xml, int n) = 0; + virtual void defaults(int n) = 0; + int nelement; +}; + +#endif + diff --git a/src/UI/PresetsUI.fl b/src/UI/PresetsUI.fl @@ -1,5 +1,5 @@ # data file for the Fltk User Interface Designer (fluid) -version 1.0105 +version 1.0107 header_name {.h} code_name {.cc} decl {\#include <FL/fl_ask.H>} {public @@ -11,6 +11,9 @@ decl {\#include <stdio.h>} {public decl {\#include <stdlib.h>} {public } +decl {\#include "../Params/PresetsArray.h"} {selected +} + decl {\#include "../Params/Presets.h"} {public } @@ -96,7 +99,7 @@ if (strlen(tmp)>0) { }else{ pastepbutton->activate(); deletepbutton->activate(); -};} selected +};} xywh {10 25 245 320} type Hold } Fl_Button pastepbutton { @@ -171,11 +174,15 @@ if (but) { };} {} } Function {copy(Presets *p,int n)} {} { - code {p->setelement(n); + code {PresetsArray *pre = dynamic_cast<PresetsArray *>(p); +if(pre) + pre->setelement(n); copy(p);} {} } Function {paste(Presets *p,PresetsUI_ *pui,int n)} {} { - code {p->setelement(n); + code {PresetsArray *pre = dynamic_cast<PresetsArray *>(p); +if(pre) + pre->setelement(n); paste(p,pui);} {} } Function {rescan()} {} {