# data file for the Fltk User Interface Designer (fluid)
version 1.0110 
header_name {.h} 
code_name {.cc}
decl {//Copyright (c) 2002-2005 Nasca Octavian Paul} {} 

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

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

decl {\#include <cmath>} {} 

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

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

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

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

decl {\#include "../Params/FilterParams.h"} {public
} 

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

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

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

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

decl {\#include "common.H"} {public
} 

class FormantFilterGraph {open : {public Fl_Box}
} {
  Function {FormantFilterGraph(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
    code {pars=NULL;
nvowel=NULL;
nformant=NULL;
graphpoints=NULL;} {}
  }
  Function {init(FilterParams *pars_,int *nvowel_,int *nformant_)} {} {
    code {pars=pars_;
nvowel=nvowel_;
nformant=nformant_;
oldx=-1;
graphpoints=new float [w()];} {}
  }
  Function {draw_freq_line(float freq,int type)} {} {
    code {float freqx=pars->getfreqpos(freq);
switch(type){
  case 0:fl_line_style(FL_SOLID);break;
  case 1:fl_line_style(FL_DOT);break;
  case 2:fl_line_style(FL_DASH);break;
}; 


if ((freqx>0.0)&&(freqx<1.0))
   fl_line(x()+(int) (freqx*w()),y(),
   x()+(int) (freqx*w()),y()+h());} {}
  }
  Function {draw()} {open
  } {
    code {int maxdB=30;
int ox=x(),oy=y(),lx=w(),ly=h(),i,oiy;
float freqx;

fl_color(FL_BLACK);
fl_rectf(ox,oy,lx,ly);


//draw the lines
fl_color(FL_GRAY);

fl_line_style(FL_SOLID);
//fl_line(ox+2,oy+ly/2,ox+lx-2,oy+ly/2);

freqx=pars->getfreqpos(1000.0);
if ((freqx>0.0)&&(freqx<1.0))
   fl_line(ox+(int) (freqx*lx),oy,
    ox+(int) (freqx*lx),oy+ly);

for (i=1;i<10;i++){
   if(i==1){
     draw_freq_line(i*100.0,0);
     draw_freq_line(i*1000.0,0);
   }else 
    if (i==5){
      draw_freq_line(i*100.0,2);
      draw_freq_line(i*1000.0,2);
    }else{
      draw_freq_line(i*100.0,1);
      draw_freq_line(i*1000.0,1);
    };
};

draw_freq_line(10000.0,0);
draw_freq_line(20000.0,1);

fl_line_style(FL_DOT);
int GY=10;if (ly<GY*3) GY=-1;
for (i=1;i<GY;i++){
   int tmp=(int)(ly/(float)GY*i);
   fl_line(ox+2,oy+tmp,ox+lx-2,oy+tmp);
};

fl_color(FL_YELLOW);
fl_font(FL_HELVETICA,10);
if (*nformant<pars->Pnumformants){
   draw_freq_line(pars->getformantfreq(pars->Pvowels[*nvowel].formants[*nformant].freq),2);

//show some information (like current formant frequency,amplitude)
   char tmpstr[20];

   snprintf(tmpstr,20,"%.2f kHz",pars->getformantfreq(pars->Pvowels[*nvowel].formants[*nformant].freq)*0.001);
   fl_draw(tmpstr,ox+1,oy+1,40,12,FL_ALIGN_LEFT,NULL,0);

   snprintf(tmpstr,20,"%d dB",(int)( rap2dB(1e-9 + pars->getformantamp(pars->Pvowels[*nvowel].formants[*nformant].amp)) + pars->getgain() ));
   fl_draw(tmpstr,ox+1,oy+15,40,12,FL_ALIGN_LEFT,NULL,0);

};

//draw the data

fl_color(FL_RED);
fl_line_style(FL_SOLID);

pars->formantfilterH(*nvowel,lx,graphpoints);

fl_line_style( FL_SOLID, 2 );
fl_begin_line();
oiy=(int) ((graphpoints[0]/maxdB+1.0)*ly/2.0);
for (i=1;i<lx;i++){
   double iy= ((graphpoints[i]/maxdB+1.0)*ly/2.0);
   if ((iy>=0)&&(oiy>=0)&&(iy<ly)&&(oiy<lx))
      fl_vertex(ox+i,oy+ly-iy);
   oiy=iy;
};
fl_end_line();
fl_line_style(FL_SOLID,0);} {}
  }
  Function {~FormantFilterGraph()} {} {
    code {delete [] graphpoints;} {}
  }
  decl {FilterParams *pars;} {}
  decl {int oldx,oldy;} {}
  decl {int *nvowel,*nformant;} {}
  decl {float *graphpoints;} {}
} 

class FilterUI {open : {public Fl_Group,PresetsUI_}
} {
  Function {FilterUI(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} {
    code {pars=NULL;
velsnsamp=NULL;
velsns=NULL;
nvowel=0;nformant=0;nseqpos=0;} {}
  }
  Function {~FilterUI()} {} {
    code {filterui->hide();
formantparswindow->hide();
hide();
//delete (filterui);
delete (formantparswindow);} {}
  }
  Function {make_window()} {open
  } {
    Fl_Window filterui {open
      xywh {498 346 275 70} type Double color 50 labelfont 1
      class Fl_Group visible
    } {
      Fl_Group filterparamswindow {
        label {Filter Parameters}
        xywh {0 0 275 75} box UP_FRAME color 183 labeltype ENGRAVED_LABEL labelsize 10 align 17
        code0 {set_module_parameters( o );}
      } {
        Fl_Choice analogfiltertypechoice {
          label FilterType
          callback {pars->Ptype=(int)o->value();
pars->changed=true;}
          tooltip {The Filter type} xywh {10 50 50 15} down_box BORDER_BOX labelsize 10 align 5 textsize 10
          code1 {o->value(pars->Ptype);}
        } {
          MenuItem {} {
            label LPF1
            xywh {40 40 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label HPF1
            xywh {50 50 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label LPF2
            xywh {60 60 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label HPF2
            xywh {70 70 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label BPF2
            xywh {82 82 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label NF2
            xywh {94 94 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label PkF2
            xywh {104 104 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label LSh2
            xywh {114 114 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label HSh2
            xywh {124 124 100 20} labelfont 1 labelsize 10
          }
        }
        Fl_Choice svfiltertypechoice {
          label FilterType
          callback {pars->Ptype=(int)o->value();
pars->changed=true;}
          tooltip {The Filter type} xywh {10 50 50 15} down_box BORDER_BOX labelsize 10 align 5 textsize 10
          code1 {o->value(pars->Ptype);}
        } {
          MenuItem {} {
            label 1LPF
            xywh {134 134 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label 1HPF
            xywh {144 144 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label 1BPF
            xywh {154 154 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label 1NF
            xywh {164 164 100 20} labelfont 1 labelsize 10
          }
        }
        Fl_Choice filtertype {
          label Category
          callback {switchcategory((int)o->value());
pars->changed=true;}
          tooltip {The Category of the Filter (Analog/Formantic/etc.)} xywh {10 20 60 15} down_box BORDER_BOX labelsize 10 align 5 textsize 10
          code0 {o->value(pars->Pcategory);}
        } {
          MenuItem {} {
            label Analog
            xywh {50 50 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label Formant
            xywh {60 60 100 20} labelfont 1 labelsize 10
          }
          MenuItem {} {
            label StVarF
            xywh {70 70 100 20} labelfont 1 labelsize 10
          }
        }
        Fl_Dial cfreqdial {
          label {C.Freq}
          callback {pars->Pfreq=(int)o->value();}
          tooltip {Center Frequency of the Filter or the base position in the vowel's sequence} xywh {75 25 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(pars->Pfreq);}
          class WidgetPDial
        }
        Fl_Dial qdial {
          label Q
          callback {pars->Pq=(int)o->value();
formantfiltergraph->redraw();}
          tooltip {Filter resonance or bandwidth} xywh {110 25 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(pars->Pq);}
          class WidgetPDial
        }
        Fl_Dial freqtrdial {
          label {freq.tr.}
          callback {pars->Pfreqtrack=(int) o->value();}
          tooltip {Filter frequency tracking (left is negative, middle is 0, and right is positive)} xywh {215 25 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(pars->Pfreqtrack);}
          class WidgetPDial
        }
        Fl_Dial vsnsadial {
          label {V.SnsA.}
          callback {if (velsnsamp!=NULL) *velsnsamp=(int)o->value();}
          tooltip {Velocity sensing amount of the Filter} xywh {145 25 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          class WidgetPDial
        }
        Fl_Dial vsnsdial {
          label {V.Sns.}
          callback {if (velsns!=NULL) *velsns=(int)o->value();}
          tooltip {Velocity Sensing Function of the Filter} xywh {180 25 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          class WidgetPDial
        }
        Fl_Dial gaindial {
          label gain
          callback {pars->Pgain=(int)o->value();
formantfiltergraph->redraw();
pars->changed=true;}
          tooltip {Filter output gain/damp} xywh {250 35 20 20} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(pars->Pgain);}
          class WidgetPDial
        }
        Fl_Choice stcounter {
          label St
          callback {pars->Pstages=(int)o->value();
formantfiltergraph->redraw();
pars->changed=true;} open
          tooltip {Filter stages (in order to increase dB/oct. value and the order of the filter)} xywh {235 5 35 15} down_box BORDER_BOX labelsize 10 textfont 1 textsize 10
          code1 {for (int i=0;i<MAX_FILTER_STAGES;i++) {char tmp[10];snprintf(tmp,10,"%dx",i+1);o->add(tmp);};}
          code2 {o->value(pars->Pstages);}
        } {}
      }
      Fl_Button editbutton {
        label Edit
        callback {formantparswindow->show();}
        xywh {15 40 50 25} labelfont 1 labelsize 11
      }
      Fl_Button {} {
        label C
        callback {presetsui->copyArray(pars);}
        xywh {186 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 55
      }
      Fl_Button {} {
        label P
        callback {presetsui->pasteArray(pars,this);}
        xywh {203 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 55
      }
    }
  }
  Function {make_formant_window()} {open
  } {
    Fl_Window formantparswindow {
      label {Formant Filter Parameters} selected
      xywh {518 473 700 205} type Double visible
    } {
      Fl_Group {} {
        xywh {485 47 105 113} box THIN_UP_BOX
      } {
        Fl_Counter {} {
          label {Formant }
          callback {nformant=(int) o->value();
update_formant_window();
formantfiltergraph->redraw();}
          xywh {545 80 40 15} type Simple labelfont 1 labelsize 10 align 4 minimum 0 maximum 127 step 1 textsize 10
          code0 {o->bounds(0,FF_MAX_FORMANTS-1);}
          code1 {o->value(nformant);}
        }
        Fl_Counter {} {
          label {Vowel no.}
          callback {nvowel=(int) o->value();
update_formant_window();
formantfiltergraph->redraw();}
          xywh {545 55 40 20} type Simple labelfont 1 labelsize 10 align 4 minimum 0 maximum 127 step 1 textfont 1 textsize 11
          code0 {o->bounds(0,FF_MAX_VOWELS-1);}
          code1 {o->value(nvowel);}
        }
        Fl_Group formantparsgroup {
          xywh {490 105 95 50} box ENGRAVED_FRAME
        } {
          Fl_Dial formant_freq_dial {
            label freq
            callback {pars->Pvowels[nvowel].formants[nformant].freq=(int) o->value();
formantfiltergraph->redraw();
pars->changed=true;}
            tooltip {Formant frequency} xywh {495 115 25 25} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
            class WidgetPDial
          }
          Fl_Dial formant_q_dial {
            label Q
            callback {pars->Pvowels[nvowel].formants[nformant].q=(int) o->value();
formantfiltergraph->redraw();
pars->changed=true;}
            tooltip {Formant's Q} xywh {525 115 24 25} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
            class WidgetPDial
          }
          Fl_Dial formant_amp_dial {
            label amp
            callback {pars->Pvowels[nvowel].formants[nformant].amp=(int) o->value();
formantfiltergraph->redraw();
pars->changed=true;}
            tooltip {Formant amplitude} xywh {555 115 24 25} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
            class WidgetPDial
          }
        }
      }
      Fl_Group {} {
        xywh {590 47 100 113} box THIN_UP_BOX
      } {
        Fl_Counter {} {
          label {Seq.Size}
          callback {pars->Psequencesize=(int) o->value();
update_formant_window();
pars->changed=true;}
          xywh {595 62 55 20} type Simple labelfont 1 labelsize 10 align 5 minimum 0 maximum 127 step 1 textfont 1 textsize 11
          code0 {o->bounds(1,FF_MAX_SEQUENCE-1);}
          code1 {o->value(pars->Psequencesize);}
        }
        Fl_Counter {} {
          label {S.Pos.}
          callback {nseqpos=(int) o->value();
update_formant_window();
pars->changed=true;}
          tooltip {Current position from the sequence} xywh {595 97 40 15} type Simple labelfont 1 labelsize 10 align 9 minimum 0 maximum 127 step 1 textsize 10
          code0 {o->bounds(0,FF_MAX_SEQUENCE-2);}
          code1 {o->value(nseqpos);}
        }
        Fl_Counter vowel_counter {
          label Vowel
          callback {pars->Psequence[nseqpos].nvowel=(int) o->value();
pars->changed=true;}
          xywh {640 97 40 15} type Simple labelsize 10 align 1 minimum 0 maximum 127 step 1 textsize 10
          code0 {o->bounds(0,FF_MAX_VOWELS-1);}
        }
        Fl_Check_Button {} {
          label {Neg.Input}
          callback {pars->Psequencereversed=(int) o->value();
pars->changed=true;}
          tooltip {Negate the input from LFO/envelopes/etc.} xywh {625 132 60 20} down_box DOWN_BOX labelsize 10
          code0 {o->value(pars->Psequencereversed);}
        }
        Fl_Dial strchdial {
          label Strch
          callback {pars->Psequencestretch=(int) o->value();
pars->changed=true;}
          tooltip {Sequence Stretch} xywh {595 130 25 25} box ROUND_UP_BOX labelsize 10 align 1 maximum 127 step 1
          code0 {o->value(pars->Psequencestretch);}
          class WidgetPDial
        }
      }
      Fl_Counter {} {
        label {Num.Formants}
        callback {pars->Pnumformants=(int) o->value();
update_formant_window();
pars->changed=true;
formantfiltergraph->redraw();}
        xywh {485 15 65 20} type Simple labelfont 1 labelsize 10 align 5 minimum 0 maximum 127 step 1
        code0 {o->bounds(1,FF_MAX_FORMANTS);}
        code1 {o->value(pars->Pnumformants);}
      }
      Fl_Dial frsldial {
        label {Fr.Sl.}
        callback {pars->Pformantslowness=(int) o->value();
pars->changed=true;}
        tooltip {Formant's Slowness (Morphing)} xywh {565 15 25 25} box ROUND_UP_BOX labelfont 1 labelsize 10 align 1 maximum 127 step 1
        code0 {o->value(pars->Pformantslowness);}
        class WidgetPDial
      }
      Fl_Value_Output centerfreqvo {
        label {C.f.}
        callback {o->value(pars->getcenterfreq()/1000.0);}
        tooltip {Center Frequency (kHz)} xywh {515 164 33 18} when 3 minimum 1 maximum 10 step 0.01 value 1 textfont 1
        code0 {o->value(pars->getcenterfreq()/1000.0);}
      }
      Fl_Value_Output octavesfreqvo {
        label {Oct.}
        callback {o->value(pars->getoctavesfreq());}
        tooltip {No. of octaves} xywh {515 182 33 18} when 3 minimum 1 maximum 127 step 1 value 5 textfont 1
        code0 {o->value(pars->getoctavesfreq());}
      }
      Fl_Slider cfknob {
        callback {pars->Pcenterfreq=(int)o->value();
centerfreqvo->do_callback();
formantfiltergraph->redraw();
pars->changed=true;}
        xywh {551 167 84 15} type {Horz Knob} box FLAT_BOX maximum 127
        code0 {o->value(pars->Pcenterfreq);}
      }
      Fl_Slider octknob {
        callback {pars->Poctavesfreq=(int)o->value();
octavesfreqvo->do_callback();
formantfiltergraph->redraw();}
        xywh {551 185 84 15} type {Horz Knob} box FLAT_BOX maximum 127
        code0 {o->value(pars->Poctavesfreq);}
      }
      Fl_Box formantfiltergraph {
        xywh {5 5 475 195} box BORDER_BOX
        code0 {o->init(pars,&nvowel,&nformant);}
        class FormantFilterGraph
      }
      Fl_Dial wvknob {
        label {Vw.Cl.}
        callback {pars->Pvowelclearness=(int) o->value();
pars->changed=true;}
        tooltip {Vowel "clearness" (how the mixed vowels are avoided)} xywh {600 15 25 25} box ROUND_UP_BOX labelfont 1 labelsize 10 align 1 maximum 127 step 1
        code0 {o->value(pars->Pvowelclearness);}
        class WidgetPDial
      }
      Fl_Button {} {
        label Close
        callback {formantparswindow->hide();}
        xywh {645 180 50 25} box THIN_UP_BOX
      }
      Fl_Button {} {
        label C
        callback {presetsui->copy(pars,nvowel);}
        xywh {635 25 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55
      }
      Fl_Button {} {
        label P
        callback {presetsui->paste(pars,this,nvowel);}
        xywh {665 25 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 55
      }
      Fl_Box {} {
        label Vowel
        xywh {635 10 55 15}
      }
    }
  }
  Function {update_formant_window()} {open
  } {
    code {formant_freq_dial->value(pars->Pvowels[nvowel].formants[nformant].freq);
formant_q_dial->value(pars->Pvowels[nvowel].formants[nformant].q);
formant_amp_dial->value(pars->Pvowels[nvowel].formants[nformant].amp);
if (nformant<pars->Pnumformants) formantparsgroup->activate();
	else formantparsgroup->deactivate();

if (nseqpos<pars->Psequencesize) vowel_counter->activate();
	else vowel_counter->deactivate();


vowel_counter->value(pars->Psequence[nseqpos].nvowel);} {}
  }
  Function {refresh()} {} {
    code {update_formant_window();
formantfiltergraph->redraw();

if (pars->Pcategory==2) svfiltertypechoice->value(pars->Ptype);
if (pars->Pcategory==0) analogfiltertypechoice->value(pars->Ptype);

filtertype->value(pars->Pcategory);

cfreqdial->value(pars->Pfreq);
qdial->value(pars->Pq);

freqtrdial->value(pars->Pfreqtrack);
gaindial->value(pars->Pgain);

stcounter->value(pars->Pstages);

int categ=pars->Pcategory;
if ((categ==0)||(categ==2)) {
	if (categ==0) {
           analogfiltertypechoice->show();
           svfiltertypechoice->hide();
        } else {
           svfiltertypechoice->show();
           analogfiltertypechoice->hide();
        };
	editbutton->hide();
        formantparswindow->hide();
        cfreqdial->label("C.freq");
} else {
	analogfiltertypechoice->hide();
	svfiltertypechoice->hide();
	editbutton->show();
        cfreqdial->label("BS.pos");
};

filterparamswindow->redraw();} {}
  }
  Function {init(FilterParams *filterpars_,unsigned char *velsnsamp_,unsigned char *velsns_)} {} {
    code {pars=filterpars_;
velsnsamp=velsnsamp_;
velsns=velsns_;

make_window();
end();
make_formant_window();


filterui->resize(this->x(),this->y(),this->w(),this->h());


if (velsnsamp==NULL){
	vsnsadial->deactivate();
	vsnsadial->value(127);
   } else vsnsadial->value(*velsnsamp);

if (velsns==NULL){
	vsnsdial->deactivate();
	vsnsdial->value(127);
   } else vsnsdial->value(*velsns);

switchcategory(pars->Pcategory);


formantparswindow->label(this->label());

update_formant_window();} {}
  }
  Function {switchcategory(int newcat)} {open
  } {
    code {if (pars->Pcategory!=newcat){
    pars->Pgain=64;
    gaindial->value(64);
    analogfiltertypechoice->value(0);
    analogfiltertypechoice->do_callback();
    svfiltertypechoice->value(0);
    svfiltertypechoice->do_callback();
};
pars->Pcategory=newcat;

refresh();} {}
  }
  Function {use_for_dynamic_filter()} {open
  } {
    code {freqtrdial->deactivate();
gaindial->when(0);

cfknob->when(FL_WHEN_RELEASE);
octknob->when(FL_WHEN_RELEASE);

frsldial->when(0);
wvknob->when(0);
formant_freq_dial->when(0);
formant_q_dial->when(0);
formant_amp_dial->when(0);
strchdial->when(0);} {}
  }
  decl {FilterParams *pars;} {}
  decl {unsigned char *velsnsamp,*velsns;} {}
  decl {int nvowel,nformant,nseqpos;} {}
} 
