summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/synti/zynaddsubfx/UI/VirKeyboard.fl
blob: aed2c930b91fb9c20832fb7d1779743ff3613390 (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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# data file for the Fltk User Interface Designer (fluid)
version 1.0106 
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 <FL/fl_draw.H>} {public
} 

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

decl {\#include "../globals.h"} {public
} 

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

decl {\#include "../Input/MidiIn.h"} {public
} 

decl {\#include "WidgetPDial.h"} {public
} 

decl {const int keyspos[12]={0,-1,1,-2,2,3,-4,4,-5,5,-6,6};} {} 

decl {const int keysoct1qw[]={'q','2','w','3','e','r','5','t','6','y','7','u','i','9','o','0','p','[','=',']','\\\\',FL_Enter,0};} {} 

decl {const int keysoct2qw[]={'z','s','x','d','c','v','g','b','h','n','j','m',',','l','.',';','/',0};} {} 

decl {const int keysoct1dw[]={'\\'','2',',','3','.','p','5','y','6','f','7','g','c','9','r','0','l','/',']','=','\\\\',FL_Enter,0};} {} 

decl {const int keysoct2dw[]={';','o','q','e','j','k','i','x','d','b','h','m','w','n','v','s','z',0};} {} 

class VirKeys {: {public Fl_Box}
} {
  decl {static const int N_OCT=6;} {}
  decl {static const int SIZE_WHITE=14;} {}
  decl {static const int SIZE_BLACK=8;} {}
  Function {VirKeys(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
    code {master=NULL;} {}
  }
  Function {init(Master *master_)} {} {
    code {master=master_;
for (int i=0;i<N_OCT*12+1;i++) pressed[i]=0;
midich=0;
midivel=100;
midioct=2;

keyoct1=3;
keyoct2=2;
rndvelocity=0;} {}
  }
  Function {draw()} {} {
    code {int ox=x(),oy=y(),lx=w(),ly=h()-1,i;

if (damage()!=1){
 fl_color(250,240,230);
 fl_rectf(ox,oy,lx,ly);

 fl_color(FL_BLACK);
 fl_line(ox,oy,ox+lx,oy);
 fl_line(ox,oy+ly,ox+lx,oy+ly);
 for (i=0;i<N_OCT*7+1;i++){
   fl_line(ox+i*SIZE_WHITE,oy,ox+i*SIZE_WHITE,oy+ly);
   int ik=i%7;
   if ((ik==1)||(ik==2)||(ik==4)||(ik==5)||(ik==6)) 
     fl_rectf(ox+i*SIZE_WHITE-SIZE_BLACK/2,oy,
              SIZE_BLACK+1,ly*3/5);
 };
};


for (i=0;i<N_OCT*12;i++){
  // if (pressed[i]==0) continue;

   int noct=i/12;
   int kv=keyspos[i%12];

   if (kv>=0){//white keys
     if (pressed[i]==0) fl_color(250,240,230);
        else fl_color(FL_BLUE);
     fl_rectf(ox+(kv+7*noct)*SIZE_WHITE+3,oy+ly*3/5+2,
       SIZE_WHITE-4,ly*2/5-3);
   } else {//black keys
     kv=keyspos[(i+1)%12];
     if (pressed[i]==0) fl_color(FL_BLACK);
        else fl_color(FL_BLUE);
     fl_rectf(ox+(kv+7*noct)*SIZE_WHITE-SIZE_BLACK/2+2,oy+2,
              SIZE_BLACK-3,ly*3/5-5);
   };
};} {}
  }
  Function {handle(int event)} {return_type int
  } {
    code {int i;
int ly=h();
int x_=Fl::event_x()-x();
int y_=Fl::event_y()-y();
if ( (x_<0)&&(x_>w()) && (y_<0)&&(y_>h())){
  return(0);
};


if ((event==FL_PUSH)||(event==FL_DRAG)||(event==FL_RELEASE)){
   int kpos=-1;
  
   if (y_>ly*3/5){//white keys
       int pos=x_/SIZE_WHITE;
       if (pos<0) return(1);
       for (i=0;i<12;i++) {
          if (pos%7==keyspos[i]) {
             kpos=pos/7*12+i;
             break;
          };
       };
   } else {//black keys
       int pos=(x_+SIZE_WHITE/2)/SIZE_WHITE;
       if (pos<0) return(1);
       for (i=1;i<12;i++) {
          if (pos%7==-keyspos[i]) {
             kpos=pos/7*12+i;
             break;
          };
       };
   };

   if (((event==FL_PUSH)||(event==FL_DRAG))&&
       (Fl::event_shift()==0)) {
        presskey(kpos,1,1);
   };

   if ((event==FL_PUSH)&&(Fl::event_shift()!=0)) {
       if (pressed[kpos]==0) presskey(kpos,0,1);
          else relasekey(kpos,1);
   };
   if ((event==FL_RELEASE)&&(Fl::event_shift()==0))
        relaseallkeys(1);
   take_focus();
};


const int *keysoct1=keysoct1qw;
const int *keysoct2=keysoct2qw;

if (config.cfg.VirKeybLayout==2) {
	keysoct1=keysoct1dw;
	keysoct2=keysoct2dw;
};

if ((event==FL_KEYDOWN)||(event==FL_KEYUP)){
   int key=Fl::event_key();
   int kpos=-1;
   for (i=0;keysoct1[i]!=0;i++) if (key==keysoct1[i]) kpos=i+12*keyoct1;
   for (i=0;keysoct2[i]!=0;i++) if (key==keysoct2[i]) kpos=i+12*keyoct2;

   if (kpos==-1) return(0);
   if (event==FL_KEYDOWN) presskey(kpos,0,2);
      else relasekey(kpos,2);
};

return(1);} {}
  }
  Function {presskey(int nk,int exclusive,int type)} {} {
    code {if (nk>=N_OCT*12) return;
if ((nk<0)&&(exclusive==0)) {
  relaseallkeys(type);
  return;
};
if (pressed[nk]!=0) return;//the key is already pressed

if (exclusive!=0) relaseallkeys(type);
pressed[nk]=type;

damage(1);
float vel=midivel;
if (rndvelocity!=0){
  vel=midivel*(127.0-rndvelocity)/127.0+RND*rndvelocity;
};

master->busy=true;
 master->NoteOn(midich,nk+midioct*12,(int)vel);
master->busy=false;} {}
  }
  Function {relasekey(int nk,int type)} {} {
    code {if ((nk<0)||(nk>=N_OCT*12)) return;
if (pressed[nk]==0) return;//the key is not pressed
if ((type!=0)&&(pressed[nk]!=type)) return;

pressed[nk]=0;


damage(1);

master->busy=true;
 master->NoteOff(midich,nk+12*midioct);
master->busy=false;} {}
  }
  Function {relaseallkeys(int type)} {} {
    code {for (int i=0;i<N_OCT*12;i++) relasekey(i,type);} {}
  }
  decl {Master *master;} {}
  decl {int pressed[N_OCT*12+1];} {}
  decl {unsigned char midich;} {public
  }
  decl {unsigned char midivel;} {public
  }
  decl {char midioct,keyoct1,keyoct2;} {public
  }
  decl {unsigned char rndvelocity;} {public
  }
} 

class VirKeyboard {selected
} {
  Function {make_window()} {} {
    Fl_Window virkeyboardwindow {
      label {Virtual Keyboard - ZynAddSubFX}
      callback {relaseallkeys();
virkeyboardwindow->hide();}
      xywh {95 563 650 130} type Double hide
    } {
      Fl_Box virkeys {
        label Keyboard
        xywh {10 10 590 80} box FLAT_BOX color 17
        code0 {o->init(master);}
        class VirKeys
      }
      Fl_Counter {} {
        label {"qwer.." Oct}
        callback {relaseallkeys();
virkeys->keyoct1=(int) o->value();
virkeys->take_focus();}
        tooltip {keys "q2w3er5t6y..." octave} xywh {380 95 45 15} type Simple labelsize 10 align 4 when 6 minimum 0 maximum 5 step 1 textfont 1 textsize 10
        code0 {o->value(virkeys->keyoct1);}
      }
      Fl_Counter {} {
        label {"zxcv.." Oct}
        callback {relaseallkeys();
virkeys->keyoct2=(int) o->value();
virkeys->take_focus();}
        tooltip {keys "zsxdcvgbh..." octave} xywh {380 110 45 15} type Simple labelsize 10 align 4 when 6 minimum 0 maximum 5 step 1 textfont 1 textsize 10
        code0 {o->value(virkeys->keyoct2);}
      }
      Fl_Value_Slider {} {
        label Vel
        callback {virkeys->midivel=(int) o->value();
virkeys->take_focus();}
        tooltip Velocity xywh {95 105 100 15} type {Horz Knob} box FLAT_BOX labelsize 10 align 5 minimum 1 maximum 127 step 1
        code0 {o->value(virkeys->midivel);}
      }
      Fl_Counter {} {
        label {Oct.}
        callback {relaseallkeys();
virkeys->midioct=(int) o->value();
virkeys->take_focus();}
        tooltip {Midi Octave} xywh {255 100 55 20} type Simple labelsize 12 align 4 when 6 minimum 0 maximum 5 step 1 textfont 1 textsize 12
        code0 {o->value(virkeys->midioct);}
      }
      Fl_Button {} {
        label Close
        callback {relaseallkeys();
virkeyboardwindow->hide();}
        xywh {545 105 55 20} box THIN_UP_BOX
      }
      Fl_Value_Slider {} {
        label Cval
        callback {int ctl=midictl;

master->busy=true;
 master->SetController(virkeys->midich,ctl,(int) o->value());
master->busy=false;
virkeys->take_focus();}
        tooltip {Controller value} xywh {605 10 15 115} type {Vert Fill} box ENGRAVED_BOX selection_color 229 labelsize 8 align 5 minimum 127 maximum 0 step 1 value 64 textsize 7
      }
      Fl_Choice {} {
        label Controller
        callback {switch((int) o->value()+1){
   case 1: midictl=C_modwheel; break;
   case 2: midictl=C_volume; break;
   case 3: midictl=C_panning; break;
   case 4: midictl=C_expression; break;
   case 5: midictl=C_sustain; break;
   case 6: midictl=C_portamento; break;
   case 7: midictl=C_filterq; break;
   case 8: midictl=C_filtercutoff; break;
   case 9: midictl=C_bandwidth; break;
   case 10: midictl=C_fmamp; break;
   case 11: midictl=C_resonance_center; break;
   case 12: midictl=C_resonance_bandwidth; break;
   default: midictl=C_NULL; break;

};



virkeys->take_focus();}
        xywh {435 105 100 15} down_box BORDER_BOX labelsize 10 align 5 when 6 textfont 1 textsize 10
        code0 {midictl=C_filtercutoff;o->value(7);}
      } {
        menuitem {} {
          label {01: Mod.Wheel}
          xywh {0 0 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {07: Volume}
          xywh {10 10 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {10: Panning}
          xywh {20 20 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {11: Expression}
          xywh {30 30 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {64: Sustain}
          xywh {40 40 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {65: Portamento}
          xywh {50 50 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {71: Filter Q}
          xywh {60 60 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {74: Filter Freq.}
          xywh {70 70 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {75: Bandwidth}
          xywh {80 80 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {76: FM Gain}
          xywh {90 90 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {77: Res. c. freq}
          xywh {100 100 100 20} labelfont 1 labelsize 10
        }
        menuitem {} {
          label {78: Res. bw.}
          xywh {110 110 100 20} labelfont 1 labelsize 10
        }
      }
      Fl_Roller pitchwheelroller {
        label Pwh
        callback {master->lock();
 master->SetController(virkeys->midich,C_pitchwheel,-(int) o->value());
master->unlock();
virkeys->take_focus();}
        tooltip {Pitch Wheel} xywh {625 10 20 95} box PLASTIC_UP_BOX labelsize 8 align 1 when 3 minimum -8192 maximum 8192 step 64
      }
      Fl_Button {} {
        label R
        callback {pitchwheelroller->value(0);
pitchwheelroller->do_callback();}
        tooltip {Reset Pitch Bend} xywh {625 110 20 15} box THIN_UP_BOX labelfont 1
      }
      Fl_Dial {} {
        label Vrnd
        callback {virkeys->rndvelocity=(int) o->value();}
        tooltip {Velocity Randomness} xywh {205 105 20 20} box ROUND_UP_BOX labelsize 10 align 129 maximum 127 step 1
        code0 {o->value(virkeys->rndvelocity);}
        class WidgetPDial
      }
      Fl_Choice partrcv {
        label {MIDI Ch.}
        callback {relaseallkeys();
virkeys->midich=(int) o->value();
virkeys->take_focus();} open
        tooltip {Send to Midi Channel} xywh {20 105 65 20} down_box BORDER_BOX labelsize 10 align 5 textfont 1 textsize 10
        code0 {char nrstr[10]; for(int i=0;i<NUM_MIDI_CHANNELS;i++){sprintf(nrstr,"Chn%d",i+1);if (i!=9) o->add(nrstr); else o->add("Drum10");};}
        code1 {o->value(virkeys->midich);}
      } {}
    }
  }
  Function {VirKeyboard(Master *master_)} {} {
    code {master=master_;
midictl=75;
make_window();} {}
  }
  Function {show()} {} {
    code {virkeyboardwindow->show();} {}
  }
  Function {relaseallkeys()} {} {
    code {virkeys->relaseallkeys(0);} {}
  }
  decl {Master *master;} {}
  decl {int midictl;} {}
}