commit 52db8d1316321e02c9c2e59f44b3d5e4fcb26352
parent bbf0e0041117996f43c7a74199e9a2947449458a
Author: paulnasca <paulnasca>
Date: Sun, 13 Jun 2004 20:01:15 +0000
*** empty log message ***
Diffstat:
3 files changed, 131 insertions(+), 66 deletions(-)
diff --git a/src/Misc/Bank.C b/src/Misc/Bank.C
@@ -150,14 +150,15 @@ char *Bank::getnamenumbered (unsigned int ninstrument){
/*
* Changes the name of an instrument (and the filename)
*/
-void Bank::setname(unsigned int ninstrument,const char *newname){
+void Bank::setname(unsigned int ninstrument,const char *newname,int newslot){
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);
+ if (newslot>=0) snprintf(tmpfilename,100,"%4d-%s",newslot+1,newname);
+ else 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';
@@ -176,6 +177,7 @@ void Bank::setname(unsigned int ninstrument,const char *newname){
snprintf(newfilename,1000,"%s/%s.xmlz",dirname,tmpfilename);
rename(ins[ninstrument].filename,newfilename);
+ snprintf(ins[ninstrument].filename,PART_MAX_NAME_LEN,"%s",newfilename);
snprintf(ins[ninstrument].name,PART_MAX_NAME_LEN,"%s",&tmpfilename[5]);
};
@@ -253,7 +255,7 @@ void Bank::loadfromslot(unsigned int ninstrument,Part *part){
part->defaultsinstrument();
- // printf("load: %s\n",ins[ninstrument].filename);
+// printf("load: %s\n",ins[ninstrument].filename);
part->loadXMLinstrument(ins[ninstrument].filename);
@@ -357,6 +359,26 @@ int Bank::locked(){
};
/*
+ * Swaps a slot with another
+ */
+void Bank::swapslot(unsigned int n1, unsigned int n2){
+ if ((n1==n2)||(locked())) return;
+ if (emptyslot(n1)&&(emptyslot(n2))) return;
+ if (emptyslot(n1)){//change n1 to n2 in order to make
+ int tmp=n2;n2=n1;n1=tmp;
+ };
+
+ if (emptyslot(n2)){//this is just a movement from slot1 to slot2
+ setname(n1,getname(n1),n2);
+ ins[n2]=ins[n1];
+ ins[n1].used=false;
+ ins[n1].name[0]='\0';
+ ins[n1].filename=NULL;
+ };
+
+};
+
+/*
* Re-scan for directories containing instrument banks
*/
diff --git a/src/Misc/Bank.h b/src/Misc/Bank.h
@@ -27,7 +27,7 @@
#include "XMLwrapper.h"
#include "Part.h"
-#define BANK_SIZE 128
+#define BANK_SIZE 160
/*
* The max. number of banks that are used
@@ -42,7 +42,7 @@ class Bank{
~Bank();
char *getname(unsigned int ninstrument);
char *getnamenumbered(unsigned int ninstrument);
- void setname(unsigned int ninstrument,const char *newname);
+ void setname(unsigned int ninstrument,const char *newname,int newslot);//if newslot==-1 then this is ignored, else it will be put on that slot
//returns 0 if the slot is not empty or 1 if the slot is empty
int emptyslot(unsigned int ninstrument);
@@ -51,8 +51,9 @@ class Bank{
void savetoslot(unsigned int ninstrument,Part *part);
void loadfromslot(unsigned int ninstrument,Part *part);
+ void swapslot(unsigned int n1,unsigned int n2);
+
int loadbank(const char *bankdirname);
-// int savebank(const char *newbankfilename,int overwrite);
int newbank(const char *newbankdirname);
char *bankfiletitle; //this is shown on the UI of the bank (the title of the window)
diff --git a/src/UI/BankUI.fl b/src/UI/BankUI.fl
@@ -39,7 +39,8 @@ class BankSlot {: {public Fl_Button,BankProcess_}
Function {BankSlot(int x,int y, int w, int h, const char *label=0):Fl_Button(x,y,w,h,label)} {} {
code {what=NULL;
whatslot=NULL;
-nslot=0;} {}
+nslot=0;
+nselected=NULL;} {}
}
Function {handle(int event)} {return_type int
} {
@@ -55,91 +56,106 @@ int tmp=Fl_Button::handle(event);
if ((*what!=0) && Fl::event_inside(this)) (bp->*fnc)();
return(tmp);} {}
}
- Function {init(int nslot_, int *what_, int *whatslot_,void (BankProcess_:: *fnc_)(void),BankProcess_ *bp_,Bank *bank_)} {} {
+ Function {init(int nslot_, int *what_, int *whatslot_,void (BankProcess_:: *fnc_)(void),BankProcess_ *bp_,Bank *bank_,int *nselected_)} {} {
code {nslot=nslot_;
what=what_;
whatslot=whatslot_;
fnc=fnc_;
bp=bp_;
bank=bank_;
+nselected=nselected_;
box(FL_THIN_UP_BOX);
align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP);
highlight=0;
refresh();} {}
}
- Function {refresh()} {} {
+ Function {refresh()} {open
+ } {
code {if (bank->emptyslot(nslot)) color(46);
else color(51);
+if (*nselected==nslot) color(80);
-//printf("%s\\n",bank->getnamenumbered(nslot));
label(bank->getnamenumbered(nslot));} {}
}
- decl {int *what,*whatslot,nslot,highlight;} {}
+ decl {int *what,*whatslot,nslot,highlight, *nselected;} {}
decl {void (BankProcess_:: *fnc)(void);} {}
decl {BankProcess_ *bp;} {}
}
class BankUI {open : {public BankProcess_}
} {
- Function {make_window()} {open
- } {
+ Function {make_window()} {} {
Fl_Window bankuiwindow {
- label Bank selected
- xywh {57 89 770 485} type Double
+ label Bank
+ xywh {4 64 785 575} type Double
code0 {o->label(bank->bankfiletitle);}
code1 {if (bank->bankfiletitle==NULL) o->label ("Choose a bank to use by pressing the 'Load/Use Bank from file...' button or choose 'New Bank...' to make a new bank.");} visible
} {
Fl_Button {} {
label Close
callback {bankuiwindow->hide();}
- xywh {554 455 60 24} box THIN_UP_BOX
+ xywh {705 546 70 24} box THIN_UP_BOX
+ }
+ Fl_Group {} {
+ xywh {5 34 772 491} box ENGRAVED_FRAME
+ } {
+ Fl_Pack {} {
+ xywh {10 39 150 481} box BORDER_BOX
+ code0 {o->box(FL_NO_BOX);}
+ code1 {for (int i=0;i<32;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank,&nselected);};}
+ } {}
+ Fl_Pack {} {
+ xywh {163 39 150 481} box BORDER_BOX
+ code0 {o->box(FL_NO_BOX);}
+ code1 {for (int i=32;i<64;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank,&nselected);};}
+ } {}
+ Fl_Pack {} {
+ xywh {316 39 150 481} box BORDER_BOX
+ code0 {o->box(FL_NO_BOX);}
+ code1 {for (int i=64;i<96;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank,&nselected);};}
+ } {}
+ Fl_Pack {} {
+ xywh {469 39 150 481} box BORDER_BOX
+ code0 {o->box(FL_NO_BOX);}
+ code1 {for (int i=96;i<128;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank,&nselected);};}
+ } {}
+ Fl_Pack {} {
+ xywh {622 39 150 481} box BORDER_BOX
+ code0 {o->box(FL_NO_BOX);}
+ code1 {for (int i=128;i<160;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank,&nselected);};}
+ } {}
}
- Fl_Pack {} {
- xywh {5 59 150 375} box BORDER_BOX
- code0 {o->box(FL_NO_BOX);}
- code1 {for (int i=0;i<25;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank);};}
- } {}
- Fl_Pack {} {
- xywh {158 59 150 375} box BORDER_BOX
- code0 {o->box(FL_NO_BOX);}
- code1 {for (int i=25;i<50;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank);};}
- } {}
- Fl_Pack {} {
- xywh {311 59 150 375} box BORDER_BOX
- code0 {o->box(FL_NO_BOX);}
- code1 {for (int i=50;i<75;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank);};}
- } {}
- Fl_Pack {} {
- xywh {464 59 150 375} box BORDER_BOX
- code0 {o->box(FL_NO_BOX);}
- code1 {for (int i=75;i<100;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank);};}
- } {}
- Fl_Pack {} {
- xywh {617 59 150 420} box BORDER_BOX
- code0 {o->box(FL_NO_BOX);}
- code1 {for (int i=100;i<128;i++){bs[i]=new BankSlot (0,0,o->w(),15," ");bs[i]->init(i,&what,&slot,&BankProcess_::process,(BankProcess_ *)this,bank);};}
- } {}
Fl_Group {} {
- xywh {5 437 321 42} box ENGRAVED_BOX
+ xywh {5 528 425 42} box ENGRAVED_BOX
} {
Fl_Light_Button writebutton {
label WRITE
- callback {if (o->value()>0.5) mode=2}
- xywh {116 443 99 30} type Radio box PLASTIC_UP_BOX down_box THIN_DOWN_BOX selection_color 1 labeltype ENGRAVED_LABEL labelfont 1 labelsize 18
+ callback {if (o->value()>0.5) mode=2;
+removeselection();}
+ xywh {116 534 99 30} type Radio box PLASTIC_UP_BOX down_box THIN_DOWN_BOX selection_color 1 labeltype ENGRAVED_LABEL labelfont 1 labelsize 18
code0 {if (bank->locked()) o->deactivate();}
}
Fl_Light_Button readbutton {
label READ
- callback {if (o->value()>0.5) mode=1;}
- xywh {11 443 99 30} type Radio box PLASTIC_UP_BOX down_box THIN_DOWN_BOX selection_color 101 labeltype ENGRAVED_LABEL labelfont 1 labelsize 18
+ callback {if (o->value()>0.5) mode=1;
+removeselection();}
+ xywh {11 534 99 30} type Radio box PLASTIC_UP_BOX down_box THIN_DOWN_BOX selection_color 101 labeltype ENGRAVED_LABEL labelfont 1 labelsize 18
code0 {o->value(1);}
}
Fl_Light_Button clearbutton {
label CLEAR
- callback {if (o->value()>0.5) mode=3;}
- xywh {221 443 99 30} type Radio box PLASTIC_UP_BOX down_box THIN_DOWN_BOX selection_color 0 labeltype ENGRAVED_LABEL labelfont 1 labelsize 18
+ callback {if (o->value()>0.5) mode=3;
+removeselection();}
+ xywh {221 534 99 30} type Radio box PLASTIC_UP_BOX down_box THIN_DOWN_BOX selection_color 0 labeltype ENGRAVED_LABEL labelfont 1 labelsize 18
+ code0 {if (bank->locked()) o->deactivate();}
+ }
+ Fl_Light_Button swapbutton {
+ label SWAP
+ callback {if (o->value()>0.5) mode=4;
+removeselection();}
+ xywh {325 534 99 30} type Radio box PLASTIC_UP_BOX down_box THIN_DOWN_BOX selection_color 227 labeltype ENGRAVED_LABEL labelfont 1 labelsize 18
code0 {if (bank->locked()) o->deactivate();}
}
}
@@ -154,14 +170,14 @@ if (dirname==NULL) return;
int result=bank->newbank(dirname);
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 {335 445 93 25} box PLASTIC_UP_BOX labelfont 1 labelsize 12 align 128
+ xywh {685 5 93 25} box PLASTIC_UP_BOX labelfont 1 labelsize 12 align 128
}
Fl_Check_Button {} {
label {auto close}
callback {config.cfg.BankUIAutoClose=(int) o->value();}
- tooltip {automatically close the bank window if the instrument is loaded} xywh {554 438 60 15} down_box DOWN_BOX labelsize 10
+ tooltip {automatically close the bank window if the instrument is loaded} xywh {705 529 60 15} down_box DOWN_BOX labelsize 10
code0 {o->value(config.cfg.BankUIAutoClose);}
}
Fl_Button {} {
@@ -172,27 +188,26 @@ if (filename==NULL) return;
master->exportbankasxmldirectory(filename);
-for (int i=0;i<128;i++) bs[i]->refresh();
+
refreshmainwindow();}
- xywh {439 438 105 40} box PLASTIC_UP_BOX color 175 labelfont 1 labelsize 15 labelcolor 0 align 128
+ xywh {515 530 105 40} box PLASTIC_UP_BOX color 175 labelfont 1 labelsize 15 labelcolor 0 align 128
}
Fl_Choice banklist {
- label Bank
callback {int n=o->value();
char *dirname=bank->banks[n].dir;
if (dirname==NULL) return;
if (bank->loadbank(dirname)==2)
fl_alert("Error: Could not load the bank from the directory\\n%s.",dirname);
-for (int i=0;i<128;i++) bs[i]->refresh();
+for (int i=0;i<BANK_SIZE;i++) bs[i]->refresh();
refreshmainwindow();} open
- xywh {5 20 205 20} down_box BORDER_BOX labelfont 1 align 5 textfont 1 textsize 12
+ xywh {5 8 220 20} down_box BORDER_BOX labelfont 1 align 0 textfont 1 textsize 12
} {}
Fl_Button {} {
- label Refresh
+ label {Refresh bank list}
callback {rescan_for_banks();
banklist->value(0);}
- tooltip {Refresh the bank list (rescan)} xywh {215 20 40 20} box THIN_UP_BOX labelsize 10
+ tooltip {Refresh the bank list (rescan)} xywh {230 8 105 20} box THIN_UP_BOX labelsize 12
}
}
}
@@ -202,6 +217,7 @@ master=master_;
npart=npart_;
bank=&master_->bank;
what=0;
+nselected=-1;
make_window();
mode=1;} {}
}
@@ -221,9 +237,9 @@ rescan_for_banks();} {}
} {
code {int slot=this->slot;
-if ((what==2)&&(bank->emptyslot(slot)==0)) {//Rename slot
+if ((what==2)&&(bank->emptyslot(slot)==0)&&(mode!=4)) {//Rename slot
const char *tmp=fl_input("Slot (instrument) name:",(const char *)bank->getname(slot));
- if (tmp!=NULL) bank->setname(slot,tmp);
+ if (tmp!=NULL) bank->setname(slot,tmp,-1);
bs[slot]->refresh();
};
@@ -265,21 +281,47 @@ if ((what==1)&&(mode==3)&&(!bank->emptyslot(slot))){//Clears the slot
};
};
-refreshmainwindow();} {}
+if (mode==4){//swap
+ bool done=false;
+ if ((what==1)&&(nselected>=0)){
+ bank->swapslot(nselected,slot);
+ int ns=nselected;
+ nselected=-1;
+ bs[slot]->refresh();
+ bs[ns]->refresh();
+ done=true;
+ };
+ if (((nselected<0)||(what==2))&&(!done)){
+ int ns=nselected;
+ nselected=slot;
+ if (ns>0) bs[ns]->refresh();
+ bs[slot]->refresh();
+ };
+};
+if (mode!=4) refreshmainwindow();} {selected
+ }
}
Function {refreshmainwindow()} {} {
code {bankuiwindow->label(bank->bankfiletitle);
-mode=1;readbutton->value(1);writebutton->value(0);clearbutton->value(0);
+mode=1;readbutton->value(1);writebutton->value(0);clearbutton->value(0);swapbutton->value(0);
+nselected=-1;
if (bank->locked()){
writebutton->deactivate();
clearbutton->deactivate();
} else {
writebutton->activate();
clearbutton->activate();
+};
+for (int i=0;i<BANK_SIZE;i++) bs[i]->refresh();} {}
+ }
+ Function {removeselection()} {} {
+ code {if (nselected>=0) {
+ int ns=nselected;
+ nselected=-1;
+ bs[ns]->refresh();
};} {}
}
- Function {rescan_for_banks()} {open
- } {
+ Function {rescan_for_banks()} {} {
code {banklist->clear();
banklist->add(" ");
bank->rescanforbanks();
@@ -288,9 +330,9 @@ for (int i=1;i<MAX_NUM_BANKS;i++) {
if (bank->banks[i].name!=NULL) banklist->add(bank->banks[i].name);
};} {}
}
- decl {BankSlot *bs[128];} {}
+ decl {BankSlot *bs[BANK_SIZE];} {}
decl {int slot,what;//"what"=what button is pressed} {}
- decl {int mode,*npart;} {}
+ decl {int mode,*npart,nselected;} {}
decl {Master *master;} {}
decl {void (BankProcess_::* fnc)(void);} {}
decl {Fl_Valuator *cbwig;} {public