home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / ZynAddFX / Setup_ZynAddSubFX-2.1.1.exe / VirKeyboard.fl < prev    next >
Encoding:
FLTK User Interface Designer  |  2004-07-03  |  11.0 KB  |  387 lines

  1. # data file for the Fltk User Interface Designer (fluid)
  2. version 1.0105 
  3. header_name {.h} 
  4. code_name {.cc}
  5. decl {//Copyright (c) 2002-2004 Nasca Octavian Paul} {} 
  6.  
  7. decl {//License: GNU GPL version 2} {} 
  8.  
  9. decl {\#include <stdlib.h>} {public
  10.  
  11. decl {\#include <FL/fl_draw.H>} {public
  12.  
  13. decl {\#include <FL/Fl_Box.H>} {public
  14.  
  15. decl {\#include "../globals.h"} {public
  16.  
  17. decl {\#include "../Misc/Master.h"} {public
  18.  
  19. decl {\#include "../Input/MidiIn.h"} {public
  20.  
  21. decl {\#include "WidgetPDial.h"} {public
  22.  
  23. decl {const int keyspos[12]={0,-1,1,-2,2,3,-4,4,-5,5,-6,6};} {} 
  24.  
  25. decl {const int keysoct1[]={'q','2','w','3','e','r','5','t','6','y','7','u','i','9','o','0','p','[','=',']','\\\\',FL_Enter,0};} {} 
  26.  
  27. decl {const int keysoct2[]={'z','s','x','d','c','v','g','b','h','n','j','m',',','l','.',';','/',0};} {} 
  28.  
  29. class VirKeys {: {public Fl_Box}
  30. } {
  31.   decl {static const int N_OCT=6;} {}
  32.   decl {static const int SIZE_WHITE=14;} {}
  33.   decl {static const int SIZE_BLACK=8;} {}
  34.   Function {VirKeys(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
  35.     code {master=NULL;} {}
  36.   }
  37.   Function {init(Master *master_)} {} {
  38.     code {master=master_;
  39. for (int i=0;i<N_OCT*12+1;i++) pressed[i]=0;
  40. midich=0;
  41. midivel=100;
  42. midioct=2;
  43.  
  44. keyoct1=3;
  45. keyoct2=2;
  46. rndvelocity=0;} {}
  47.   }
  48.   Function {draw()} {} {
  49.     code {int ox=x(),oy=y(),lx=w(),ly=h()-1,i;
  50.  
  51. if (damage()!=1){
  52.  fl_color(250,240,230);
  53.  fl_rectf(ox,oy,lx,ly);
  54.  
  55.  fl_color(FL_BLACK);
  56.  fl_line(ox,oy,ox+lx,oy);
  57.  fl_line(ox,oy+ly,ox+lx,oy+ly);
  58.  for (i=0;i<N_OCT*7+1;i++){
  59.    fl_line(ox+i*SIZE_WHITE,oy,ox+i*SIZE_WHITE,oy+ly);
  60.    int ik=i%7;
  61.    if ((ik==1)||(ik==2)||(ik==4)||(ik==5)||(ik==6)) 
  62.      fl_rectf(ox+i*SIZE_WHITE-SIZE_BLACK/2,oy,
  63.               SIZE_BLACK+1,ly*3/5);
  64.  };
  65. };
  66.  
  67.  
  68. for (i=0;i<N_OCT*12;i++){
  69.   // if (pressed[i]==0) continue;
  70.  
  71.    int noct=i/12;
  72.    int kv=keyspos[i%12];
  73.  
  74.    if (kv>=0){//white keys
  75.      if (pressed[i]==0) fl_color(250,240,230);
  76.         else fl_color(FL_BLUE);
  77.      fl_rectf(ox+(kv+7*noct)*SIZE_WHITE+3,oy+ly*3/5+2,
  78.        SIZE_WHITE-4,ly*2/5-3);
  79.    } else {//black keys
  80.      kv=keyspos[(i+1)%12];
  81.      if (pressed[i]==0) fl_color(FL_BLACK);
  82.         else fl_color(FL_BLUE);
  83.      fl_rectf(ox+(kv+7*noct)*SIZE_WHITE-SIZE_BLACK/2+2,oy+2,
  84.               SIZE_BLACK-3,ly*3/5-5);
  85.    };
  86. };} {}
  87.   }
  88.   Function {handle(int event)} {return_type int
  89.   } {
  90.     code {int i;
  91. int ly=h();
  92. int x_=Fl::event_x()-x();
  93. int y_=Fl::event_y()-y();
  94. if ( (x_<0)&&(x_>w()) && (y_<0)&&(y_>h())){
  95.   return(0);
  96. };
  97.  
  98.  
  99. if ((event==FL_PUSH)||(event==FL_DRAG)||(event==FL_RELEASE)){
  100.    int kpos=-1;
  101.   
  102.    if (y_>ly*3/5){//white keys
  103.        int pos=x_/SIZE_WHITE;
  104.        if (pos<0) return(1);
  105.        for (i=0;i<12;i++) {
  106.           if (pos%7==keyspos[i]) {
  107.              kpos=pos/7*12+i;
  108.              break;
  109.           };
  110.        };
  111.    } else {//black keys
  112.        int pos=(x_+SIZE_WHITE/2)/SIZE_WHITE;
  113.        if (pos<0) return(1);
  114.        for (i=1;i<12;i++) {
  115.           if (pos%7==-keyspos[i]) {
  116.              kpos=pos/7*12+i;
  117.              break;
  118.           };
  119.        };
  120.    };
  121.  
  122.    if (((event==FL_PUSH)||(event==FL_DRAG))&&
  123.        (Fl::event_shift()==0)) {
  124.         presskey(kpos,1,1);
  125.    };
  126.  
  127.    if ((event==FL_PUSH)&&(Fl::event_shift()!=0)) {
  128.        if (pressed[kpos]==0) presskey(kpos,0,1);
  129.           else relasekey(kpos,1);
  130.    };
  131.    if ((event==FL_RELEASE)&&(Fl::event_shift()==0))
  132.         relaseallkeys(1);
  133.    take_focus();
  134. };
  135.  
  136. if ((event==FL_KEYDOWN)||(event==FL_KEYUP)){
  137.    int key=Fl::event_key();
  138.    int kpos=-1;
  139.    for (i=0;keysoct1[i]!=0;i++) if (key==keysoct1[i]) kpos=i+12*keyoct1;
  140.    for (i=0;keysoct2[i]!=0;i++) if (key==keysoct2[i]) kpos=i+12*keyoct2;
  141.  
  142.    if (kpos==-1) return(0);
  143.    if (event==FL_KEYDOWN) presskey(kpos,0,2);
  144.       else relasekey(kpos,2);
  145. };
  146.  
  147. return(1);} {}
  148.   }
  149.   Function {presskey(int nk,int exclusive,int type)} {} {
  150.     code {if (nk>=N_OCT*12) return;
  151. if ((nk<0)&&(exclusive==0)) {
  152.   relaseallkeys(type);
  153.   return;
  154. };
  155. if (pressed[nk]!=0) return;//the key is already pressed
  156.  
  157. if (exclusive!=0) relaseallkeys(type);
  158. pressed[nk]=type;
  159.  
  160. damage(1);
  161. float vel=midivel;
  162. if (rndvelocity!=0){
  163.   vel=midivel*(127.0-rndvelocity)/127.0+RND*rndvelocity;
  164. };
  165.  
  166. pthread_mutex_lock(&master->mutex);
  167.  master->NoteOn(midich,nk+midioct*12,(int)vel);
  168. pthread_mutex_unlock(&master->mutex);} {}
  169.   }
  170.   Function {relasekey(int nk,int type)} {} {
  171.     code {if ((nk<0)||(nk>=N_OCT*12)) return;
  172. if (pressed[nk]==0) return;//the key is not pressed
  173. if ((type!=0)&&(pressed[nk]!=type)) return;
  174.  
  175. pressed[nk]=0;
  176.  
  177.  
  178. damage(1);
  179.  
  180. pthread_mutex_lock(&master->mutex);
  181.  master->NoteOff(midich,nk+12*midioct);
  182. pthread_mutex_unlock(&master->mutex);} {}
  183.   }
  184.   Function {relaseallkeys(int type)} {} {
  185.     code {for (int i=0;i<N_OCT*12;i++) relasekey(i,type);} {}
  186.   }
  187.   decl {Master *master;} {}
  188.   decl {int pressed[N_OCT*12+1];} {}
  189.   decl {unsigned char midich;} {public
  190.   }
  191.   decl {unsigned char midivel;} {public
  192.   }
  193.   decl {char midioct,keyoct1,keyoct2;} {public
  194.   }
  195.   decl {unsigned char rndvelocity;} {public
  196.   }
  197.  
  198. class VirKeyboard {} {
  199.   Function {make_window()} {} {
  200.     Fl_Window virkeyboardwindow {
  201.       label {Virtual Keyboard - ZynAddSubFX}
  202.       callback {relaseallkeys();
  203. virkeyboardwindow->hide();}
  204.       xywh {118 534 650 130} type Double hide
  205.     } {
  206.       Fl_Box virkeys {
  207.         label Keyboard
  208.         xywh {10 10 590 80} box FLAT_BOX color 17
  209.         code0 {o->init(master);}
  210.         class VirKeys
  211.       }
  212.       Fl_Counter {} {
  213.         label {"qwer.." Oct}
  214.         callback {relaseallkeys();
  215. virkeys->keyoct1=(int) o->value();
  216. virkeys->take_focus();}
  217.         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
  218.         code0 {o->value(virkeys->keyoct1);}
  219.       }
  220.       Fl_Counter {} {
  221.         label {"zxcv.." Oct}
  222.         callback {relaseallkeys();
  223. virkeys->keyoct2=(int) o->value();
  224. virkeys->take_focus();}
  225.         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
  226.         code0 {o->value(virkeys->keyoct2);}
  227.       }
  228.       Fl_Value_Slider {} {
  229.         label Vel
  230.         callback {virkeys->midivel=(int) o->value();
  231. virkeys->take_focus();}
  232.         tooltip Velocity xywh {90 105 105 15} type {Horz Knob} box FLAT_BOX labelsize 10 align 5 minimum 1 maximum 127 step 1
  233.         code0 {o->value(virkeys->midivel);}
  234.       }
  235.       Fl_Counter {} {
  236.         label {Oct.}
  237.         callback {relaseallkeys();
  238. virkeys->midioct=(int) o->value();
  239. virkeys->take_focus();}
  240.         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
  241.         code0 {o->value(virkeys->midioct);}
  242.       }
  243.       Fl_Button {} {
  244.         label Close
  245.         callback {relaseallkeys();
  246. virkeyboardwindow->hide();}
  247.         xywh {545 105 55 20} box THIN_UP_BOX
  248.       }
  249.       Fl_Value_Slider {} {
  250.         label Cval
  251.         callback {int ctl=midictl;
  252.  
  253. pthread_mutex_lock(&master->mutex);
  254.  master->SetController(virkeys->midich,ctl,(int) o->value());
  255. pthread_mutex_unlock(&master->mutex);
  256. virkeys->take_focus();}
  257.         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
  258.       }
  259.       Fl_Choice {} {
  260.         label Controller
  261.         callback {switch((int) o->value()+1){
  262.    case 1: midictl=C_modwheel; break;
  263.    case 2: midictl=C_volume; break;
  264.    case 3: midictl=C_panning; break;
  265.    case 4: midictl=C_expression; break;
  266.    case 5: midictl=C_sustain; break;
  267.    case 6: midictl=C_portamento; break;
  268.    case 7: midictl=C_filterq; break;
  269.    case 8: midictl=C_filtercutoff; break;
  270.    case 9: midictl=C_bandwidth; break;
  271.    case 10: midictl=C_fmamp; break;
  272.    case 11: midictl=C_resonance_center; break;
  273.    case 12: midictl=C_resonance_bandwidth; break;
  274.    default: midictl=C_NULL; break;
  275.  
  276. };
  277.  
  278.  
  279.  
  280. virkeys->take_focus();}
  281.         xywh {435 105 100 15} down_box BORDER_BOX labelsize 10 align 5 when 6 textfont 1 textsize 10
  282.         code0 {midictl=C_bandwidth;o->value(8);}
  283.       } {
  284.         menuitem {} {
  285.           label {01: Mod.Wheel}
  286.           xywh {0 0 100 20} labelfont 1 labelsize 10
  287.         }
  288.         menuitem {} {
  289.           label {07: Volume}
  290.           xywh {10 10 100 20} labelfont 1 labelsize 10
  291.         }
  292.         menuitem {} {
  293.           label {10: Panning}
  294.           xywh {20 20 100 20} labelfont 1 labelsize 10
  295.         }
  296.         menuitem {} {
  297.           label {11: Expression}
  298.           xywh {30 30 100 20} labelfont 1 labelsize 10
  299.         }
  300.         menuitem {} {
  301.           label {64: Sustain}
  302.           xywh {40 40 100 20} labelfont 1 labelsize 10
  303.         }
  304.         menuitem {} {
  305.           label {65: Portamento}
  306.           xywh {50 50 100 20} labelfont 1 labelsize 10
  307.         }
  308.         menuitem {} {
  309.           label {71: Filter Q}
  310.           xywh {60 60 100 20} labelfont 1 labelsize 10
  311.         }
  312.         menuitem {} {
  313.           label {74: Filter Freq.}
  314.           xywh {70 70 100 20} labelfont 1 labelsize 10
  315.         }
  316.         menuitem {} {
  317.           label {75: Bandwidth}
  318.           xywh {80 80 100 20} labelfont 1 labelsize 10
  319.         }
  320.         menuitem {} {
  321.           label {76: FM Gain}
  322.           xywh {90 90 100 20} labelfont 1 labelsize 10
  323.         }
  324.         menuitem {} {
  325.           label {77: Res. c. freq}
  326.           xywh {100 100 100 20} labelfont 1 labelsize 10
  327.         }
  328.         menuitem {} {
  329.           label {78: Res. bw.}
  330.           xywh {110 110 100 20} labelfont 1 labelsize 10
  331.         }
  332.       }
  333.       Fl_Roller pitchwheelroller {
  334.         label Pwh
  335.         callback {pthread_mutex_lock(&master->mutex);
  336.  master->SetController(virkeys->midich,C_pitchwheel,-(int) o->value());
  337. pthread_mutex_unlock(&master->mutex);
  338. virkeys->take_focus();}
  339.         tooltip {Pitch Wheel} xywh {625 10 20 95} box PLASTIC_UP_BOX labelsize 8 align 1 when 3 minimum -8192 maximum 8192 step 64
  340.       }
  341.       Fl_Button {} {
  342.         label R
  343.         callback {pitchwheelroller->value(0);
  344. pitchwheelroller->do_callback();}
  345.         tooltip {Reset Pitch Bend} xywh {625 110 20 15} box THIN_UP_BOX labelfont 1
  346.       }
  347.       Fl_Dial {} {
  348.         label Vrnd
  349.         callback {virkeys->rndvelocity=(int) o->value();}
  350.         tooltip {Velocity Randomness} xywh {205 105 20 20} box ROUND_UP_BOX labelsize 10 align 129 maximum 127 step 1
  351.         code0 {o->value(virkeys->rndvelocity);}
  352.         class WidgetPDial
  353.       }
  354.       Fl_Choice partrcv {
  355.         label {MIDI Ch.}
  356.         callback {relaseallkeys();
  357. virkeys->midich=(int) o->value();
  358. virkeys->take_focus();} open selected
  359.         tooltip {Send to Midi Channel} xywh {15 105 65 20} down_box BORDER_BOX labelsize 10 align 5 textfont 1 textsize 10
  360.         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");};}
  361.         code1 {o->value(virkeys->midich);}
  362.       } {}
  363.     }
  364.   }
  365.   Function {VirKeyboard(Master *master_)} {} {
  366.     code {master=master_;
  367. midictl=75;
  368. make_window();} {}
  369.   }
  370.   Function {show()} {} {
  371.     code {virkeyboardwindow->show();} {}
  372.   }
  373.   Function {relaseallkeys()} {} {
  374.     code {virkeys->relaseallkeys(0);} {}
  375.   }
  376.   decl {Master *master;} {}
  377.   decl {int midictl;} {}
  378.