home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / ZynAddFX / Setup_ZynAddSubFX-2.1.1.exe / ResonanceUI.fl < prev    next >
Encoding:
FLTK User Interface Designer  |  2004-08-15  |  10.0 KB  |  365 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 <FL/Fl_Box.H>} {public
  10.  
  11. decl {\#include <FL/fl_draw.H>} {public
  12.  
  13. decl {\#include <FL/Fl_Value_Output.H>} {public
  14.  
  15. decl {\#include <math.h>} {} 
  16.  
  17. decl {\#include <stdio.h>} {} 
  18.  
  19. decl {\#include <stdlib.h>} {} 
  20.  
  21. decl {\#include <string.h>} {} 
  22.  
  23. decl {\#include "../Synth/Resonance.h"} {public
  24.  
  25. decl {\#include "WidgetPDial.h"} {public
  26.  
  27. decl {\#include "PresetsUI.h"} {public
  28.  
  29. class ResonanceGraph {: {public Fl_Box}
  30. } {
  31.   Function {ResonanceGraph(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
  32.     code {respar=NULL;
  33. cbwidget=NULL;} {}
  34.   }
  35.   Function {init(Resonance *respar_,Fl_Value_Output *khzvalue_,Fl_Value_Output *dbvalue_)} {} {
  36.     code {respar=respar_;
  37. khzvalue=khzvalue_;
  38. dbvalue=dbvalue_;
  39. oldx=-1;
  40. khzval=-1;} {}
  41.   }
  42.   Function {draw_freq_line(REALTYPE freq,int type)} {} {
  43.     code {REALTYPE freqx=respar->getfreqpos(freq);
  44. switch(type){
  45.   case 0:fl_line_style(FL_SOLID);break;
  46.   case 1:fl_line_style(FL_DOT);break;
  47.   case 2:fl_line_style(FL_DASH);break;
  48. }; 
  49.  
  50.  
  51. if ((freqx>0.0)&&(freqx<1.0))
  52.    fl_line(x()+(int) (freqx*w()),y(),
  53.    x()+(int) (freqx*w()),y()+h());} {}
  54.   }
  55.   Function {draw()} {} {
  56.     code {int ox=x(),oy=y(),lx=w(),ly=h(),i,ix,iy,oiy;
  57. REALTYPE freqx;
  58.  
  59. fl_color(FL_BLACK);
  60. fl_rectf(ox,oy,lx,ly);
  61.  
  62.  
  63. //draw the lines
  64. fl_color(FL_GRAY);
  65.  
  66. fl_line_style(FL_SOLID);
  67. fl_line(ox+2,oy+ly/2,ox+lx-2,oy+ly/2);
  68.  
  69. freqx=respar->getfreqpos(1000.0);
  70. if ((freqx>0.0)&&(freqx<1.0))
  71.    fl_line(ox+(int) (freqx*lx),oy,
  72.     ox+(int) (freqx*lx),oy+ly);
  73.  
  74. for (i=1;i<10;i++){
  75.    if(i==1){
  76.      draw_freq_line(i*100.0,0);
  77.      draw_freq_line(i*1000.0,0);
  78.    }else 
  79.     if (i==5){
  80.       draw_freq_line(i*100.0,2);
  81.       draw_freq_line(i*1000.0,2);
  82.     }else{
  83.       draw_freq_line(i*100.0,1);
  84.       draw_freq_line(i*1000.0,1);
  85.     };
  86. };
  87.  
  88. draw_freq_line(10000.0,0);
  89. draw_freq_line(20000.0,1);
  90.  
  91. fl_line_style(FL_DOT);
  92. int GY=10;if (ly<GY*3) GY=-1;
  93. for (i=1;i<GY;i++){
  94.    int tmp=(int)(ly/(REALTYPE)GY*i);
  95.    fl_line(ox+2,oy+tmp,ox+lx-2,oy+tmp);
  96. };
  97.  
  98.  
  99.  
  100. //draw the data
  101. fl_color(FL_RED);
  102. fl_line_style(FL_SOLID);
  103. oiy=(int)(respar->Prespoints[0]/128.0*ly);
  104. for (i=1;i<N_RES_POINTS;i++){
  105.    ix=(int)(i*1.0/N_RES_POINTS*lx);
  106.    iy=(int)(respar->Prespoints[i]/128.0*ly);
  107.    fl_line(ox+ix-1,oy+ly-oiy,ox+ix,oy+ly-iy);
  108.    oiy=iy;
  109. };} {}
  110.   }
  111.   Function {handle(int event)} {return_type int
  112.   } {
  113.     code {int x_=Fl::event_x()-x();
  114. int y_=Fl::event_y()-y();
  115. if ( (x_>=0)&&(x_<w()) && (y_>=0)&&(y_<h())){
  116.    khzvalue->value(respar->getfreqx(x_*1.0/w())/1000.0);
  117.    dbvalue->value((1.0-y_*2.0/h())*respar->PmaxdB);
  118. };
  119.  
  120. if ((event==FL_PUSH)||(event==FL_DRAG)){
  121.   int leftbutton=1;
  122.   if (Fl::event_button()==FL_RIGHT_MOUSE) leftbutton=0;
  123.   if (x_<0) x_=0;if (y_<0) y_=0;
  124.   if (x_>=w()) x_=w();if (y_>=h()-1) y_=h()-1;
  125.  
  126.   if ((oldx<0)||(oldx==x_)){
  127.     int sn=(int)(x_*1.0/w()*N_RES_POINTS);
  128.     int sp=127-(int)(y_*1.0/h()*127);
  129.     if (leftbutton!=0) respar->setpoint(sn,sp);
  130.         else respar->setpoint(sn,64);
  131.   } else {
  132.     int x1=oldx;
  133.     int x2=x_;
  134.     int y1=oldy;
  135.     int y2=y_;
  136.     if (oldx>x_){
  137.       x1=x_;y1=y_;
  138.       x2=oldx;y2=oldy;
  139.     };
  140.    for (int i=0;i<x2-x1;i++){
  141.       int sn=(int)((i+x1)*1.0/w()*N_RES_POINTS);
  142.       REALTYPE yy=(y2-y1)*1.0/(x2-x1)*i;
  143.       int sp=127-(int)((y1+yy)/h()*127);
  144.       if (leftbutton!=0) respar->setpoint(sn,sp);
  145.          else respar->setpoint(sn,64);
  146.     };
  147.   };
  148.  
  149.   oldx=x_;oldy=y_;
  150.   redraw();
  151. };
  152.  
  153. if (event==FL_RELEASE) {
  154.     oldx=-1;
  155.     if (cbwidget!=NULL) cbwidget->do_callback();
  156. };
  157.  
  158. return(1);} {}
  159.   }
  160.   Function {setcbwidget(Fl_Widget *cbwidget)} {} {
  161.     code {this->cbwidget=cbwidget;} {}
  162.   }
  163.   decl {Fl_Value_Output *khzvalue;} {}
  164.   decl {Fl_Value_Output *dbvalue;} {}
  165.   decl {Resonance *respar;} {}
  166.   decl {int oldx,oldy;} {}
  167.   decl {REALTYPE khzval;} {public
  168.   }
  169.   decl {Fl_Widget *cbwidget;} {}
  170.  
  171. class ResonanceUI {: PresetsUI_
  172. } {
  173.   Function {make_window()} {} {
  174.     Fl_Window resonancewindow {
  175.       label Resonance
  176.       xywh {45 259 780 305} type Double hide
  177.     } {
  178.       Fl_Value_Output khzvalue {
  179.         label kHz
  180.         xywh {415 264 45 18} align 8 minimum 0.001 maximum 48 step 0.01 textfont 1
  181.         code0 {//this widget must be before the calling widgets}
  182.       }
  183.       Fl_Value_Output dbvalue {
  184.         label dB
  185.         xywh {415 282 45 18} align 8 minimum -150 maximum 150 step 0.1 textfont 1
  186.         code0 {//this widget must be before the calling widgets}
  187.       }
  188.       Fl_Group {} {
  189.         xywh {6 5 768 256} box BORDER_BOX
  190.         code0 {rg=new ResonanceGraph(o->x(),o->y(),o->w(),o->h(),"");}
  191.         code1 {rg->init(respar,khzvalue,dbvalue);}
  192.         code2 {rg->show();}
  193.       } {}
  194.       Fl_Button {} {
  195.         label Close
  196.         callback {resonancewindow->hide();}
  197.         xywh {690 270 84 27} box THIN_UP_BOX
  198.       }
  199.       Fl_Button {} {
  200.         label Zero
  201.         callback {for (int i=0;i<N_RES_POINTS;i++) 
  202.    respar->setpoint(i,64);
  203. resonancewindow->redraw();
  204. redrawPADnoteApply();}
  205.         tooltip {Clear the resonance function} xywh {491 264 66 15} box THIN_UP_BOX labelfont 1
  206.       }
  207.       Fl_Button {} {
  208.         label Smooth
  209.         callback {respar->smooth();
  210. resonancewindow->redraw();
  211. redrawPADnoteApply();}
  212.         tooltip {Smooth the resonance function} xywh {491 282 66 18} box THIN_UP_BOX labelfont 1
  213.       }
  214.       Fl_Check_Button enabled {
  215.         label Enable
  216.         callback {respar->Penabled=(int) o->value();
  217. redrawPADnoteApply();}
  218.         xywh {6 270 78 27} box THIN_UP_BOX down_box DOWN_BOX
  219.         code0 {o->value(respar->Penabled);}
  220.       }
  221.       Fl_Roller maxdb {
  222.         callback {maxdbvo->value(o->value());
  223. respar->PmaxdB=(int) o->value();
  224. redrawPADnoteApply();}
  225.         xywh {90 282 84 15} type Horizontal minimum 1 maximum 90 step 1 value 30
  226.       }
  227.       Fl_Value_Output maxdbvo {
  228.         label {Max.}
  229.         callback {o->value(respar->PmaxdB);}
  230.         tooltip {The Maximum amplitude (dB)} xywh {126 264 24 18} minimum 1 maximum 127 step 1 value 30 textfont 1
  231.         code0 {o->value(respar->PmaxdB);}
  232.       }
  233.       Fl_Box {} {
  234.         label dB
  235.         xywh {150 264 24 18}
  236.       }
  237.       Fl_Value_Output centerfreqvo {
  238.         label {C.f.}
  239.         callback {o->value(respar->getcenterfreq()/1000.0);}
  240.         tooltip {Center Frequency (kHz)} xywh {210 264 33 18} when 3 minimum 1 maximum 10 step 0.01 value 1 textfont 1
  241.         code0 {o->value(respar->getcenterfreq()/1000.0);}
  242.       }
  243.       Fl_Value_Output octavesfreqvo {
  244.         label {Oct.}
  245.         callback {o->value(respar->getoctavesfreq());}
  246.         tooltip {No. of octaves} xywh {210 282 33 18} when 3 minimum 1 maximum 127 step 1 value 30 textfont 1
  247.         code0 {o->value(respar->getoctavesfreq());}
  248.       }
  249.       Fl_Button {} {
  250.         label RND2
  251.         callback {respar->randomize(1);
  252. resonancewindow->redraw();
  253. redrawPADnoteApply();}
  254.         tooltip {Randomize the resonance function} xywh {566 276 42 12} box THIN_UP_BOX labelfont 1 labelsize 10
  255.       }
  256.       Fl_Button {} {
  257.         label RND1
  258.         callback {respar->randomize(0);
  259. resonancewindow->redraw();
  260. redrawPADnoteApply();}
  261.         tooltip {Randomize the resonance function} xywh {566 264 42 12} box THIN_UP_BOX labelfont 1 labelsize 10
  262.       }
  263.       Fl_Button {} {
  264.         label RND3
  265.         callback {respar->randomize(2);
  266. resonancewindow->redraw();
  267. redrawPADnoteApply();}
  268.         tooltip {Randomize the resonance function} xywh {566 288 42 12} box THIN_UP_BOX labelfont 1 labelsize 10
  269.       }
  270.       Fl_Check_Button p1st {
  271.         label {P.1st}
  272.         callback {respar->Pprotectthefundamental=(int) o->value();
  273. redrawPADnoteApply();}
  274.         tooltip {Protect the fundamental frequency (do not damp the first harmonic)} xywh {365 285 45 15} down_box DOWN_BOX labelsize 10
  275.         code0 {o->value(respar->Pprotectthefundamental);}
  276.       }
  277.       Fl_Button {} {
  278.         label InterpP
  279.         callback {int type;
  280. if (Fl::event_button()==FL_LEFT_MOUSE) type=0;
  281.        else type=1;
  282. respar->interpolatepeaks(type);
  283. resonancewindow->redraw();
  284. redrawPADnoteApply();}
  285.         tooltip {Interpolate the peaks} xywh {365 265 46 15} box THIN_UP_BOX labelfont 1 labelsize 10
  286.       }
  287.       Fl_Dial centerfreq {
  288.         label {C.f.}
  289.         callback {respar->Pcenterfreq=(int)o->value();
  290. centerfreqvo->do_callback();
  291. rg->redraw();
  292. redrawPADnoteApply();}
  293.         xywh {245 265 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
  294.         code0 {o->value(respar->Pcenterfreq);}
  295.         class WidgetPDial
  296.       }
  297.       Fl_Dial octavesfreq {
  298.         label {Oct.}
  299.         callback {respar->Poctavesfreq=(int)o->value();
  300. octavesfreqvo->do_callback();
  301. rg->redraw();
  302. redrawPADnoteApply();}
  303.         xywh {280 265 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
  304.         code0 {o->value(respar->Poctavesfreq);}
  305.         class WidgetPDial
  306.       }
  307.       Fl_Button {} {
  308.         label C
  309.         callback {presetsui->copy(respar);}
  310.         xywh {625 275 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7
  311.       }
  312.       Fl_Button {} {
  313.         label P
  314.         callback {presetsui->paste(respar,this);}
  315.         xywh {655 275 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7
  316.       }
  317.     }
  318.   }
  319.   Function {ResonanceUI(Resonance *respar_)} {} {
  320.     code {respar=respar_;
  321. cbwidget=NULL;
  322. make_window();} {}
  323.   }
  324.   Function {~ResonanceUI()} {} {
  325.     code {resonancewindow->hide();} {}
  326.   }
  327.   Function {redrawPADnoteApply()} {} {
  328.     code {if (cbwidget!=NULL) cbwidget->do_callback();} {}
  329.   }
  330.   Function {setcbwidget(Fl_Widget *cbwidget)} {} {
  331.     code {this->cbwidget=cbwidget;
  332. rg->setcbwidget(cbwidget);} {}
  333.   }
  334.   Function {refresh()} {} {
  335.     code {redrawPADnoteApply();
  336.  
  337. enabled->value(respar->Penabled);
  338.  
  339. maxdb->value(respar->PmaxdB);
  340. maxdbvo->value(respar->PmaxdB);
  341.  
  342. centerfreqvo->value(respar->getcenterfreq()/1000.0);
  343. octavesfreqvo->value(respar->getoctavesfreq());
  344.  
  345. centerfreq->value(respar->Pcenterfreq);
  346. octavesfreq->value(respar->Poctavesfreq);
  347.  
  348. p1st->value(respar->Pprotectthefundamental);
  349.  
  350. rg->redraw();} {selected
  351.     }
  352.   }
  353.   decl {Resonance *respar;} {public
  354.   }
  355.   decl {ResonanceGraph *rg;} {}
  356.   decl {Fl_Widget *cbwidget;} {}
  357.