summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/synti/zynaddsubfx/UI/BankUI.fl
blob: cf1cfe9efd8e08a8be80cc15f55698811a6c53f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# data file for the Fltk User Interface Designer (fluid)
version 1.0104 
header_name {.h} 
code_name {.cc}
decl {//Copyright (c) 2002-2005 Nasca Octavian Paul} {} 

decl {//License: GNU GPL version 2} {} 

decl {\#include <stdlib.h>} {public
} 

decl {\#include <stdio.h>} {public
} 

decl {\#include <string.h>} {public
} 

decl {\#include <FL/Fl_Button.H>} {public
} 

decl {\#include <FL/Fl_File_Chooser.H>} {public
} 

decl {\#include "../Misc/Master.h"} {public
} 

decl {\#include "../Misc/Bank.h"} {public
} 

decl {\#include "../Misc/Config.h"} {public
} 

class BankProcess_ {} {
  Function {process()} {open return_type {virtual void}
  } {}
  decl {Bank *bank;} {public
  }
} 

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;
nselected=NULL;} {}
  }
  Function {handle(int event)} {return_type int
  } {
    code {if (what==NULL) return(0);
if (Fl::event_inside(this)){
  *what=0;*whatslot=nslot;
  if ((event==FL_RELEASE)&&(Fl::event_button()==1))*what=1;
  if ((event==FL_RELEASE)&&(Fl::event_button()==3))*what=2;
  if (event==FL_PUSH) highlight=1;
}else highlight=0;

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_,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()} {} {
    code {if (bank->emptyslot(nslot)) {
	color(46);
} else {
	if (bank->isPADsynth_used(nslot)) color(26);
		else color(51);
};

if (*nselected==nslot) color(6);


label(bank->getnamenumbered(nslot));} {}
  }
  decl {int *what,*whatslot,nslot,highlight, *nselected;} {}
  decl {void (BankProcess_:: *fnc)(void);} {}
  decl {BankProcess_ *bp;} {}
} 

class BankUI {: {public BankProcess_}
} {
  Function {make_window()} {} {
    Fl_Window bankuiwindow {
      label Bank
      xywh {4 64 785 575} type Double hide
      code0 {o->label(bank->bankfiletitle);}
      code1 {if (bank->bankfiletitle==NULL) o->label ("Choose a bank from the bank list on the left (or go to settings if to configure the bank location) or choose 'New Bank...' to make a new bank.");}
    } {
      Fl_Button {} {
        label Close
        callback {bankuiwindow->hide();}
        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_Group modeselect {
        xywh {5 528 425 42} box ENGRAVED_BOX
      } {
        Fl_Light_Button writebutton {
          label WRITE
          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;
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;
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();}
        }
      }
      Fl_Button {} {
        label {New Bank...}
        callback {const char *dirname;

dirname=fl_input("New empty Bank:");
if (dirname==NULL) return;


int result=bank->newbank(dirname);

if (result!=0) fl_alert("Error: Could not make a new bank (directory)..");

refreshmainwindow();}
        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 {705 529 60 15} down_box DOWN_BOX labelsize 10
        code0 {o->value(config.cfg.BankUIAutoClose);}
      }
      Fl_Choice banklist {
        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<BANK_SIZE;i++) bs[i]->refresh();
refreshmainwindow();} open
        xywh {5 8 220 20} down_box BORDER_BOX labelfont 1 align 0 textfont 1 textsize 12
      } {}
      Fl_Button {} {
        label {Refresh bank list}
        callback {rescan_for_banks();
banklist->value(0);}
        tooltip {Refresh the bank list (rescan)} xywh {230 8 105 20} box THIN_UP_BOX color 50 labelsize 12
      }
      Fl_Check_Button {} {
        label {Show PADsynth status}
        callback {config.cfg.CheckPADsynth=(int) o->value();
refreshmainwindow();}
        xywh {435 530 150 15} down_box DOWN_BOX labelsize 12
        code0 {o->value(config.cfg.CheckPADsynth);}
      }
    }
  }
  Function {BankUI(Master *master_,int *npart_)} {} {
    code {fnc=&BankProcess_::process;
master=master_;
npart=npart_;
bank=&master_->bank;
what=0;
nselected=-1;
make_window();
mode=1;} {}
  }
  Function {~BankUI()} {return_type virtual
  } {
    code {bankuiwindow->hide();
delete(bankuiwindow);} {}
  }
  Function {show()} {} {
    code {bankuiwindow->show();
simplesetmode(config.cfg.UserInterfaceMode==2);} {}
  }
  Function {hide()} {} {
    code {bankuiwindow->hide();} {}
  }
  Function {init(Fl_Valuator *cbwig_)} {} {
    code {cbwig=cbwig_;
rescan_for_banks();} {}
  }
  Function {process()} {return_type void
  } {
    code {int slot=this->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,-1);
    bs[slot]->refresh();
};

if ((what==1)&&(mode==1)&&(!bank->emptyslot(slot))){//Reads from slot
    master->busy=true;
     bank->loadfromslot(slot,master->part[*npart]);
    master->busy=false;
    master->part[*npart]->applyparameters();
    snprintf((char *)master->part[*npart]->Pname,PART_MAX_NAME_LEN,"%s",bank->getname(slot));
     cbwig->do_callback();
     
     if (config.cfg.BankUIAutoClose!=0)
         bankuiwindow->hide();

};

if ((what==1)&&(mode==2)){//save(write) to slot
     if (!bank->emptyslot(slot)){
       if (!fl_ask("Overwrite the slot no. %d ?",slot+1)) goto nooverwriteslot;
      };
       master->busy=true;
        bank->savetoslot(slot,master->part[*npart]);
       master->busy=false;

       bs[slot]->refresh();
       mode=1;readbutton->value(1);writebutton->value(0);
       nooverwriteslot:;
};



if ((what==1)&&(mode==3)&&(!bank->emptyslot(slot))){//Clears the slot
      if (fl_ask("Clear the slot no. %d ?",slot+1)){
          bank->clearslot(slot);
          bs[slot]->refresh();
      };
};

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);swapbutton->value(0);
nselected=-1;
if (bank->locked()){
    writebutton->deactivate();
    clearbutton->deactivate();
    swapbutton->deactivate();
} else {
    writebutton->activate();
    clearbutton->activate();
    swapbutton->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()} {} {
    code {banklist->clear();
banklist->add(" ");
bank->rescanforbanks();

for (int i=1;i<MAX_NUM_BANKS;i++) {
    if (bank->banks[i].name!=NULL) banklist->add(bank->banks[i].name);
};} {}
  }
  Function {simplesetmode(bool beginnerui)} {} {
    code {readbutton->value(1);
mode=1;
removeselection();
if (beginnerui) modeselect->hide();
	else modeselect->show();} {}
  }
  decl {BankSlot *bs[BANK_SIZE];} {}
  decl {int slot,what;//"what"=what button is pressed} {}
  decl {int mode,*npart,nselected;} {}
  decl {Master *master;} {}
  decl {void (BankProcess_::* fnc)(void);} {}
  decl {Fl_Valuator *cbwig;} {public
  }
}