summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/synti/zynaddsubfx/UI/EnvelopeUI.fl
blob: 090a77fc7ea28d5d628e33a7ac7b1d06a21e3aab (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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
# 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 "WidgetPDial.h"} {public
} 

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

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

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

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

decl {\#include "../Params/EnvelopeParams.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
} 

class EnvelopeFreeEdit {: {public Fl_Box}
} {
  Function {EnvelopeFreeEdit(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
    code {env=NULL;
pair=NULL;} {}
  }
  Function {init(EnvelopeParams *env_)} {} {
    code {env=env_;
oldx=-1;
currentpoint=-1;
cpx=0;
lastpoint=-1;} {}
  }
  Function {setpair(Fl_Box *pair_)} {} {
    code {pair=pair_;} {}
  }
  Function {getpointx(int n)} {return_type int
  } {
    code {int lx=w()-10;
int npoints=env->Penvpoints;

float  sum=0;
for (int i=1;i<npoints;i++) sum+=env->getdt(i)+1;

float sumbefore=0;//the sum of all points before the computed point
for (int i=1;i<=n;i++) sumbefore+=env->getdt(i)+1;

return((int) (sumbefore/(REALTYPE) sum*lx));} {}
  }
  Function {getpointy(int n)} {return_type int
  } {
    code {int ly=h()-10;

return((int) ((1.0-env->Penvval[n]/127.0)*ly));} {}
  }
  Function {getnearest(int x,int y)} {return_type int
  } {
    code {x-=5;y-=5;

int nearestpoint=0;
int nearestval=1000000;//a big value
for (int i=0;i<env->Penvpoints;i++){
   int distance=abs(x-getpointx(i))+abs(y-getpointy(i));
   if (distance<nearestval) {
     nearestpoint=i;
     nearestval=distance;  
   };
};
return(nearestpoint);} {}
  }
  Function {draw()} {private
  } {
    code {int ox=x(),oy=y(),lx=w(),ly=h();
if (env->Pfreemode==0) env->converttofree();
int npoints=env->Penvpoints;

if (active_r()) fl_color(FL_BLACK);
    else fl_color(90,90,90);
if (!active_r()) currentpoint=-1;

fl_rectf(ox,oy,lx,ly);

ox+=5;oy+=5;lx-=10;ly-=10;

//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);

//draws the evelope points and lines
Fl_Color alb=FL_WHITE;
if (!active_r()) alb=fl_rgb_color(180,180,180);
fl_color(alb);
int oldxx=0,xx=0,oldyy=0,yy=getpointy(0);
fl_rectf(ox-3,oy+yy-3,6,6);
for (int i=1;i<npoints;i++){
    oldxx=xx;oldyy=yy;
    xx=getpointx(i);yy=getpointy(i);
    if (i==currentpoint) fl_color(FL_RED);
        else fl_color(alb);
    fl_line(ox+oldxx,oy+oldyy,ox+xx,oy+yy);
    fl_rectf(ox+xx-3,oy+yy-3,6,6);
};

//draw the last moved point point (if exists)
if (lastpoint>=0){
    fl_color(FL_CYAN);
    fl_rectf(ox+getpointx(lastpoint)-5,oy+getpointy(lastpoint)-5,10,10);
};

//draw the sustain position
if (env->Penvsustain>0){
    fl_color(FL_YELLOW);
    xx=getpointx(env->Penvsustain);
    fl_line(ox+xx,oy+0,ox+xx,oy+ly);
};

//Show the envelope duration and the current line duration
fl_font(FL_HELVETICA|FL_BOLD,10);
float time=0.0;
if (currentpoint<=0){
   fl_color(alb);
   for (int i=1;i<npoints;i++) time+=env->getdt(i);
} else {
   fl_color(255,0,0);
   time=env->getdt(currentpoint);
};
char tmpstr[20];
if (time<1000.0) snprintf((char *)&tmpstr,20,"%.1fms",time);
     else snprintf((char *)&tmpstr,20,"%.2fs",time/1000.0);
fl_draw(tmpstr,ox+lx-20,oy+ly-10,20,10,FL_ALIGN_RIGHT,NULL,0);} {}
  }
  Function {handle(int event)} {return_type int
  } {
    code {int x_=Fl::event_x()-x();
int y_=Fl::event_y()-y();

if (event==FL_PUSH) {
  currentpoint=getnearest(x_,y_);
  cpx=x_;
  cpdt=env->Penvdt[currentpoint];
  lastpoint=currentpoint;
  redraw();
  if (pair!=NULL) pair->redraw();
};

if (event==FL_RELEASE){
  currentpoint=-1;
  redraw();
  if (pair!=NULL) pair->redraw();
};

if ((event==FL_DRAG)&&(currentpoint>=0)){
  int ny=127-(int) (y_*127.0/h());
  if (ny<0) ny=0;if (ny>127) ny=127;
  env->Penvval[currentpoint]=ny;

  int dx=(int)((x_-cpx)*0.1);
  int newdt=cpdt+dx;
  if (newdt<0) newdt=0;if (newdt>127) newdt=127;
  if (currentpoint!=0) env->Penvdt[currentpoint]=newdt;
     else env->Penvdt[currentpoint]=0;

  redraw();
  if (pair!=NULL) pair->redraw();
};


return(1);} {}
  }
  decl {Fl_Box *pair;} {}
  decl {EnvelopeParams *env;} {}
  decl {int oldx,oldy;} {}
  decl {int currentpoint,cpx,cpdt;} {}
  decl {int lastpoint;} {public
  }
} 

class EnvelopeUI {: {public Fl_Group,PresetsUI_}
} {
  Function {EnvelopeUI(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} {
    code {env=NULL;
freemodeeditwindow=NULL;
envADSR=NULL;
envASR=NULL;
envADSRfilter=NULL;
envASRbw=NULL;
envfree=NULL;} {}
  }
  Function {~EnvelopeUI()} {} {
    code {envwindow->hide();
hide();
freemodeeditwindow->hide();
delete (freemodeeditwindow);} {}
  }
  Function {make_freemode_edit_window()} {} {
    Fl_Window freemodeeditwindow {
      label Envelope
      xywh {60 308 575 180} type Double hide
    } {
      Fl_Box freeedit {
        label Envelope
        xywh {5 5 565 145} box FLAT_BOX color 0
        code0 {o->init(env);}
        class EnvelopeFreeEdit
      }
      Fl_Button addpoint {
        label {Add point}
        callback {int curpoint=freeedit->lastpoint;
if (curpoint<0) return;
//if (curpoint>=env->Penvpoints-1) return;
if (env->Penvpoints>=MAX_ENVELOPE_POINTS) return;

for (int i=env->Penvpoints;i>=curpoint+1;i--){
   env->Penvdt[i]=env->Penvdt[i-1];
   env->Penvval[i]=env->Penvval[i-1];
};

if (curpoint==0) {
  env->Penvdt[1]=64;
};

env->Penvpoints++;
if (curpoint<=env->Penvsustain) env->Penvsustain++;

freeedit->lastpoint+=1;
freeedit->redraw();
envfree->redraw();

sustaincounter->value(env->Penvsustain);
sustaincounter->maximum(env->Penvpoints-2);}
        xywh {115 155 80 20} box THIN_UP_BOX
        code0 {if (env->Pfreemode==0) o->hide();}
      }
      Fl_Button deletepoint {
        label {Delete point}
        callback {int curpoint=freeedit->lastpoint;
if (curpoint<1) return;
if (curpoint>=env->Penvpoints-1) return;
if (env->Penvpoints<=3) return;

for (int i=curpoint+1;i<env->Penvpoints;i++){
   env->Penvdt[i-1]=env->Penvdt[i];
   env->Penvval[i-1]=env->Penvval[i];
};

env->Penvpoints--;

if (curpoint<=env->Penvsustain) env->Penvsustain--;


freeedit->lastpoint-=1;
freeedit->redraw();
envfree->redraw();

sustaincounter->value(env->Penvsustain);
sustaincounter->maximum(env->Penvpoints-2);}
        xywh {200 155 80 20} box THIN_UP_BOX
        code0 {if (env->Pfreemode==0) o->hide();}
      }
      Fl_Light_Button freemodebutton {
        label FreeMode
        callback {reinit();

freeedit->lastpoint=-1;
freeedit->redraw();}
        tooltip {Enable or disable the freemode} xywh {10 155 95 25} box PLASTIC_UP_BOX
      }
      Fl_Check_Button forcedreleasecheck {
        label frcR
        callback {env->Pforcedrelease=(int)o->value();}
        tooltip {Forced Relase} xywh {410 165 40 15} down_box DOWN_BOX labelsize 11
        code0 {o->value(env->Pforcedrelease);}
        code1 {if (env->Pfreemode==0) o->hide();}
      }
      Fl_Dial envstretchdial {
        label {Str.}
        callback {env->Penvstretch=(int)o->value();}
        tooltip {Envelope stretch (on lower notes make the envelope longer)} xywh {380 155 25 25} box ROUND_UP_BOX labelsize 11 align 4 maximum 127 step 1
        code0 {o->value(env->Penvstretch);}
        code1 {if (env->Pfreemode==0) o->hide();}
        class WidgetPDial
      }
      Fl_Button {} {
        label Close
        callback {freemodeeditwindow->hide();}
        xywh {510 155 60 25} box THIN_UP_BOX
      }
      Fl_Check_Button linearenvelopecheck {
        label L
        callback {env->Plinearenvelope=(int)o->value();}
        tooltip {Linear Envelope} xywh {410 151 30 15} down_box DOWN_BOX labelsize 11
        code0 {o->value(env->Plinearenvelope);}
        code1 {if ((env->Pfreemode==0)||(env->Envmode>2)) o->hide();}
      }
      Fl_Counter sustaincounter {
        label Sust
        callback {env->Penvsustain=(int) o->value();
freeedit->redraw();
envfree->redraw();}
        tooltip {Sustain (0 is disabled)} xywh {315 155 40 15} type Simple labelsize 12 align 4 minimum 0 maximum 127 step 1
        code0 {o->value(env->Penvsustain);}
        code1 {if (env->Pfreemode==0) o->hide();}
        code2 {o->maximum(env->Penvpoints-2);}
      }
      Fl_Button {} {
        label C
        callback {presetsui->copy(env);}
        xywh {465 160 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
      }
      Fl_Button {} {
        label P
        callback {presetsui->paste(env,this);}
        xywh {482 160 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
      }
    }
  }
  Function {make_ADSR_window()} {} {
    Fl_Window envADSR {
      xywh {108 336 205 70} type Double color 50 labelfont 1 hide
      class Fl_Group
    } {
      Fl_Group {} {
        label {Amplitude Envelope}
        xywh {0 0 205 70} box PLASTIC_UP_BOX color 223 labeltype ENGRAVED_LABEL labelsize 11 align 17
      } {
        Fl_Dial e1adt {
          label {A.dt}
          callback {env->PA_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Attack time} xywh {5 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PA_dt);}
          class WidgetPDial
        }
        Fl_Dial e1ddt {
          label {D.dt}
          callback {env->PD_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Decay time} xywh {40 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PD_dt);}
          class WidgetPDial
        }
        Fl_Dial e1rdt {
          label {R.dt}
          callback {env->PR_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Release time} xywh {110 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PR_dt);}
          class WidgetPDial
        }
        Fl_Dial e1sval {
          label {S.val}
          callback {env->PS_val=(int)o->value();
freeedit->redraw();}
          tooltip {Sustain value} xywh {75 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PS_val);}
          class WidgetPDial
        }
        Fl_Check_Button e1forcedrelease {
          label frcR
          callback {env->Pforcedrelease=(int)o->value();}
          tooltip {Forced Relase} xywh {180 35 20 15} down_box DOWN_BOX labelsize 11 align 6
          code0 {o->value(env->Pforcedrelease);}
        }
        Fl_Dial e1envstretch {
          label Stretch
          callback {env->Penvstretch=(int)o->value();}
          tooltip {Envelope stretch (on lower notes makes the envelope longer)} xywh {145 25 25 25} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->Penvstretch);}
          class WidgetPDial
        }
        Fl_Button {} {
          label E
          callback {freemodeeditwindow->show();}
          tooltip {Envelope window} xywh {185 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
        }
        Fl_Check_Button e1linearenvelope {
          label L
          callback {env->Plinearenvelope=(int)o->value();}
          tooltip {The evelope is linear} xywh {180 20 15 15} down_box DOWN_BOX labelsize 11 align 4
          code0 {o->value(env->Plinearenvelope);}
        }
        Fl_Button {} {
          label C
          callback {presetsui->copy(env);}
          xywh {150 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button {} {
          label P
          callback {presetsui->paste(env,this);}
          xywh {167 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
      }
    }
  }
  Function {make_ASR_window()} {} {
    Fl_Window envASR {
      xywh {71 320 210 70} type Double hide
      class Fl_Group
    } {
      Fl_Group {} {
        label {Frequency Envelope}
        xywh {0 0 210 70} box PLASTIC_UP_BOX color 223 labeltype ENGRAVED_LABEL labelsize 11 align 17
      } {
        Fl_Dial e2aval {
          label {A.val}
          callback {env->PA_val=(int)o->value();
freeedit->redraw();}
          tooltip {Starting value} xywh {5 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PA_val);}
          class WidgetPDial
        }
        Fl_Dial e2adt {
          label {A.dt}
          callback {env->PA_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Attack time} xywh {40 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PA_dt);}
          class WidgetPDial
        }
        Fl_Dial e2rval {
          label {R.val}
          callback {env->PR_val=(int)o->value();
freeedit->redraw();}
          tooltip {Release value} xywh {110 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PR_val);}
          class WidgetPDial
        }
        Fl_Dial e2rdt {
          label {R.dt}
          callback {env->PR_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Release time} xywh {75 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PR_dt);}
          class WidgetPDial
        }
        Fl_Dial e2envstretch {
          label Stretch
          callback {env->Penvstretch=(int)o->value();}
          tooltip {Envelope stretch (on lower notes makes the envelope longer)} xywh {145 25 25 25} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->Penvstretch);}
          class WidgetPDial
        }
        Fl_Check_Button e2forcedrelease {
          label frcR
          callback {env->Pforcedrelease=(int)o->value();}
          tooltip {Forced release} xywh {180 25 15 25} down_box DOWN_BOX labelsize 11 align 6
          code0 {o->value(env->Pforcedrelease);}
        }
        Fl_Button {} {
          label C
          callback {presetsui->copy(env);}
          xywh {155 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button {} {
          label P
          callback {presetsui->paste(env,this);}
          xywh {172 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
      }
      Fl_Button {} {
        label E
        callback {freemodeeditwindow->show();}
        tooltip {Envelope window} xywh {190 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
      }
    }
  }
  Function {make_ADSRfilter_window()} {} {
    Fl_Window envADSRfilter {
      xywh {87 143 275 70} type Double color 50 labelfont 1 hide
      class Fl_Group
    } {
      Fl_Group {} {
        label {Filter Envelope}
        xywh {0 0 275 70} box PLASTIC_UP_BOX color 223 labeltype ENGRAVED_LABEL labelsize 11 align 17
      } {
        Fl_Dial e3aval {
          label {A.val}
          callback {env->PA_val=(int)o->value();
freeedit->redraw();}
          tooltip {Starting value} xywh {5 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PA_val);}
          class WidgetPDial
        }
        Fl_Dial e3adt {
          label {A.dt}
          callback {env->PA_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Attack time} xywh {40 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PA_dt);}
          class WidgetPDial
        }
        Fl_Dial e3dval {
          label {D.val}
          callback {env->PD_val=(int)o->value();
freeedit->redraw();}
          tooltip {decay value} xywh {75 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PD_val);}
          class WidgetPDial
        }
        Fl_Dial e3ddt {
          label {D.dt}
          callback {env->PD_dt=(int)o->value();
freeedit->redraw();}
          tooltip {decay time} xywh {110 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PD_dt);}
          class WidgetPDial
        }
        Fl_Dial e3rdt {
          label {R.dt}
          callback {env->PR_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Release time} xywh {145 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PR_dt);}
          class WidgetPDial
        }
        Fl_Dial e3rval {
          label {R.val}
          callback {env->PR_val=(int)o->value();
freeedit->redraw();}
          tooltip {Release value} xywh {180 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PR_val);}
          class WidgetPDial
        }
        Fl_Dial e3envstretch {
          label Stretch
          callback {env->Penvstretch=(int)o->value();}
          tooltip {Envelope stretch (on lower notes makes the envelope longer)} xywh {215 25 25 25} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->Penvstretch);}
          class WidgetPDial
        }
        Fl_Check_Button e3forcedrelease {
          label frcR
          callback {env->Pforcedrelease=(int)o->value();}
          tooltip {Forced Relase} xywh {250 30 15 20} down_box DOWN_BOX labelsize 11 align 6
          code0 {o->value(env->Pforcedrelease);}
        }
        Fl_Button {} {
          label E
          callback {freemodeeditwindow->show();}
          xywh {255 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
        }
        Fl_Button {} {
          label C
          callback {presetsui->copy(env);}
          xywh {220 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button {} {
          label P
          callback {presetsui->paste(env,this);}
          xywh {237 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
      }
    }
  }
  Function {make_ASRbw_window()} {} {
    Fl_Window envASRbw {
      xywh {224 539 210 70} type Double hide
      class Fl_Group
    } {
      Fl_Group {} {
        label {BandWidth Envelope}
        xywh {0 0 210 70} box PLASTIC_UP_BOX color 223 labeltype ENGRAVED_LABEL labelsize 11 align 17
      } {
        Fl_Dial e4aval {
          label {A.val}
          callback {env->PA_val=(int)o->value();
freeedit->redraw();}
          tooltip {Starting value} xywh {5 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PA_val);}
          class WidgetPDial
        }
        Fl_Dial e4adt {
          label {A.dt}
          callback {env->PA_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Attack time} xywh {40 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PA_dt);}
          class WidgetPDial
        }
        Fl_Dial e4rval {
          label {R.val}
          callback {env->PR_val=(int)o->value();
freeedit->redraw();}
          tooltip {Release value} xywh {110 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PR_val);}
          class WidgetPDial
        }
        Fl_Dial e4rdt {
          label {R.dt}
          callback {env->PR_dt=(int)o->value();
freeedit->redraw();}
          tooltip {Release time} xywh {75 20 30 30} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->PR_dt);}
          class WidgetPDial
        }
        Fl_Dial e4envstretch {
          label Stretch
          callback {env->Penvstretch=(int)o->value();}
          tooltip {Envelope stretch (on lower notes makes the envelope longer)} xywh {145 25 25 25} box ROUND_UP_BOX labelsize 11 maximum 127 step 1
          code0 {o->value(env->Penvstretch);}
          class WidgetPDial
        }
        Fl_Check_Button e4forcedrelease {
          label frcR
          callback {env->Pforcedrelease=(int)o->value();}
          tooltip {Forced release} xywh {180 25 15 25} down_box DOWN_BOX labelsize 11 align 6
          code0 {o->value(env->Pforcedrelease);}
        }
        Fl_Button {} {
          label C
          callback {presetsui->copy(env);}
          xywh {155 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button {} {
          label P
          callback {presetsui->paste(env,this);}
          xywh {172 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
      }
      Fl_Button {} {
        label E
        callback {freemodeeditwindow->show();}
        xywh {190 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
      }
    }
  }
  Function {make_free_window()} {} {
    Fl_Window envfree {
      xywh {373 413 205 70} type Double color 50 labelfont 1 hide resizable
      class Fl_Group
    } {
      Fl_Group envfreegroup {
        label {Amplitude Envelope}
        xywh {0 0 205 70} box PLASTIC_UP_BOX color 223 labeltype ENGRAVED_LABEL labelsize 11 align 17 resizable
      } {
        Fl_Box freeeditsmall {
          label Envelope
          callback {envfree->redraw();}
          xywh {5 20 195 45} box FLAT_BOX color 0 resizable
          code0 {o->init(env);}
          class EnvelopeFreeEdit
        }
        Fl_Button {} {
          label E
          callback {freemodeeditwindow->show();}
          xywh {185 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
        }
        Fl_Button {} {
          label C
          callback {presetsui->copy(env);}
          xywh {150 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button {} {
          label P
          callback {presetsui->paste(env,this);}
          xywh {167 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
      }
    }
  }
  Function {init(EnvelopeParams *env_)} {} {
    code {env=env_;
make_ADSR_window();
make_ASR_window();
make_ADSRfilter_window();
make_ASRbw_window();
make_free_window();

make_freemode_edit_window();

envwindow=NULL;
if (env->Envmode==3) envfreegroup->label("Frequency Envelope");
if (env->Envmode==4) envfreegroup->label("Filter Envelope");
if (env->Envmode==5) envfreegroup->label("Bandwidth Envelope");

freemodeeditwindow->label(this->label());


freeeditsmall->setpair(freeedit);
freeedit->setpair(freeeditsmall);


refresh();} {}
  }
  Function {reinit()} {} {
    code {if (env->Pfreemode!=0){
  int answer=fl_ask("Disable the free mode of the Envelope?");
  if (env->Pfreemode!=0) freemodebutton->value(1);
          else freemodebutton->value(0);
  if (answer==0) return;
};

if (env->Pfreemode==0) env->Pfreemode=1;
     else env->Pfreemode=0;

hide();
int winx=freemodeeditwindow->x();
int winy=freemodeeditwindow->y();

freemodeeditwindow->hide();

envwindow->hide();
Fl_Group *par=envwindow->parent();
par->hide();


refresh();
envwindow->show();
par->redraw();

par->show();
show();
freemodeeditwindow->position(winx,winy);
freemodeeditwindow->show();

if (env->Pfreemode!=0) {
	freemodebutton->value(1);
	addpoint->show();
	deletepoint->show();
	forcedreleasecheck->show();
}else{
	freemodebutton->value(0);
	addpoint->hide();
	deletepoint->hide();
	forcedreleasecheck->hide();
};} {selected
    }
  }
  Function {refresh()} {} {
    code {freemodebutton->value(env->Pfreemode);

sustaincounter->value(env->Penvsustain);
if (env->Pfreemode==0) sustaincounter->hide();
	else sustaincounter->show();
sustaincounter->maximum(env->Penvpoints-2);

envstretchdial->value(env->Penvstretch);
if (env->Pfreemode==0) envstretchdial->hide();
	else envstretchdial->show();

linearenvelopecheck->value(env->Plinearenvelope);
if ((env->Pfreemode==0)||(env->Envmode>2)) linearenvelopecheck->hide();
	else linearenvelopecheck->show();

forcedreleasecheck->value(env->Pforcedrelease);
if (env->Pfreemode==0) forcedreleasecheck->hide();

freeedit->redraw();


if (env->Pfreemode==0){
   switch(env->Envmode){
         case(1):
         case(2):
		e1adt->value(env->PA_dt);
		e1ddt->value(env->PD_dt);
		e1sval->value(env->PS_val);
		e1rdt->value(env->PR_dt);
		e1envstretch->value(env->Penvstretch);
		e1linearenvelope->value(env->Plinearenvelope);
		e1forcedrelease->value(env->Pforcedrelease);
         break;
         case(3):
		e2aval->value(env->PA_val);
		e2adt->value(env->PA_dt);
		e2rdt->value(env->PR_dt);
		e2rval->value(env->PR_val);
		e2envstretch->value(env->Penvstretch);
		e2forcedrelease->value(env->Pforcedrelease);
         break; 
         case(4):
		e3aval->value(env->PA_val);
		e3adt->value(env->PA_dt);
		e3dval->value(env->PD_val);
		e3ddt->value(env->PD_dt);
		e3rdt->value(env->PR_dt);
		e3rval->value(env->PR_val);
		e3envstretch->value(env->Penvstretch);
		e3forcedrelease->value(env->Pforcedrelease);
         break; 
         case(5):
		e4aval->value(env->PA_val);
		e4adt->value(env->PA_dt);
		e4rdt->value(env->PR_dt);
		e4rval->value(env->PR_val);
		e4envstretch->value(env->Penvstretch);
		e4forcedrelease->value(env->Pforcedrelease);
         break;
         default:
         break; 
   };
}else{
       envfree->redraw();
};


envADSR->hide();
envASR->hide();
envADSRfilter->hide();
envASRbw->hide();
envfree->hide();

if (env->Pfreemode==0){
   switch(env->Envmode){
         case(1):
         case(2):
           envwindow=envADSR;
         break;
         case(3):
           envwindow=envASR;
         break; 
         case(4):
           envwindow=envADSRfilter;
         break; 
         case(5):
          envwindow=envASRbw;
         break;
         default:
         break; 
   };
}else{
   envwindow=envfree;
};

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

envwindow->show();} {}
  }
  decl {EnvelopeParams *env;} {}
  decl {Fl_Group *envwindow;} {}
}