VirKeyboard.fl (15111B)
1 # data file for the Fltk User Interface Designer (fluid) 2 version 1.0302 3 header_name {.h} 4 code_name {.cc} 5 decl {//Copyright (c) 2002-2005 Nasca Octavian Paul} {private local 6 } 7 8 decl {//License: GNU GPL version 2 or later} {private local 9 } 10 11 decl {\#include <cstdlib>} {public local 12 } 13 14 decl {\#include <FL/fl_draw.H>} {public local 15 } 16 17 decl {\#include <FL/Fl_Box.H>} {public local 18 } 19 20 decl {\#include "../globals.h"} {public local 21 } 22 23 decl {\#include "../Misc/Util.h"} {public local 24 } 25 26 decl {\#include "WidgetPDial.h"} {public local 27 } 28 29 decl {\#include "Fl_Osc_Counter.H"} {public local 30 } 31 32 decl {\#include "common.H"} {public local 33 } 34 35 decl {\#ifdef NTK_GUI 36 \#include "FL/Fl_Shared_Image.H" 37 \#endif} {public local 38 } 39 40 decl {using namespace zyn;} {public local 41 } 42 43 decl {const int keyspos[12]={0,-1,1,-2,2,3,-4,4,-5,5,-6,6};} {private local 44 } 45 46 decl {const int keysoct1qwerty[]={'q','2','w','3','e','r','5','t','6','y','7','u','i','9','o','0','p','[','=',']','\\\\',FL_Enter,0};} {private local 47 } 48 49 decl {const int keysoct2qwerty[]={'z','s','x','d','c','v','g','b','h','n','j','m',',','l','.',';','/',0};} {private local 50 } 51 52 decl {const int keysoct1dw[]={'\\'','2',',','3','.','p','5','y','6','f','7','g','c','9','r','0','l','/',']','=','\\\\',FL_Enter,0};} {private local 53 } 54 55 decl {const int keysoct2dw[]={';','o','q','e','j','k','i','x','d','b','h','m','w','n','v','s','z',0};} {private local 56 } 57 58 decl {const int keysoct1qwertz[]={'q','2','w','3','e','r','5','t','6','z','7','u','i','9','o','0','p',252,'\\'','+','\\\\',FL_Enter,0};} {private local 59 } 60 61 decl {const int keysoct2qwertz[]={'y','s','x','d','c','v','g','b','h','n','j','m',',','l','.',246,'-',0};} {private local 62 } 63 64 decl {const int keysoct1az[]={'a',233,'z','\\"','e','r','(','t','-','y',232,'u','i',231,'o',224,'p',65106,'=','$',0};} {private local 65 } 66 67 decl {const int keysoct2az[]={'w','s','x','d','c','v','g','b','h','n','j',',',';','l',':','m','!',0};} {private local 68 } 69 70 class VirKeys {open : {public Fl_Box, public Fl_Osc_Widget} 71 } { 72 decl {static const int N_OCT=6;} {private local 73 } 74 decl {static const int SIZE_WHITE=14;} {private local 75 } 76 decl {static const int SIZE_BLACK=8;} {private local 77 } 78 Function {VirKeys(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label),Fl_Osc_Widget()} {} { 79 code {} {} 80 } 81 Function {OSC_value(int layout)} {} { 82 code { 83 keylayout = layout; 84 } {} 85 } 86 Function {init(Fl_Osc_Interface *osc_, std::string loc_)} {open 87 } { 88 code {osc=osc_; 89 osc->createLink("/config/cfg.VirKeybLayout", this); 90 osc->requestValue("/config/cfg.VirKeybLayout"); 91 loc=loc_; 92 for (int i=0;i<N_OCT*12+1;i++) pressed[i]=0; 93 keylayout=0; 94 midich=0; 95 midivel=100; 96 midioct=2; 97 98 keyoct1=3; 99 keyoct2=2; 100 rndvelocity=0;} {selected 101 } 102 } 103 Function {draw()} {} { 104 code {int ox=x(),oy=y(),lx=w(),ly=h()-1,i; 105 106 \#ifdef NTK_GUI 107 \#ifdef CARLA_VERSION_STRING 108 Fl_Image *white_up = Fl_Shared_Image::get( gUiPixmapPath + "/white_key.png" ); 109 Fl_Image *white_down = Fl_Shared_Image::get( gUiPixmapPath + "/white_key_pressed.png" ); 110 Fl_Image *black_up = Fl_Shared_Image::get( gUiPixmapPath + "/black_key.png" ); 111 Fl_Image *black_down = Fl_Shared_Image::get( gUiPixmapPath + "/black_key_pressed.png" ); 112 \#else 113 Fl_Image *white_up = Fl_Shared_Image::get( PIXMAP_PATH "white_key.png" ); 114 Fl_Image *white_down = Fl_Shared_Image::get( PIXMAP_PATH "white_key_pressed.png" ); 115 Fl_Image *black_up = Fl_Shared_Image::get( PIXMAP_PATH "black_key.png" ); 116 Fl_Image *black_down = Fl_Shared_Image::get( PIXMAP_PATH "black_key_pressed.png" ); 117 \#endif 118 119 120 //On error fetch everything from source directory 121 if(!(white_up&&white_down&&black_up&&black_down)) { 122 white_up = Fl_Shared_Image::get(SOURCE_DIR "/pixmaps/white_key.png"); 123 white_down = Fl_Shared_Image::get(SOURCE_DIR "/pixmaps/white_key_pressed.png"); 124 black_up = Fl_Shared_Image::get(SOURCE_DIR "/pixmaps/black_key.png"); 125 black_down = Fl_Shared_Image::get(SOURCE_DIR "/pixmaps/black_key_pressed.png"); 126 } 127 128 Fl_Image *key; 129 130 for (i=0;i<N_OCT*12;i++) { 131 int noct=i/12; 132 int kv=keyspos[i%12]; 133 134 if (kv>=0){//white keys 135 if (pressed[i]==0) 136 key = white_up; 137 else 138 key = white_down; 139 140 key->draw( ox + (kv + 7 * noct ) * white_up->w() + 3, oy ); 141 } 142 } 143 144 for (i=0;i<N_OCT*12;i++){ 145 int noct=i/12; 146 int kv=keyspos[i%12]; 147 148 if ( kv < 0 ) { 149 kv=keyspos[(i+1)%12]; 150 if (pressed[i]==0) 151 key = black_up; 152 else 153 key = black_down; 154 155 key->draw( ox + (kv + 7 * noct ) * white_up->w() - black_up->w() / 2 + 2, oy ); 156 } 157 } 158 (void)lx; 159 (void)ly; 160 \#else 161 if (damage()!=1){ 162 fl_color(250,240,230); 163 fl_rectf(ox,oy,lx,ly); 164 165 fl_color(FL_BLACK); 166 fl_line(ox,oy,ox+lx,oy); 167 fl_line(ox,oy+ly,ox+lx,oy+ly); 168 for (i=0;i<N_OCT*7+1;i++){ 169 fl_line(ox+i*SIZE_WHITE,oy,ox+i*SIZE_WHITE,oy+ly); 170 int ik=i%7; 171 if ((ik==1)||(ik==2)||(ik==4)||(ik==5)||(ik==6)) 172 fl_rectf(ox+i*SIZE_WHITE-SIZE_BLACK/2,oy, 173 SIZE_BLACK+1,ly*3/5); 174 } 175 } 176 177 178 for (i=0;i<N_OCT*12;i++){ 179 // if (pressed[i]==0) continue; 180 181 int noct=i/12; 182 int kv=keyspos[i%12]; 183 184 if (kv>=0){//white keys 185 if (pressed[i]==0) fl_color(250,240,230); 186 else fl_color(FL_BLUE); 187 fl_rectf(ox+(kv+7*noct)*SIZE_WHITE+3,oy+ly*3/5+2, 188 SIZE_WHITE-4,ly*2/5-3); 189 } else {//black keys 190 kv=keyspos[(i+1)%12]; 191 if (pressed[i]==0) fl_color(FL_BLACK); 192 else fl_color(FL_BLUE); 193 fl_rectf(ox+(kv+7*noct)*SIZE_WHITE-SIZE_BLACK/2+2,oy+2, 194 SIZE_BLACK-3,ly*3/5-5); 195 } 196 } 197 \#endif} {} 198 } 199 Function {handle(int event)} {return_type int 200 } { 201 code {int i; 202 int ly=h(); 203 int x_=Fl::event_x()-x(); 204 int y_=Fl::event_y()-y(); 205 if ( (x_<0)&&(x_>w()) && (y_<0)&&(y_>h())){ 206 return(0); 207 }; 208 209 210 if ((event==FL_PUSH)||(event==FL_DRAG)||(event==FL_RELEASE)){ 211 int kpos=-1; 212 213 if (y_>ly*3/5){//white keys 214 int pos=x_/SIZE_WHITE; 215 if (pos<0) return(1); 216 for (i=0;i<12;i++) { 217 if (pos%7==keyspos[i]) { 218 kpos=pos/7*12+i; 219 break; 220 }; 221 }; 222 } else {//black keys 223 int pos=(x_+SIZE_WHITE/2)/SIZE_WHITE; 224 if (pos<0) return(1); 225 for (i=1;i<12;i++) { 226 if (pos%7==-keyspos[i]) { 227 kpos=pos/7*12+i; 228 break; 229 }; 230 }; 231 }; 232 233 if ((kpos!=-1)&&((event==FL_PUSH)||(event==FL_DRAG))&& 234 (Fl::event_shift()==0)) { 235 presskey(kpos,1,1); 236 }; 237 238 if ((event==FL_PUSH)&&(Fl::event_shift()!=0)) { 239 if (pressed[kpos]==0) presskey(kpos,0,1); 240 else releasekey(kpos,1); 241 }; 242 if ((event==FL_RELEASE)&&(Fl::event_shift()==0)) 243 releaseallkeys(1); 244 take_focus(); 245 }; 246 247 248 const int *keysoct1=keysoct1qwerty; 249 const int *keysoct2=keysoct2qwerty; 250 251 if (keylayout==2) { 252 keysoct1=keysoct1dw; 253 keysoct2=keysoct2dw; 254 }else if (keylayout==3) { 255 keysoct1=keysoct1qwertz; 256 keysoct2=keysoct2qwertz; 257 }else if (keylayout==4) { 258 keysoct1=keysoct1az; 259 keysoct2=keysoct2az; 260 }; 261 262 if ((event==FL_KEYDOWN)||(event==FL_KEYUP)){ 263 int key=Fl::event_key(); 264 int kpos=-1; 265 for (i=0;keysoct1[i]!=0;i++) if (key==keysoct1[i]) kpos=i+12*keyoct1; 266 for (i=0;keysoct2[i]!=0;i++) if (key==keysoct2[i]) kpos=i+12*keyoct2; 267 268 269 270 271 if (kpos==-1) return(0); 272 if ((event==FL_KEYUP) && (Fl::event_key(key)==0) && (Fl::get_key(key)!=0)) return(0); 273 if (event==FL_KEYDOWN) presskey(kpos,0,2); 274 else releasekey(kpos,2); 275 }; 276 277 return(1);} {} 278 } 279 Function {presskey(int nk,int exclusive,int type)} {} { 280 code {//Exclusive means that multiple keys can be pressed at once 281 //when the user uses the shift key 282 if (nk>=N_OCT*12) return; 283 if ((nk<0)&&(exclusive==0)) { 284 releaseallkeys(type); 285 return; 286 }; 287 if (nk<0) return; 288 if (pressed[nk]!=0) return;//the key is already pressed 289 290 if (exclusive!=0) releaseallkeys(type); 291 pressed[nk]=type; 292 293 damage(1); 294 float vel=midivel; 295 if (rndvelocity!=0){ 296 vel=midivel*(127.0-rndvelocity)/127.0+(rand()/RAND_MAX)*rndvelocity; 297 }; 298 299 osc->write(loc+"noteOn", "iii", midich,nk+midioct*12,(int)vel);} {} 300 } 301 Function {releasekey(int nk,int type)} {} { 302 code {if ((nk<0)||(nk>=N_OCT*12)) return; 303 if (pressed[nk]==0) return;//the key is not pressed 304 if ((type!=0)&&(pressed[nk]!=type)) return; 305 306 pressed[nk]=0; 307 308 309 damage(1); 310 311 osc->write(loc+"noteOff", "ii", midich,nk+12*midioct);} {} 312 } 313 Function {releaseallkeys(int type)} {} { 314 code {for (int i=0;i<N_OCT*12;i++) releasekey(i,type);} {} 315 } 316 decl {int pressed[N_OCT*12+1];} {private local 317 } 318 decl {unsigned char midich;} {public local 319 } 320 decl {int keylayout;} {public local 321 } 322 decl {unsigned char midivel;} {public local 323 } 324 decl {char midioct,keyoct1,keyoct2;} {public local 325 } 326 decl {unsigned char rndvelocity;} {public local 327 } 328 decl {Fl_Osc_Interface *osc;} {private local 329 } 330 decl {std::string loc;} {private local 331 } 332 } 333 334 class VirKeyboard {open 335 } { 336 Function {make_window()} {open 337 } { 338 Fl_Window virkeyboardwindow { 339 label {Virtual Keyboard - ZynAddSubFX} 340 callback {releaseallkeys(); 341 virkeyboardwindow->hide();} open 342 xywh {103 620 650 130} type Double visible 343 } { 344 Fl_Box virkeys { 345 label Keyboard 346 xywh {10 10 590 80} box FLAT_BOX color 17 347 code0 {o->init(osc,loc);} 348 class VirKeys 349 } 350 Fl_Counter {} { 351 label {"qwer.." Oct} 352 callback {releaseallkeys(); 353 virkeys->keyoct1=(int) o->value(); 354 virkeys->take_focus();} 355 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 356 code0 {o->value(virkeys->keyoct1);} 357 } 358 Fl_Counter {} { 359 label {"zxcv.." Oct} 360 callback {releaseallkeys(); 361 virkeys->keyoct2=(int) o->value(); 362 virkeys->take_focus();} 363 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 364 code0 {o->value(virkeys->keyoct2);} 365 } 366 Fl_Value_Slider {} { 367 label Vel 368 callback {virkeys->midivel=(int) o->value(); 369 virkeys->take_focus();} 370 tooltip Velocity xywh {95 105 100 15} type {Horz Knob} box NO_BOX labelsize 10 align 5 minimum 1 maximum 127 step 1 371 code0 {o->value(virkeys->midivel);} 372 } 373 Fl_Counter {} { 374 label {Oct.} 375 callback {releaseallkeys(); 376 virkeys->midioct=(int) o->value(); 377 virkeys->take_focus();} 378 tooltip {Midi Octave} xywh {255 100 55 20} type Simple labelsize 11 align 4 when 6 minimum 0 maximum 5 step 1 textfont 1 textsize 11 379 code0 {o->value(virkeys->midioct);} 380 } 381 Fl_Button {} { 382 label Close 383 callback {releaseallkeys(); 384 virkeyboardwindow->hide();} 385 xywh {545 105 55 20} box THIN_UP_BOX 386 } 387 Fl_Value_Slider {} { 388 label Cval 389 callback {int ctl=midictl; 390 391 osc->write("/setController", "iii", virkeys->midich,ctl,(int) o->value()); 392 virkeys->take_focus();} 393 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 394 } 395 Fl_Choice {} { 396 label Controller 397 callback {switch((int) o->value()+1){ 398 case 1: midictl=C_modwheel; break; 399 case 2: midictl=C_volume; break; 400 case 3: midictl=C_panning; break; 401 case 4: midictl=C_expression; break; 402 case 5: midictl=C_sustain; break; 403 case 6: midictl=C_portamento; break; 404 case 7: midictl=C_filterq; break; 405 case 8: midictl=C_filtercutoff; break; 406 case 9: midictl=C_bandwidth; break; 407 case 10: midictl=C_fmamp; break; 408 case 11: midictl=C_resonance_center; break; 409 case 12: midictl=C_resonance_bandwidth; break; 410 default: midictl=C_NULL; break; 411 412 }; 413 414 415 416 virkeys->take_focus();} 417 xywh {435 105 100 15} down_box BORDER_BOX labelsize 10 align 5 when 6 textfont 1 textsize 10 418 code0 {midictl=C_filtercutoff;o->value(7);} 419 } { 420 MenuItem {} { 421 label {01: Mod.Wheel} 422 xywh {0 0 100 20} labelfont 1 labelsize 10 423 } 424 MenuItem {} { 425 label {07: Volume} 426 xywh {10 10 100 20} labelfont 1 labelsize 10 427 } 428 MenuItem {} { 429 label {10: Panning} 430 xywh {20 20 100 20} labelfont 1 labelsize 10 431 } 432 MenuItem {} { 433 label {11: Expression} 434 xywh {30 30 100 20} labelfont 1 labelsize 10 435 } 436 MenuItem {} { 437 label {64: Sustain} 438 xywh {40 40 100 20} labelfont 1 labelsize 10 439 } 440 MenuItem {} { 441 label {65: Portamento} 442 xywh {50 50 100 20} labelfont 1 labelsize 10 443 } 444 MenuItem {} { 445 label {71: Filter Q} 446 xywh {60 60 100 20} labelfont 1 labelsize 10 447 } 448 MenuItem {} { 449 label {74: Filter Freq.} 450 xywh {70 70 100 20} labelfont 1 labelsize 10 451 } 452 MenuItem {} { 453 label {75: Bandwidth} 454 xywh {80 80 100 20} labelfont 1 labelsize 10 455 } 456 MenuItem {} { 457 label {76: FM Gain} 458 xywh {90 90 100 20} labelfont 1 labelsize 10 459 } 460 MenuItem {} { 461 label {77: Res. c. freq} 462 xywh {100 100 100 20} labelfont 1 labelsize 10 463 } 464 MenuItem {} { 465 label {78: Res. bw.} 466 xywh {110 110 100 20} labelfont 1 labelsize 10 467 } 468 } 469 Fl_Roller pitchwheelroller { 470 label Pwh 471 callback {osc->write("/setController", "iii", virkeys->midich,C_pitchwheel,-(int) o->value()); 472 virkeys->take_focus();} 473 tooltip {Pitch Wheel} xywh {625 10 20 95} labelsize 8 align 1 when 3 minimum -8192 maximum 8192 step 64 474 } 475 Fl_Button {} { 476 label R 477 callback {pitchwheelroller->value(0); 478 pitchwheelroller->do_callback();} 479 tooltip {Reset Pitch Bend} xywh {625 110 20 15} box THIN_UP_BOX labelfont 1 480 } 481 Fl_Dial {} { 482 label Vrnd 483 callback {virkeys->rndvelocity=(int) o->value();} 484 tooltip {Velocity Randomness} xywh {205 105 20 20} box ROUND_UP_BOX labelsize 10 align 129 maximum 127 step 1 485 code0 {o->value(virkeys->rndvelocity);} 486 class WidgetPDial 487 } 488 Fl_Choice partrcv { 489 label {MIDI Ch.} 490 callback {releaseallkeys(); 491 virkeys->midich=(int) o->value(); 492 virkeys->take_focus();} open 493 tooltip {Send to Midi Channel} xywh {20 105 65 20} down_box BORDER_BOX labelsize 10 align 5 textfont 1 textsize 10 494 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");};} 495 code1 {o->value(virkeys->midich);} 496 } {} 497 } 498 } 499 Function {VirKeyboard(Fl_Osc_Interface *osc_, std::string loc_)} {open 500 } { 501 code {osc=osc_; 502 loc=loc_; 503 midictl=75; 504 make_window();} {} 505 } 506 Function {~VirKeyboard()} {open 507 } { 508 code {delete virkeyboardwindow;} {} 509 } 510 Function {show()} {open 511 } { 512 code {virkeyboardwindow->show();} {} 513 } 514 Function {releaseallkeys()} {open 515 } { 516 code {virkeys->releaseallkeys(0);} {} 517 } 518 decl {int midictl;} {private local 519 } 520 decl {Fl_Osc_Interface *osc;} {private local 521 } 522 decl {std::string loc;} {private local 523 } 524 }