zynaddsubfx

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

commit 1a1aeaec929957b3725261daa8a89844dd6a7d0c
parent a03e086b9b0c837cb6cd9565d77a58926fa80b4f
Author: paulnasca <paulnasca>
Date:   Thu, 26 Feb 2004 19:59:24 +0000

*** empty log message ***

Diffstat:
MChangeLog | 4+++-
Msrc/Misc/Bank.C | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/Misc/Bank.h | 31+++++++++++++++++++++++++------
Msrc/Misc/Master.C | 10+++++-----
Msrc/Misc/Master.h | 5++++-
Msrc/UI/BankUI.fl | 2+-
6 files changed, 148 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -542,4 +542,6 @@ 15 Feb 2004 - O mica modificare la envelope parameters in sensul ca envelope-ul prestabilit la FM nu mai este liniar 22 Feb 2004 - Adaugat normalize Full RMS la Oscil 23 Feb 2004 - Inceput sa fac ca sa pot adauga Bank bazat pe XML (adaugat temporar clasa OldBank) - +24 Feb 2004 - Continuat la Bank +25 Feb 2004 - La Bank - inceput sa scriu partea ca sa arate instrumentele din banca +26 Feb 2004 - continuat la Bank diff --git a/src/Misc/Bank.C b/src/Misc/Bank.C @@ -24,17 +24,28 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <dirent.h> +/* #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> - +*/ Bank::Bank(){ + for (int i=0;i<BANK_SIZE;i++){ + ins[i].used=false; + memset(ins[i].name,0,PART_MAX_NAME_LEN+1); + ins[i].filename=NULL; + }; + + loadbank("bank_xml"); + }; Bank::~Bank(){ + clearbank(); }; @@ -51,9 +62,10 @@ char *Bank::getnamenumbered (unsigned char ninstrument){ }; /* - * Changes the name of an instrument + * Changes the name of an instrument (and the filename) */ void Bank::setname(unsigned char ninstrument,const char *newname){ +// if (ninstrument<0)&&() }; /* @@ -69,16 +81,16 @@ void Bank::clearslot(unsigned char ninstrument){ }; /* - * Save the instrument to a slot (the instrument is stored in a buffer who was filled - * with instrument parameters) + * Save the instrument to a slot */ -void Bank::savetoslot(unsigned char ninstrument,const char *name,Buffer *buf){ +void Bank::savetoslot(unsigned char ninstrument,const char *name,XMLwrapper *buf){ }; /* - * Loads the instrument from the bank to a buffer (who will be "dumped" to instrument parameters) + * Loads the instrument from the bank to a buffer */ -void Bank::loadfromslot(unsigned char ninstrument,Buffer *buf){ +void Bank::loadfromslot(unsigned char ninstrument,XMLwrapper *buf){ + }; @@ -86,19 +98,54 @@ void Bank::loadfromslot(unsigned char ninstrument,Buffer *buf){ /* * Load a bank from a file and makes it current */ -int Bank::loadfilebank(const char *newbankfilename){ -}; - -/* - * Save the bank to a file and makes it current - */ -int Bank::savefilebank(const char *newbankfilename, int overwrite){ +int Bank::loadbank(const char *bankdirname){ + DIR *dir=opendir(bankdirname); + + clearbank(); + + if (dir==NULL) return(-1); + + printf("%s/\n",bankdirname); + struct dirent *fn; + + char *remainfiles[BANK_SIZE]; + memset(remainfiles,0,sizeof(remainfiles)); + int remainfilek=0; + + while(fn=readdir(dir)){ + if (fn->d_type!=DT_REG) continue;//this is not a regular file + const char *filename= fn->d_name; + + //sa verific daca e si extensia dorita + + //verify if the name is like this NNNN-name (where N is a digit) + int no=0,startname=0; + + for (int i=0;i<4;i++) { + if (strlen(filename)<=i) break; + + if ((filename[i]>='0')&&(filename[i]<='9')) no=no*10+(filename[i]-'0'); + else if (startname!=0) startname=i; + }; + + + + if (no!=0){//the instrument position in the bank is found + addtobank(no-1,filename,&filename[startname]); + } else { + addtobank(-1,filename,filename); + }; + + }; + + + closedir(dir); }; /* * Makes a new bank, put it on a file and makes it current bank */ -int Bank::newfilebank(const char *newbankfilename, int overwrite){ +int Bank::newbank(const char *newbankdirname, int overwrite){ }; /* @@ -107,3 +154,51 @@ int Bank::newfilebank(const char *newbankfilename, int overwrite){ int Bank::locked(){ }; + +// private stuff + +void Bank::clearbank(){ + for (int i=0;i<BANK_SIZE;i++) deletefrombank(i); +}; + +int Bank::addtobank(int pos, const char *filename, const char* name){ + if ((pos>=0)&&(pos<BANK_SIZE)){ + if (ins[pos].used) pos=-1;//force it to find a new free position + } else if (pos>=BANK_SIZE) pos=-1; + + + if (pos<0) {//find a free position + for (int i=BANK_SIZE-1;i>=0;i--) + if (!ins[i].used) { + pos=i; + break; + }; + + }; + + if (pos<0) return (-1);//the bank is full + + printf("%s %d\n",filename,pos); + + deletefrombank(pos); + + ins[pos].used=true; + snprintf(ins[pos].name,PART_MAX_NAME_LEN,name); + + int len=strlen(filename); + ins[pos].filename=new char[len+1]; + snprintf(ins[pos].filename,len,"%s",filename); + + return(0); +}; + +void Bank::deletefrombank(int pos){ + if ((pos<0)||(pos>=BANK_SIZE)) return; + ins[pos].used=false; + memset(ins[pos].name,0,PART_MAX_NAME_LEN+1); + if (ins[pos].filename!=NULL) { + delete (ins[pos].filename); + ins[pos].filename=NULL; + }; +}; + diff --git a/src/Misc/Bank.h b/src/Misc/Bank.h @@ -24,7 +24,9 @@ #define BANK_H #include "../globals.h" -#include "Buffer.h" +#include "XMLwrapper.h" + +#define BANK_SIZE 128 class Bank{ public: @@ -35,15 +37,32 @@ class Bank{ void setname(unsigned char ninstrument,const char *newname); int emptyslot(unsigned char ninstrument); void clearslot(unsigned char ninstrument); - void savetoslot(unsigned char ninstrument,const char *name,Buffer *buf); - void loadfromslot(unsigned char ninstrument,Buffer *buf); - int loadfilebank(const char *newbankfilename); - int savefilebank(const char *newbankfilename,int overwrite); - int newfilebank(const char *newbankfilename,int overwrite); + void savetoslot(unsigned char ninstrument,const char *name,XMLwrapper *xml); + void loadfromslot(unsigned char ninstrument,XMLwrapper *xml); + + int loadbank(const char *bankdirname); +// int savebank(const char *newbankfilename,int overwrite); + int newbank(const char *newbankdirname,int overwrite); char *bankfiletitle; //this is shown on the UI of the bank (the title of the window) int locked(); private: + + //it adds a filename to the bank + //if pos is -1 it try to find a position + //returns -1 if the bank is full, or 0 if the instrument was added + int addtobank(int pos,const char* filename,const char* name); + + void deletefrombank(int pos); + + void clearbank(); + + + struct{ + bool used; + char name[PART_MAX_NAME_LEN+1]; + char *filename; + }ins[BANK_SIZE]; }; #endif diff --git a/src/Misc/Master.C b/src/Misc/Master.C @@ -703,17 +703,17 @@ void Master::exportbankasxmldirectory(const char *directory){ mkdir(directory,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); for (int slot=0;slot<128;slot++){ tmppart->defaults(); - bank.loadfromslot(slot,&slbuf); + oldbank.loadfromslot(slot,&slbuf); slbuf.changemode(0); tmppart->saveloadbuf(&slbuf,1); - snprintf((char *)tmppart->kit[0].Pname,PART_MAX_NAME_LEN,bank.getname(slot)); - snprintf((char *)tmppart->Pname,PART_MAX_NAME_LEN,bank.getname(slot)); - if (bank.emptyslot(slot)) continue; + snprintf((char *)tmppart->kit[0].Pname,PART_MAX_NAME_LEN,oldbank.getname(slot)); + snprintf((char *)tmppart->Pname,PART_MAX_NAME_LEN,oldbank.getname(slot)); + if (oldbank.emptyslot(slot)) continue; snprintf(nostr,10,"%4d",slot+1); for (int i=0;i<strlen(nostr);i++) if (nostr[i]==' ') nostr[i]='0'; - snprintf(filename,1000,"%s/%s-%s.xml",directory,nostr,bank.getname(slot)); + snprintf(filename,1000,"%s/%s-%s.xml",directory,nostr,oldbank.getname(slot)); printf("%s\n",filename); tmppart->saveXML(filename); }; diff --git a/src/Misc/Master.h b/src/Misc/Master.h @@ -32,6 +32,7 @@ #include "Microtonal.h" #include "OldBank.h" +#include "Bank.h" #include "Dump.h" #include "../Seq/Sequencer.h" #include "XMLwrapper.h" @@ -124,7 +125,9 @@ class Master{ //other objects Microtonal microtonal; - OldBank bank; + OldBank oldbank; + Bank bank; + FFTwrapper *fft; pthread_mutex_t mutex; diff --git a/src/UI/BankUI.fl b/src/UI/BankUI.fl @@ -216,7 +216,7 @@ if (tmp!=NULL) master->exportbankasxmldirectory(tmp);} selected code {fnc=&BankProcess_::process; master=master_; npart=npart_; -bank=&master_->bank; +bank=&master_->oldbank; what=0; make_window(); mode=1;} {}