commit 18effe58760fc9dbce66fe143a36ead58d339186
parent 5cd8f3a3a20b6219452e33becf4289c6a214a494
Author: paulnasca <paulnasca>
Date: Mon, 1 Mar 2004 19:59:26 +0000
*** empty log message ***
Diffstat:
7 files changed, 78 insertions(+), 40 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -550,7 +550,9 @@
- Corectata o eroare foarte veche la LFO amplitudine (amplitudinea nu scadea corespunzator)
28 Feb 2004 - Se poate incarca si salva instrumente in Bank
01 Mar 2004 - Se pot schimba bancile de instrumente
-
+ - Introduse si celelalte functii la Bank (cu exceptia salvarii/incarcarii locului bancii folosite)
+ - Se poate importa banci din bnk_zyn
+
diff --git a/src/Misc/Bank.C b/src/Misc/Bank.C
@@ -25,14 +25,8 @@
#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(){
memset(defaultinsname,0,PART_MAX_NAME_LEN);
snprintf(defaultinsname,PART_MAX_NAME_LEN,"%s"," ");
@@ -46,6 +40,8 @@ Bank::Bank(){
clearbank();
loadbank("bank_xml");
+
+ bankfiletitle=dirname;
};
@@ -75,7 +71,33 @@ char *Bank::getnamenumbered (unsigned int ninstrument){
* Changes the name of an instrument (and the filename)
*/
void Bank::setname(unsigned int ninstrument,const char *newname){
-// if (ninstrument<0)&&()
+ if (emptyslot(ninstrument)) return;
+
+ char newfilename[1000+1],tmpfilename[100+1];
+
+ memset(newfilename,0,1001);
+ memset(tmpfilename,0,101);
+ snprintf(tmpfilename,100,"%4d-%s",ninstrument+1,newname);
+
+ //add the zeroes at the start of filename
+ for (int i=0;i<4;i++) if (tmpfilename[i]==' ') tmpfilename[i]='0';
+
+ //make the filenames legal
+ for (int i=0;i<strlen(tmpfilename);i++) {
+ char c=tmpfilename[i];
+ if ((c>='0')&&(c<='9')) continue;
+ if ((c>='A')&&(c<='Z')) continue;
+ if ((c>='a')&&(c<='z')) continue;
+ if ((c=='-')||(c==' ')) continue;
+
+ tmpfilename[i]='_';
+ };
+
+ snprintf(newfilename,1000,"%s/%s.xmlz",dirname,tmpfilename);
+
+ rename(ins[ninstrument].filename,newfilename);
+ snprintf(ins[ninstrument].name,PART_MAX_NAME_LEN,"%s",&tmpfilename[5]);
+
};
/*
@@ -96,7 +118,6 @@ void Bank::clearslot(unsigned int ninstrument){
if (emptyslot(ninstrument)) return;
remove(ins[ninstrument].filename);
deletefrombank(ninstrument);
-
};
/*
@@ -145,14 +166,14 @@ void Bank::savetoslot(unsigned int ninstrument,Part *part){
};
/*
- * Loads the instrument from the bank to a buffer
+ * Loads the instrument from the bank
*/
void Bank::loadfromslot(unsigned int ninstrument,Part *part){
if (emptyslot(ninstrument)) return;
part->defaultsinstrument();
- printf("load: %s\n",ins[ninstrument].filename);
+ // printf("load: %s\n",ins[ninstrument].filename);
part->loadXMLinstrument(ins[ninstrument].filename);
@@ -172,7 +193,7 @@ int Bank::loadbank(const char *bankdirname){
dirname=new char[strlen(bankdirname)+1];
snprintf(dirname,strlen(bankdirname)+1,"%s",bankdirname);
- printf("%s/\n",bankdirname);
+ // printf("%s/\n",bankdirname);
struct dirent *fn;
@@ -226,14 +247,18 @@ int Bank::loadbank(const char *bankdirname){
/*
* Makes a new bank, put it on a file and makes it current bank
*/
-int Bank::newbank(const char *newbankdirname, int overwrite){
+int Bank::newbank(const char *newbankdirname){
+ int result=mkdir(newbankdirname,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+ if (result<0) return(-1);
+
+ return(loadbank(newbankdirname));
};
/*
* Check if the bank is locked (i.e. the file opened was readonly)
*/
int Bank::locked(){
- return(0);
+ return(dirname==NULL);
};
// private stuff
@@ -261,7 +286,7 @@ int Bank::addtobank(int pos, const char *filename, const char* name){
if (pos<0) return (-1);//the bank is full
- printf("%s %d\n",filename,pos);
+ // printf("%s %d\n",filename,pos);
deletefrombank(pos);
diff --git a/src/Misc/Bank.h b/src/Misc/Bank.h
@@ -46,7 +46,7 @@ class Bank{
int loadbank(const char *bankdirname);
// int savebank(const char *newbankfilename,int overwrite);
- int newbank(const char *newbankdirname,int overwrite);
+ int newbank(const char *newbankdirname);
char *bankfiletitle; //this is shown on the UI of the bank (the title of the window)
int locked();
diff --git a/src/Misc/Config.C b/src/Misc/Config.C
@@ -120,6 +120,8 @@ void Config::readConfig(char *filename){
par[0]=0;val[0]=0;
if (sscanf(line,"%s = %s",par,val)!=2) continue;//bad line
if ((strlen(par)<1)|| (strlen(val)<1)) continue;//empty parameter/value
+
+// printf("%s\n",val);
int intvalue=0;
diff --git a/src/Misc/Master.C b/src/Misc/Master.C
@@ -695,14 +695,25 @@ void Master::saveloadbuf(Buffer *buf){
};
};
-void Master::exportbankasxmldirectory(const char *directory){
- char filename[1000],nostr[10];
+void Master::exportbankasxmldirectory(const char *bankfilename){
+ char filename[1000],directory[1000],nostr[10];
Part *tmppart=new Part(µtonal,fft,&mutex);
tmppart->Penabled=1;
+
+ int pos=strlen(bankfilename)-20;
+ if (pos<0) pos=0;
+ snprintf(directory,1000,"export-%s",&bankfilename[pos]);
+ for (int i=0;i<strlen(directory);i++){
+ if ((directory[i]=='/')||(directory[i]=='\\')||(directory[i]=='.'))
+ directory[i]='_';
+ };
+
+
mkdir(directory,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
for (int slot=0;slot<128;slot++){
tmppart->defaults();
+ oldbank.loadfilebank(bankfilename);
oldbank.loadfromslot(slot,&slbuf);
slbuf.changemode(0);
tmppart->saveloadbuf(&slbuf,1);
@@ -717,7 +728,8 @@ void Master::exportbankasxmldirectory(const char *directory){
printf("%s\n",filename);
tmppart->saveXML(filename);
};
-
+
+ bank.loadbank(directory);
delete (tmppart);
};
diff --git a/src/Misc/Master.h b/src/Misc/Master.h
@@ -44,7 +44,7 @@ class Master{
~Master();
void saveloadbuf(Buffer *buf);
- void exportbankasxmldirectory(const char *directory);
+ void exportbankasxmldirectory(const char *bankfilename);
//saves all settings to a XML file
//returns 0 for ok, 1 if there is a existing file or -1 if there is an error
diff --git a/src/UI/BankUI.fl b/src/UI/BankUI.fl
@@ -151,27 +151,18 @@ if (dirname==NULL) return;
if (bank->loadbank(dirname)==2)
fl_alert("Error: Could not load the bank from the directory.");
for (int i=0;i<128;i++) bs[i]->refresh();
-refreshmainwindow();} selected
+refreshmainwindow();}
xywh {330 385 95 20} box PLASTIC_UP_BOX labelfont 1 labelsize 12 align 128
}
Fl_Button {} {
label {New Bank...}
- callback {char *filename;
-\#define EXT ".bnk_zyn"
-filename=fl_file_chooser("New empty Bank:","(*"EXT")",NULL,0);
-if (filename==NULL) return;
-filename=fl_filename_setext(filename,EXT);
-\#undef EXT
+ callback {char *dirname;
+dirname=fl_dir_chooser("New empty Bank:",NULL,0);
+if (dirname==NULL) return;
-if (filename==NULL) return;
-int result=bank->newbank(filename,0);
-if (result==1) {
- if (fl_ask("The file exists. \\nOverwrite it?")){
- result=bank->newbank(filename,1);
- } else return;
+int result=bank->newbank(dirname);
-};
-if (result!=0) fl_alert("Error: Could not save the bank to the file..");
+if (result!=0) fl_alert("Error: Could not make a new bank (directory)..");
for (int i=0;i<128;i++) bs[i]->refresh();
refreshmainwindow();}
xywh {330 407 93 20} box PLASTIC_UP_BOX labelfont 1 labelsize 12 align 128
@@ -183,10 +174,16 @@ refreshmainwindow();}
code0 {o->value(config.cfg.BankUIAutoClose);}
}
Fl_Button {} {
- label {XML export}
- callback {const char *tmp=fl_input("Enter the directory:","bank_xml");
-if (tmp!=NULL) master->exportbankasxmldirectory(tmp);}
- xywh {508 390 37 35} box PLASTIC_UP_BOX labelsize 11 align 128
+ label {IMPORT from bnk_zyn}
+ callback {const char *filename;
+filename=fl_file_chooser("Convert Bank from bnk_zyn file:","(*.bnk_zyn)",NULL,0);
+if (filename==NULL) return;
+
+master->exportbankasxmldirectory(filename);
+
+for (int i=0;i<128;i++) bs[i]->refresh();
+refreshmainwindow();} selected
+ xywh {440 385 105 40} box PLASTIC_UP_BOX color 175 labelfont 1 labelsize 15 labelcolor 0 align 128
}
}
}