zynaddsubfx

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

commit ac08dcaf674c56ac39c5c2b71051d39a3e1b4994
parent d7c8fa3bff2001296383f7cd5356249a65e131c0
Author: paulnasca <paulnasca>
Date:   Sun, 22 Aug 2004 17:42:20 +0000

*** empty log message ***

Diffstat:
MChangeLog | 1+
Msrc/Misc/Bank.C | 2+-
Msrc/Misc/XMLwrapper.C | 1+
Msrc/Params/Presets.C | 27++++++++++++++++++---------
Msrc/Params/Presets.h | 2+-
Msrc/Params/PresetsStore.C | 34+++++++++++++++++++++++++++++++++-
Msrc/Params/PresetsStore.h | 1+
Msrc/UI/PresetsUI.fl | 56++++++++++++++++++++++++++++++++++++++++++--------------
8 files changed, 98 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -699,5 +699,6 @@ 21 Aug 2004 - Am lucrat putin la salvare/incarcare a listei dir. cu presetari 22 Aug 2004 - Corectata o eroare de compilare - Makefile-ul modificat, a.i. make-ul sa se opreasca in caz de eroare + - Terminat managerul de preset-uri \ No newline at end of file diff --git a/src/Misc/Bank.C b/src/Misc/Bank.C @@ -222,7 +222,7 @@ int Bank::loadbank(const char *bankdirname){ while ((fn=readdir(dir))){ #ifndef OS_WINDOWS - if (fn->d_type!=DT_REG) continue;//this is not a regular file + if (fn->d_type!=DT_REG) continue; #endif const char *filename= fn->d_name; diff --git a/src/Misc/XMLwrapper.C b/src/Misc/XMLwrapper.C @@ -216,6 +216,7 @@ int XMLwrapper::loadXMLfile(const char *filename){ if (tree==NULL) return(-2);//this is not XML + node=root=mxmlFindElement(tree,tree,"ZynAddSubFX-data",NULL,NULL,MXML_DESCEND); if (root==NULL) return(-3);//the XML doesnt embbed zynaddsubfx data push(root); diff --git a/src/Params/Presets.C b/src/Params/Presets.C @@ -59,21 +59,30 @@ void Presets::copy(const char *name){ nelement=-1; }; -void Presets::paste(){ +void Presets::paste(int npreset){ char type[MAX_PRESETTYPE_SIZE]; strcpy(type,this->type); if (nelement!=-1) strcat(type,"n"); if (strstr(type,"Plfo")!=NULL) strcpy(type,"Plfo"); - if (!checkclipboardtype()) { - nelement=-1; - return; - }; XMLwrapper *xml=new XMLwrapper(); - if (!presetsstore.pasteclipboard(xml)) { - delete(xml); - nelement=-1; - return; + 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) { diff --git a/src/Params/Presets.h b/src/Params/Presets.h @@ -33,7 +33,7 @@ class Presets{ virtual ~Presets(); void copy(const char *name);//if name==NULL, the clipboard is used - void paste(); + void paste(int npreset);//npreset==0 for clipboard bool checkclipboardtype(); char type[MAX_PRESETTYPE_SIZE]; diff --git a/src/Params/PresetsStore.C b/src/Params/PresetsStore.C @@ -21,6 +21,8 @@ */ #include <stdlib.h> #include <string.h> +#include <dirent.h> +#include <sys/stat.h> #include "PresetsStore.h" #include "../Misc/Util.h" @@ -80,10 +82,31 @@ void PresetsStore::clearpresets(){ void PresetsStore::rescanforpresets(char *type){ clearpresets(); -// int presetk=0; + int presetk=0; + char ftype[MAX_STRING_SIZE]; + snprintf(ftype,MAX_STRING_SIZE,".%s.xpz",type); + for (int i=0;i<MAX_BANK_ROOT_DIRS;i++){ if (config.cfg.presetsDirList[i]==NULL) continue; + char *dirname=config.cfg.presetsDirList[i]; //de continuat aici + DIR *dir=opendir(dirname); + if (dir==NULL) continue; + struct dirent *fn; + while((fn=readdir(dir))){ + const char *filename=fn->d_name; + if (strstr(filename,ftype)==NULL) continue; + presets[presetk].file=new char [MAX_STRING_SIZE]; + presets[presetk].name=new char [MAX_STRING_SIZE]; + snprintf(presets[presetk].file,MAX_STRING_SIZE,"%s%s",dirname,filename); + snprintf(presets[presetk].name,MAX_STRING_SIZE,"%s",filename); + + char *tmp=strstr(presets[presetk].name,ftype); + if (tmp!=NULL) tmp[0]='\0'; + presetk++; if (presetk>=MAX_PRESETS) return; + }; + + closedir(dir); }; }; @@ -109,4 +132,13 @@ void PresetsStore::copypreset(XMLwrapper *xml,char *type, const char *name){ xml->saveXMLfile(filename); }; +bool PresetsStore::pastepreset(XMLwrapper *xml, int npreset){ + npreset--; + if (npreset>=MAX_PRESETS) return(false); + char *filename=presets[npreset].file; + if (filename==NULL) return(false); + bool result=(xml->loadXMLfile(filename)>=0); + return(result); +}; + diff --git a/src/Params/PresetsStore.h b/src/Params/PresetsStore.h @@ -38,6 +38,7 @@ class PresetsStore{ //presets stuff void copypreset(XMLwrapper *xml,char *type, const char *name); + bool pastepreset(XMLwrapper *xml, int npreset); struct presetstruct{ char *file; diff --git a/src/UI/PresetsUI.fl b/src/UI/PresetsUI.fl @@ -35,12 +35,12 @@ pastewin->hide();delete(pastewin);} {} } { Fl_Window copywin { label {Copy to Clipboard/Preset} - xywh {243 174 265 315} type Double box PLASTIC_THIN_UP_BOX color 238 non_modal visible + xywh {243 174 265 315} type Double box PLASTIC_THIN_UP_BOX color 238 hide modal } { Fl_Browser copybrowse { - xywh {10 25 245 205} + xywh {10 25 245 205} type Select } - Fl_Button {} { + Fl_Button copypbutton { label {Copy to Preset} callback {const char *tmp=presetname->value(); if (tmp!=NULL) { @@ -51,7 +51,7 @@ if (tmp!=NULL) { };} xywh {145 235 110 20} box THIN_UP_BOX } - Fl_Button {} { + Fl_Button copybutton { label {Copy to Clipboard} callback {p->copy(NULL); copywin->hide();} @@ -70,23 +70,38 @@ copywin->hide();} xywh {50 5 205 15} box FLAT_BOX color 238 labelfont 1 labelsize 12 align 20 } Fl_Input presetname { - xywh {10 235 130 20} + callback {const char *tmp=o->value(); +if (tmp==NULL) tmp=""; +if (strlen(tmp)>0) { + copybutton->deactivate(); + copypbutton->activate(); +} else { + copybutton->activate(); + copypbutton->deactivate(); +};} + xywh {10 235 130 20} when 1 } } Fl_Window pastewin { label {Paste from Clipboard/Preset} - xywh {516 204 265 315} type Double box PLASTIC_THIN_UP_BOX color 238 hide modal + xywh {343 225 265 315} type Double box PLASTIC_THIN_UP_BOX color 238 hide modal } { Fl_Browser pastebrowse { + callback {if (o->value()==0) pastepbutton->deactivate(); + else pastepbutton->activate();} xywh {10 30 245 205} type Hold } - Fl_Button {} { + Fl_Button pastepbutton { label {Paste from Preset} + callback {int n=pastebrowse->value(); +if (n!=0) p->paste(n); +pastewin->hide(); +pui->refresh();} selected xywh {50 240 160 20} box THIN_UP_BOX } Fl_Button pastebutton { label {Paste from Clipboard} - callback {p->paste(); + callback {p->paste(0); pastewin->hide(); pui->refresh();} xywh {25 270 90 35} box THIN_UP_BOX align 192 @@ -105,15 +120,19 @@ pui->refresh();} } } } - Function {copy(Presets *p)} {open - } { - code {this->p=p; + Function {copy(Presets *p)} {} { + code {copybutton->activate(); +copypbutton->deactivate(); + + +this->p=p; this->pui=NULL; bool but=(Fl::event_button()!=FL_LEFT_MOUSE); presetname->cut(0,presetname->maximum_size()); if (but) p->copy(NULL); else { + rescan(); copytypetext->label(&p->type[1]); copywin->show(); };} {} @@ -123,11 +142,13 @@ if (but) p->copy(NULL); code {this->p=p; this->pui=pui; bool but=(Fl::event_button()!=FL_LEFT_MOUSE); +pastepbutton->deactivate(); if (but) { - p->paste(); + p->paste(0); pui->refresh(); } else { + rescan(); pastetypetext->label(&p->type[1]); if (p->checkclipboardtype()) pastebutton->activate(); else pastebutton->deactivate(); @@ -145,8 +166,15 @@ paste(p,pui);} {} Function {rescan()} {open } { code {copybrowse->clear(); -pastebrowse->clear();} {selected - } +pastebrowse->clear(); +p->rescanforpresets(); + +for (int i=0;i<MAX_PRESETS;i++){ + char *name=presetsstore.presets[i].name; + if (name==NULL) break; + copybrowse->add(name); + pastebrowse->add(name); +};} {} } decl {Presets *p;} {public }