summaryrefslogtreecommitdiff
path: root/attic/muse_qt4_evolution/synti/zynaddsubfx/UI/ResonanceUI.fl
blob: b9171a496118b8ab6bd482432de82da8b5133402 (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
# 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 <FL/Fl_Box.H>} {public
} 

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

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

decl {\#include <math.h>} {} 

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

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

decl {\#include <string.h>} {} 

decl {\#include "../Synth/Resonance.h"} {public
} 

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

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

class ResonanceGraph {: {public Fl_Box}
} {
  Function {ResonanceGraph(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
    code {respar=NULL;
cbwidget=NULL;
applybutton=NULL;} {}
  }
  Function {init(Resonance *respar_,Fl_Value_Output *khzvalue_,Fl_Value_Output *dbvalue_)} {} {
    code {respar=respar_;
khzvalue=khzvalue_;
dbvalue=dbvalue_;
oldx=-1;
khzval=-1;} {}
  }
  Function {draw_freq_line(REALTYPE freq,int type)} {} {
    code {REALTYPE freqx=respar->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()} {} {
    code {int ox=x(),oy=y(),lx=w(),ly=h(),i,ix,iy,oiy;
REALTYPE 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=respar->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/(REALTYPE)GY*i);
   fl_line(ox+2,oy+tmp,ox+lx-2,oy+tmp);
};



//draw the data
fl_color(FL_RED);
fl_line_style(FL_SOLID);
oiy=(int)(respar->Prespoints[0]/128.0*ly);
for (i=1;i<N_RES_POINTS;i++){
   ix=(int)(i*1.0/N_RES_POINTS*lx);
   iy=(int)(respar->Prespoints[i]/128.0*ly);
   fl_line(ox+ix-1,oy+ly-oiy,ox+ix,oy+ly-iy);
   oiy=iy;
};} {}
  }
  Function {handle(int event)} {return_type int
  } {
    code {int x_=Fl::event_x()-x();
int y_=Fl::event_y()-y();
if ( (x_>=0)&&(x_<w()) && (y_>=0)&&(y_<h())){
   khzvalue->value(respar->getfreqx(x_*1.0/w())/1000.0);
   dbvalue->value((1.0-y_*2.0/h())*respar->PmaxdB);
};

if ((event==FL_PUSH)||(event==FL_DRAG)){
  int leftbutton=1;
  if (Fl::event_button()==FL_RIGHT_MOUSE) leftbutton=0;
  if (x_<0) x_=0;if (y_<0) y_=0;
  if (x_>=w()) x_=w();if (y_>=h()-1) y_=h()-1;

  if ((oldx<0)||(oldx==x_)){
    int sn=(int)(x_*1.0/w()*N_RES_POINTS);
    int sp=127-(int)(y_*1.0/h()*127);
    if (leftbutton!=0) respar->setpoint(sn,sp);
        else respar->setpoint(sn,64);
  } else {
    int x1=oldx;
    int x2=x_;
    int y1=oldy;
    int y2=y_;
    if (oldx>x_){
      x1=x_;y1=y_;
      x2=oldx;y2=oldy;
    };
   for (int i=0;i<x2-x1;i++){
      int sn=(int)((i+x1)*1.0/w()*N_RES_POINTS);
      REALTYPE yy=(y2-y1)*1.0/(x2-x1)*i;
      int sp=127-(int)((y1+yy)/h()*127);
      if (leftbutton!=0) respar->setpoint(sn,sp);
         else respar->setpoint(sn,64);
    };
  };

  oldx=x_;oldy=y_;
  redraw();
};

if (event==FL_RELEASE) {
	oldx=-1;
	if (cbwidget!=NULL) {
		cbwidget->do_callback();
		if (applybutton!=NULL) {
			applybutton->color(FL_RED);
			applybutton->redraw();

		};
	};
};

return(1);} {selected
    }
  }
  Function {setcbwidget(Fl_Widget *cbwidget,Fl_Widget *applybutton)} {} {
    code {this->cbwidget=cbwidget;
this->applybutton=applybutton;} {}
  }
  decl {Fl_Value_Output *khzvalue;} {}
  decl {Fl_Value_Output *dbvalue;} {}
  decl {Resonance *respar;} {}
  decl {int oldx,oldy;} {}
  decl {REALTYPE khzval;} {public
  }
  decl {Fl_Widget *cbwidget,*applybutton;} {}
} 

class ResonanceUI {: PresetsUI_
} {
  Function {make_window()} {} {
    Fl_Window resonancewindow {
      label Resonance
      xywh {45 259 780 305} type Double visible
    } {
      Fl_Value_Output khzvalue {
        label kHz
        xywh {415 264 45 18} align 8 minimum 0.001 maximum 48 step 0.01 textfont 1
        code0 {//this widget must be before the calling widgets}
      }
      Fl_Value_Output dbvalue {
        label dB
        xywh {415 282 45 18} align 8 minimum -150 maximum 150 step 0.1 textfont 1
        code0 {//this widget must be before the calling widgets}
      }
      Fl_Group {} {
        xywh {6 5 768 256} box BORDER_BOX
        code0 {rg=new ResonanceGraph(o->x(),o->y(),o->w(),o->h(),"");}
        code1 {rg->init(respar,khzvalue,dbvalue);}
        code2 {rg->show();}
      } {}
      Fl_Button {} {
        label Close
        callback {resonancewindow->hide();}
        xywh {690 283 84 17} box THIN_UP_BOX
      }
      Fl_Button {} {
        label Zero
        callback {for (int i=0;i<N_RES_POINTS;i++) 
   respar->setpoint(i,64);
resonancewindow->redraw();
redrawPADnoteApply();}
        tooltip {Clear the resonance function} xywh {491 264 66 15} box THIN_UP_BOX labelfont 1
      }
      Fl_Button {} {
        label Smooth
        callback {respar->smooth();
resonancewindow->redraw();
redrawPADnoteApply();}
        tooltip {Smooth the resonance function} xywh {491 282 66 18} box THIN_UP_BOX labelfont 1
      }
      Fl_Check_Button enabled {
        label Enable
        callback {respar->Penabled=(int) o->value();
redrawPADnoteApply();}
        xywh {6 270 78 27} box THIN_UP_BOX down_box DOWN_BOX
        code0 {o->value(respar->Penabled);}
      }
      Fl_Roller maxdb {
        callback {maxdbvo->value(o->value());
respar->PmaxdB=(int) o->value();
redrawPADnoteApply();}
        xywh {90 282 84 15} type Horizontal minimum 1 maximum 90 step 1 value 30
      }
      Fl_Value_Output maxdbvo {
        label {Max.}
        callback {o->value(respar->PmaxdB);}
        tooltip {The Maximum amplitude (dB)} xywh {126 264 24 18} minimum 1 maximum 127 step 1 value 30 textfont 1
        code0 {o->value(respar->PmaxdB);}
      }
      Fl_Box {} {
        label dB
        xywh {150 264 24 18}
      }
      Fl_Value_Output centerfreqvo {
        label {C.f.}
        callback {o->value(respar->getcenterfreq()/1000.0);}
        tooltip {Center Frequency (kHz)} xywh {210 264 33 18} when 3 minimum 1 maximum 10 step 0.01 value 1 textfont 1
        code0 {o->value(respar->getcenterfreq()/1000.0);}
      }
      Fl_Value_Output octavesfreqvo {
        label {Oct.}
        callback {o->value(respar->getoctavesfreq());}
        tooltip {No. of octaves} xywh {210 282 33 18} when 3 minimum 1 maximum 127 step 1 value 30 textfont 1
        code0 {o->value(respar->getoctavesfreq());}
      }
      Fl_Button {} {
        label RND2
        callback {respar->randomize(1);
resonancewindow->redraw();
redrawPADnoteApply();}
        tooltip {Randomize the resonance function} xywh {566 276 42 12} box THIN_UP_BOX labelfont 1 labelsize 10
      }
      Fl_Button {} {
        label RND1
        callback {respar->randomize(0);
resonancewindow->redraw();
redrawPADnoteApply();}
        tooltip {Randomize the resonance function} xywh {566 264 42 12} box THIN_UP_BOX labelfont 1 labelsize 10
      }
      Fl_Button {} {
        label RND3
        callback {respar->randomize(2);
resonancewindow->redraw();
redrawPADnoteApply();}
        tooltip {Randomize the resonance function} xywh {566 288 42 12} box THIN_UP_BOX labelfont 1 labelsize 10
      }
      Fl_Check_Button p1st {
        label {P.1st}
        callback {respar->Pprotectthefundamental=(int) o->value();
redrawPADnoteApply();}
        tooltip {Protect the fundamental frequency (do not damp the first harmonic)} xywh {365 285 45 15} down_box DOWN_BOX labelsize 10
        code0 {o->value(respar->Pprotectthefundamental);}
      }
      Fl_Button {} {
        label InterpP
        callback {int type;
if (Fl::event_button()==FL_LEFT_MOUSE) type=0;
       else type=1;
respar->interpolatepeaks(type);
resonancewindow->redraw();
redrawPADnoteApply();}
        tooltip {Interpolate the peaks} xywh {365 265 46 15} box THIN_UP_BOX labelfont 1 labelsize 10
      }
      Fl_Dial centerfreq {
        label {C.f.}
        callback {respar->Pcenterfreq=(int)o->value();
centerfreqvo->do_callback();
rg->redraw();
redrawPADnoteApply();}
        xywh {245 265 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
        code0 {o->value(respar->Pcenterfreq);}
        class WidgetPDial
      }
      Fl_Dial octavesfreq {
        label {Oct.}
        callback {respar->Poctavesfreq=(int)o->value();
octavesfreqvo->do_callback();
rg->redraw();
redrawPADnoteApply();}
        xywh {280 265 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
        code0 {o->value(respar->Poctavesfreq);}
        class WidgetPDial
      }
      Fl_Button {} {
        label C
        callback {presetsui->copy(respar);}
        xywh {625 275 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7
      }
      Fl_Button {} {
        label P
        callback {presetsui->paste(respar,this);}
        xywh {655 275 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 12 labelcolor 7
      }
      Fl_Button applybutton {
        label Apply
        callback {applybutton->color(FL_GRAY);
applybutton->redraw();
if (cbapplywidget!=NULL) {
	cbapplywidget->do_callback();
	cbapplywidget->color(FL_GRAY);
	cbapplywidget->redraw();
};}
        xywh {690 265 85 15} box THIN_UP_BOX labelfont 1 labelsize 12
      }
    }
  }
  Function {ResonanceUI(Resonance *respar_)} {} {
    code {respar=respar_;
cbwidget=NULL;
cbapplywidget=NULL;
make_window();
applybutton->hide();} {}
  }
  Function {~ResonanceUI()} {} {
    code {resonancewindow->hide();} {}
  }
  Function {redrawPADnoteApply()} {} {
    code {if (cbwidget!=NULL) {
	cbwidget->do_callback();
	applybutton->color(FL_RED);
	applybutton->redraw();
};} {}
  }
  Function {setcbwidget(Fl_Widget *cbwidget,Fl_Widget *cbapplywidget)} {} {
    code {this->cbwidget=cbwidget;
this->cbapplywidget=cbapplywidget;
rg->setcbwidget(cbwidget,applybutton);
applybutton->show();} {}
  }
  Function {refresh()} {} {
    code {redrawPADnoteApply();

enabled->value(respar->Penabled);

maxdb->value(respar->PmaxdB);
maxdbvo->value(respar->PmaxdB);

centerfreqvo->value(respar->getcenterfreq()/1000.0);
octavesfreqvo->value(respar->getoctavesfreq());

centerfreq->value(respar->Pcenterfreq);
octavesfreq->value(respar->Poctavesfreq);

p1st->value(respar->Pprotectthefundamental);

rg->redraw();} {}
  }
  decl {Resonance *respar;} {public
  }
  decl {ResonanceGraph *rg;} {}
  decl {Fl_Widget *cbwidget,*cbapplywidget;} {}
}