# data file for the Fltk User Interface Designer (fluid)
version 1.0304
header_name {.h}
code_name {.cc}
comment {Envelope.h} {not_in_source in_header
}

comment {Envelope.cc} {in_source not_in_header
}

comment {Original ZynAddSubFX author Nasca Octavian Paul
Copyright (C) 2002-2005 Nasca Octavian Paul
Copyright 2009, Alan Calvert
Copyright 2016-2020 Will Godfrey

This file is part of yoshimi, which is free software: you can redistribute
it and/or modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.

yoshimi is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.   See the GNU General Public License (version 2 or
later) for more details.

You should have received a copy of the GNU General Public License along with
yoshimi; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA  02110-1301, USA.

This file is a derivative of the ZynAddSubFX original.

} {selected in_source in_header
}

decl {\#include "UI/MiscGui.h"} {public local
}

decl {\#include "UI/WidgetCheckButton.h"} {public local
}

decl {\#include "UI/WidgetPDial.h"} {public local
}

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

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

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

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

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

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

decl {\#include "Misc/SynthEngine.h"} {public global
}

decl {\#include "MasterUI.h"} {private global
}

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 {send_data(int action, int control, int offset, float value, int type)} {} {
    code {//
        type |= TOPLEVEL::type::Write;
        collect_data(synth, value, action, type, control, npart, kititem, engine, TOPLEVEL::insert::envelopePointChange, group, offset);} {}
  }
  Function {init(EnvelopeParams *env_, int npart_, int kititem_, int engine_, int group_)} {} {
    code {//
    env = env_;
    oldx = -1;
    currentpoint = -1;
    cpx = 0;
    lastpoint = -1;
    synth = env->getSynthEngine();
    npart = npart_;
    kititem = kititem_;
    engine = engine_;
    group = group_;} {}
  }
  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; // this is ambiguous :(

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

    return((int) (sumbefore / (float) 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();
    int oy = y();
    int lx = w();
    float scale = lx / 500.0f;
    fl_line_style(0, int(1 * scale));
    int 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(ox + 2, oy + ly / 2, ox + lx - 2, oy + ly / 2);

    //draws the evelope points and lines
    fl_line_style(0, int(2 *scale));
    Fl_Color alb = FL_WHITE;
    if (!active_r())
        alb = fl_rgb_color(180,180,180);
    fl_color(alb);
    int oldxx = 0;
    int xx = 0;
    int oldyy = 0;
    int 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)
    fl_line_style(0, int(1 * scale));
    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 * scale);
    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[40];
    if (time<1000.0)
        snprintf((char *)&tmpstr, 40, "%.1fms", time);
    else
        snprintf((char *)&tmpstr, 40, "%.2fs", time / 1000.0);
    fl_draw(tmpstr, ox + lx - 20 * scale, oy + ly - 10 * scale, 20 * scale, 10 * scale, FL_ALIGN_RIGHT, NULL, 0);

    //Draw formatted point value in the top right corner when dragging points
    if (currentpoint >= 0)
    {
        string valDesc;
        float val = (float) env->Penvval[currentpoint];
        switch(env->Envmode){
            case PART::envelope::groupmode::amplitudeLin: //linear amplitude
            case PART::envelope::groupmode::amplitudeLog: //db amplitude
                if (env->Plinearenvelope)
                    valDesc = convert_value(VC_EnvelopeLinAmpSusVal, val);
                else
                    valDesc = convert_value(VC_EnvelopeAmpSusVal, val);
                break;
            case PART::envelope::groupmode::frequency: //frequency offset
                valDesc = convert_value(VC_EnvelopeFreqVal, val);
                break;
            case PART::envelope::groupmode::filter: //filter frequency offset
                valDesc = convert_value(VC_EnvelopeFilterVal, val);
                break;
            case PART::envelope::groupmode::bandwidth: //bandwidth offset (unformatted)
                valDesc = convert_value(VC_EnvelopeBandwidthVal, val);
                break;
            default:
                valDesc = "unknown env. type";
        }
        strcpy(tmpstr, valDesc.c_str());
        fl_color(FL_CYAN);
        fl_draw(tmpstr, ox + lx - 30, oy, 30, 25, FL_ALIGN_RIGHT, NULL, 0);
}
fl_line_style(0,1);} {}
  }
  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();
            return(1);
        }
    }

    if (event == FL_RELEASE)
    {
        currentpoint = -1;
    }

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

        int dx = (int)((x_- cpx) * 0.1);
        int newdt = cpdt + dx;
        if (newdt < 0)
            newdt = 0;
        if (newdt > 127)
            newdt = 127;

        send_data(TOPLEVEL::action::forceUpdate, currentpoint, newdt, ny, TOPLEVEL::type::Write);
}
return(1);} {}
  }
  decl {Fl_Box *pair;} {private local
  }
  decl {EnvelopeParams *env;} {private local
  }
  decl {int oldx,oldy;} {private local
  }
  decl {int currentpoint,cpx,cpdt;} {private local
  }
  decl {int lastpoint;} {public local
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {int npart;} {private local
  }
  decl {int kititem;} {private local
  }
  decl {int engine;} {private local
  }
  decl {int group;} {private local
  }
}

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 {//
    synth = NULL;
    env=NULL;
    freemodeeditwindow=NULL;
    envADSR=NULL;
    envASR=NULL;
    envADSRfilter=NULL;
    envASRbw=NULL;
    envfree=NULL;} {}
  }
  Function {~EnvelopeUI()} {} {
    code {//
	if (freemodeeditwindow->x() > 4)
            saveWin(synth, freemodeeditwindow->w(), freemodeeditwindow->h(), freemodeeditwindow->x(), freemodeeditwindow->y(),freemodeeditwindow->visible(), "xEnvelope-free " + to_string(engine) + " " + to_string(group));
        freemodeeditwindow->hide();
        delete (freemodeeditwindow);
        envwindow->hide();
        hide();} {}
  }
  Function {make_freemode_edit_window()} {} {
    Fl_Window freemodeeditwindow {
      label Envelope
      callback {freeClose->do_callback();}
      xywh {614 158 575 180} type Double hide resizable
      code0 {freeDW = o->w(); freeDH = o->h();}
      code1 {o->size_range(freeDW, freeDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Box freeedit {
        label Envelope
        xywh {5 5 565 145} box FLAT_BOX color 0
        code0 {o->init(env, npart, kititem, engine, group);}
        class EnvelopeFreeEdit
      }
      Fl_Light_Button freemodebutton {
        label FreeMode
        callback {//
        if (env->Pfreemode != 0)
        {
            bool answer = choice(synth, "", "Yes", "No", "Disable the free mode of the Envelope?") > 1;
            if (!answer)
            {
                o->value(1); // back as it was
                return;
            }
        }

        send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::enableFreeMode, o->value(), TOPLEVEL::type::Write);}
        tooltip {Enable or disable the freemode} xywh {10 154 95 22} box PLASTIC_UP_BOX labelsize 11
      }
      Fl_Button addpoint {
        label {Add point}
        callback {//
        int curpoint = freeedit->lastpoint;
        if (curpoint<0)
            return;
        if (env->Penvpoints >= MAX_ENVELOPE_POINTS)
            return;

        int value = env->Penvval[curpoint];
        int offset = env->Penvdt[curpoint];

        send_data(TOPLEVEL::action::forceUpdate, group, curpoint, value, TOPLEVEL::type::Write, TOPLEVEL::insert::envelopePoints, offset);}
        xywh {112 155 80 20} box THIN_UP_BOX labelsize 11
        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;

send_data(TOPLEVEL::action::forceUpdate, group, curpoint, 0, TOPLEVEL::type::Write, TOPLEVEL::insert::envelopePoints);}
        xywh {200 155 80 20} box THIN_UP_BOX labelsize 11
        code0 {if (env->Pfreemode==0) o->hide();}
      }
      Fl_Counter sustaincounter {
        label Sust
        callback {//
        send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::sustainPoint, o->value(), TOPLEVEL::type::Write);}
        tooltip {Sustain (0 is disabled)} xywh {315 158 40 15} type Simple labelsize 11 align 4 minimum 0 maximum 127 step 1 textfont 1 textsize 12
        code0 {o->value(env->Penvsustain);}
        code1 {if (env->Pfreemode==0) o->hide();}
        code2 {o->maximum(env->Penvpoints-2);}
      }
      Fl_Dial envstretchdial {
        label {Str.}
        callback {//
        send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::stretch, o->value(), TOPLEVEL::type::Write);}
        tooltip {Envelope stretch (on lower notes make the envelope longer)} xywh {380 153 25 25} box ROUND_UP_BOX labelsize 10 align 4 maximum 127 step 1
        code0 {o->value(env->Penvstretch);}
        code1 {if (env->Pfreemode==0) o->hide();}
        code2 {o->setValueType(VC_EnvStretch);}
        class WidgetPDial
      }
      Fl_Check_Button linearenvelopecheck {
        class Fl_Check_Button2
        label L
        callback {//
        send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::linearEnvelope, o->value(), TOPLEVEL::type::Write);}
        tooltip {Linear Envelope} xywh {415 151 30 15} down_box DOWN_BOX labelsize 10
        code0 {o->value(env->Plinearenvelope);}
        code1 {if ((env->Pfreemode==0)||(env->Envmode>2)) o->hide();}
      }
      Fl_Check_Button forcedreleasecheck {
        class Fl_Check_Button2
        label frcR
        callback {//
        send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::forcedRelease, o->value(), TOPLEVEL::type::Write);}
        tooltip {Forced Release} xywh {415 165 40 15} down_box DOWN_BOX labelsize 10
        code0 {o->value(env->Pforcedrelease);}
        code1 {if (env->Pfreemode==0) o->hide();}
      }
      Fl_Button freecopy {
        label C
        callback {synth->getGuiMaster()->getPresetsUi()->copy(env);}
        xywh {465 158 16 16} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
      }
      Fl_Button freepaste {
        label P
        callback {synth->getGuiMaster()->getPresetsUi()->paste(env,this);}
        xywh {486 158 16 16} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
      }
      Fl_Button freeClose {
        label Close
        callback {freemodeeditwindow->hide();
saveWin(synth, freemodeeditwindow->w(), freemodeeditwindow->h(), freemodeeditwindow->x(), freemodeeditwindow->y(), false, "xEnvelope-free " + to_string(engine) + " " + to_string(group));}
        xywh {519 155 44 20} box THIN_UP_BOX labelsize 12
      }
    }
  }
  Function {make_ADSR_window()} {} {
    Fl_Window envADSR {
      xywh {1185 87 205 70} type Double color 50 labelfont 1 hide
      class Fl_Group
    } {
      Fl_Group e1name {
        label {Amplitude Env}
        xywh {0 0 205 70} box PLASTIC_UP_BOX color 223 labelfont 1 labelsize 10 align 17
      } {
        Fl_Dial e1adt {
          label {A.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::attackTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Attack time} xywh {5 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PA_dt);}
          class WidgetPDial
        }
        Fl_Dial e1ddt {
          label {D.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::decayTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Decay time} xywh {40 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PD_dt);}
          class WidgetPDial
        }
        Fl_Dial e1rdt {
          label {R.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::releaseTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Release time} xywh {110 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PR_dt);}
          class WidgetPDial
        }
        Fl_Dial e1sval {
          label {S.val}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::sustainLevel, o->value(), TOPLEVEL::type::Write);}
          tooltip {Sustain value} xywh {75 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeAmpSusVal);}
          code1 {o->value(env->PS_val);}
          class WidgetPDial
        }
        Fl_Check_Button e1forcedrelease {
          class Fl_Check_Button2
          label frcR
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::forcedRelease, o->value(), TOPLEVEL::type::Write);}
          tooltip {Forced Release} xywh {180 35 20 15} down_box DOWN_BOX labelsize 10 align 6
          code0 {o->value(env->Pforcedrelease);}
        }
        Fl_Dial e1envstretch {
          label Stretch
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::stretch, o->value(), TOPLEVEL::type::Write);}
          tooltip {Envelope stretch (on lower notes makes the envelope longer)} xywh {145 25 25 25} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(env->Penvstretch);}
          code1 {o->setValueType(VC_EnvStretch);}
          class WidgetPDial
        }
        Fl_Button e1E {
          label E
          callback {//
          showfree();
          send_data(0, group, ENVELOPEINSERT::control::edit, o->value(), TOPLEVEL::type::Write);}
          tooltip {Envelope window} xywh {185 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
        }
        Fl_Check_Button e1linearenvelope {
          class Fl_Check_Button2
          label L
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::linearEnvelope, o->value(), TOPLEVEL::type::Write);}
          tooltip {The envelope is linear} xywh {180 20 15 15} down_box DOWN_BOX labelsize 10 align 4
          code0 {o->value(env->Plinearenvelope);}
        }
        Fl_Button e1C {
          label C
          callback {//
          synth->getGuiMaster()->getPresetsUi()->copy(env);}
          xywh {150 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button e1P {
          label P
          callback {synth->getGuiMaster()->getPresetsUi()->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 {1183 190 210 70} type Double hide
      class Fl_Group
    } {
      Fl_Group e2name {
        label {Frequency Env}
        xywh {0 0 210 70} box PLASTIC_UP_BOX color 223 labelfont 1 labelsize 10 align 17
      } {
        Fl_Dial e2aval {
          label {A.val}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::attackLevel, o->value(), TOPLEVEL::type::Write);}
          tooltip {Starting value} xywh {5 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeFreqVal);}
          code1 {o->value(env->PA_val);}
          class WidgetPDial
        }
        Fl_Dial e2adt {
          label {A.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::attackTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Attack time} xywh {40 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PA_dt);}
          class WidgetPDial
        }
        Fl_Dial e2rval {
          label {R.val}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::releaseLevel, o->value(), TOPLEVEL::type::Write);}
          tooltip {Release value} xywh {110 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeFreqVal);}
          code1 {o->value(env->PR_val);}
          class WidgetPDial
        }
        Fl_Dial e2rdt {
          label {R.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::releaseTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Release time} xywh {75 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PR_dt);}
          class WidgetPDial
        }
        Fl_Dial e2envstretch {
          label Stretch
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::stretch, o->value(), TOPLEVEL::type::Write);}
          tooltip {Envelope stretch (on lower notes makes the envelope longer)} xywh {145 25 25 25} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(env->Penvstretch);}
          code1 {o->setValueType(VC_EnvStretch);}
          class WidgetPDial
        }
        Fl_Check_Button e2forcedrelease {
          class Fl_Check_Button2
          label frcR
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::forcedRelease, o->value(), TOPLEVEL::type::Write);}
          tooltip {Forced release} xywh {180 25 15 25} down_box DOWN_BOX labelsize 10 align 6
          code0 {o->value(env->Pforcedrelease);}
        }
        Fl_Button e2C {
          label C
          callback {synth->getGuiMaster()->getPresetsUi()->copy(env);}
          xywh {155 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button e2P {
          label P
          callback {synth->getGuiMaster()->getPresetsUi()->paste(env,this);}
          xywh {172 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
      }
      Fl_Button e2E {
        label E
        callback {//
      showfree();
      send_data(0, group, ENVELOPEINSERT::control::edit, o->value(), TOPLEVEL::type::Write);}
        tooltip {Envelope window} xywh {190 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
      }
    }
  }
  Function {make_ADSRfilter_window()} {} {
    Fl_Window envADSRfilter {
      xywh {1121 294 275 70} type Double color 50 labelfont 1 hide
      class Fl_Group
    } {
      Fl_Group e3name {
        label {Filter Envelope}
        xywh {0 0 275 70} box PLASTIC_UP_BOX color 223 labelfont 1 labelsize 10 align 17
      } {
        Fl_Dial e3aval {
          label {A.val}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::attackLevel, o->value(), TOPLEVEL::type::Write);}
          tooltip {Starting value} xywh {5 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeFilterVal);}
          code1 {o->value(env->PA_val);}
          class WidgetPDial
        }
        Fl_Dial e3adt {
          label {A.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::attackTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Attack time} xywh {40 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PA_dt);}
          class WidgetPDial
        }
        Fl_Dial e3dval {
          label {D.val}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::decayLevel, o->value(), TOPLEVEL::type::Write);}
          tooltip {decay value} xywh {75 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeFilterVal);}
          code1 {o->value(env->PD_val);}
          class WidgetPDial
        }
        Fl_Dial e3ddt {
          label {D.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::decayTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {decay time} xywh {110 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PD_dt);}
          class WidgetPDial
        }
        Fl_Dial e3rdt {
          label {R.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::releaseTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Release time} xywh {145 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PR_dt);}
          class WidgetPDial
        }
        Fl_Dial e3rval {
          label {R.val}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::releaseLevel, o->value(), TOPLEVEL::type::Write);}
          tooltip {Release value} xywh {180 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeFilterVal);}
          code1 {o->value(env->PR_val);}
          class WidgetPDial
        }
        Fl_Dial e3envstretch {
          label Stretch
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::stretch, o->value(), TOPLEVEL::type::Write);}
          tooltip {Envelope stretch (on lower notes makes the envelope longer)} xywh {215 25 25 25} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(env->Penvstretch);}
          code1 {o->setValueType(VC_EnvStretch);}
          class WidgetPDial
        }
        Fl_Check_Button e3forcedrelease {
          class Fl_Check_Button2
          label frcR
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::forcedRelease, o->value(), TOPLEVEL::type::Write);}
          tooltip {Forced Release} xywh {250 30 15 20} down_box DOWN_BOX labelsize 10 align 6
          code0 {o->value(env->Pforcedrelease);}
        }
        Fl_Button e3E {
          label E
          callback {//
          showfree();
          send_data(0, group, ENVELOPEINSERT::control::edit, o->value(), TOPLEVEL::type::Write);}
          xywh {255 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
        }
        Fl_Button e3C {
          label C
          callback {synth->getGuiMaster()->getPresetsUi()->copy(env);}
          xywh {220 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button e3P {
          label P
          callback {synth->getGuiMaster()->getPresetsUi()->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 {1209 649 210 70} type Double hide
      class Fl_Group
    } {
      Fl_Group e4name {
        label {BandWidth Env}
        xywh {0 0 210 70} box PLASTIC_UP_BOX color 223 labelfont 1 labelsize 10 align 17
      } {
        Fl_Dial e4aval {
          label {A.val}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::attackLevel, o->value(), TOPLEVEL::type::Write);}
          tooltip {Bandwidth multiplier, start} xywh {8 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(env->PA_val);}
          code1 {o->setValueType(VC_EnvelopeBandwidthVal);}
          class WidgetPDial
        }
        Fl_Dial e4adt {
          label {A.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::attackTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Attack time} xywh {43 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PA_dt);}
          class WidgetPDial
        }
        Fl_Dial e4rval {
          label {R.val}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::releaseLevel, o->value(), TOPLEVEL::type::Write);}
          tooltip {Bandwidth multiplier, release} xywh {113 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(env->PR_val);}
          code1 {o->setValueType(VC_EnvelopeBandwidthVal);}
          class WidgetPDial
        }
        Fl_Dial e4rdt {
          label {R.dt}
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::releaseTime, o->value(), TOPLEVEL::type::Write);}
          tooltip {Release time} xywh {78 20 30 30} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->setValueType(VC_EnvelopeDT);}
          code1 {o->value(env->PR_dt);}
          class WidgetPDial
        }
        Fl_Dial e4envstretch {
          label Stretch
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::stretch, o->value(), TOPLEVEL::type::Write);}
          tooltip {Envelope stretch (on lower notes makes the envelope longer)} xywh {148 25 25 25} box ROUND_UP_BOX labelsize 10 maximum 127 step 1
          code0 {o->value(env->Penvstretch);}
          code1 {o->setValueType(VC_EnvStretch);}
          class WidgetPDial
        }
        Fl_Check_Button e4forcedrelease {
          class Fl_Check_Button2
          label frcR
          callback {//
          send_data(TOPLEVEL::action::forceUpdate, group, ENVELOPEINSERT::control::forcedRelease, o->value(), TOPLEVEL::type::Write);}
          tooltip {Forced release} xywh {185 25 15 25} down_box DOWN_BOX labelsize 10 align 6
          code0 {o->value(env->Pforcedrelease);}
        }
        Fl_Button e4C {
          label C
          callback {synth->getGuiMaster()->getPresetsUi()->copy(env);}
          xywh {155 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
        Fl_Button e4P {
          label P
          callback {synth->getGuiMaster()->getPresetsUi()->paste(env,this);}
          xywh {172 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
        }
      }
      Fl_Button e4E {
        label E
        callback {//
        showfree();
        send_data(0, group, ENVELOPEINSERT::control::edit, o->value(), TOPLEVEL::type::Write);}
        xywh {190 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
      }
    }
  }
  Function {make_free_window()} {} {
    Fl_Window envfree {
      xywh {874 240 205 70} type Double color 50 labelfont 1 hide resizable
      class Fl_Group
    } {
      Fl_Group envfreegroup {
        label {Amplitude Env}
        xywh {0 0 205 70} box PLASTIC_UP_BOX color 223 labelfont 1 labelsize 10 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, npart, kititem, engine, group);}
          class EnvelopeFreeEdit
        }
      }
      Fl_Button efC {
        label C
        callback {synth->getGuiMaster()->getPresetsUi()->copy(env);}
        xywh {150 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
      }
      Fl_Button efP {
        label P
        callback {synth->getGuiMaster()->getPresetsUi()->paste(env,this);}
        xywh {168 5 15 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 10 labelcolor 7
      }
      Fl_Button efE {
        label E
        callback {showfree();
          send_data(0, group, ENVELOPEINSERT::control::edit, o->value(), TOPLEVEL::type::Write);}
        xywh {185 5 15 15} box PLASTIC_UP_BOX labelfont 1 labelsize 10
      }
    }
  }
  Function {send_data(int action, int group, int control, float value, int type, int insert = TOPLEVEL::insert::envelopeGroup, int offset = UNUSED)} {} {
    code {//
    collect_data(synth, value, action, type, control, npart, kititem, engine, insert, group, offset);} {}
  }
  Function {returns_update(CommandBlock *getData)} {} {
    code {//
    float value = getData->data.value;
    unsigned char control = getData->data.control;
    unsigned char part = getData->data.part;
    unsigned char eng = getData->data.engine;
    unsigned char insert = getData->data.insert;
    unsigned char param = getData->data.parameter;
    unsigned char offset = getData->data.offset;

    int value_int = lrint(value);
    bool value_bool = _SYS_::F2B(value);
    bool isFreemode = _SYS_::F2B(freemodebutton->value());
    bool NotUs = ((getData->data.source & TOPLEVEL::action::noAction) != TOPLEVEL::action::fromGUI || (getData->data.source & TOPLEVEL::action::forceUpdate));

    if (part != npart || (eng >= 128 && eng != engine))
        return;

    if (insert == TOPLEVEL::insert::envelopePoints || insert == TOPLEVEL::insert::envelopePointChange)
    {
        if (insert == TOPLEVEL::insert::envelopePointChange) // adjust point
            freeedit->lastpoint = control;
        else if (offset > 127) // delete point
            freeedit->lastpoint -= 1;
        else // add point
            freeedit->lastpoint += 1;
        freeedit->redraw();
        envfree->redraw();
        sustaincounter->value(env->Penvsustain);
        sustaincounter->maximum(env->Penvpoints-2);
        return;
    }

    bool change = true;
    switch(control)
    {
        case ENVELOPEINSERT::control::attackLevel:
            if (NotUs)
            {
                switch (param)
                {
                    case TOPLEVEL::insertType::frequency:
                        e2aval->value(value);
                        break;
                    case TOPLEVEL::insertType::filter:
                        e3aval->value(value);
                        break;
                    case TOPLEVEL::insertType::bandwidth:
                        e4aval->value(value);
                        break;
                }
            }
            break;

        case ENVELOPEINSERT::control::attackTime:
            if (NotUs)
            {
                switch (param)
                {
                    case TOPLEVEL::insertType::amplitude:
                        e1adt->value(value);
                        break;
                    case TOPLEVEL::insertType::frequency:
                        e2adt->value(value);
                        break;
                    case TOPLEVEL::insertType::filter:
                        e3adt->value(value);
                        break;
                    case TOPLEVEL::insertType::bandwidth:
                        e4adt->value(value);
                        break;
                }
            }
            break;

        case ENVELOPEINSERT::control::decayLevel:
            if (param == TOPLEVEL::insertType::filter && NotUs)
                e3dval->value(value);
            break;

        case ENVELOPEINSERT::control::decayTime:
            if (NotUs)
            {
                switch (param)
                {
                    case TOPLEVEL::insertType::amplitude:
                        e1ddt->value(value);
                        break;
                    case TOPLEVEL::insertType::filter:
                        e3ddt->value(value);
                        break;
                }
            }
            break;

        case ENVELOPEINSERT::control::sustainLevel:
            if (param == TOPLEVEL::insertType::amplitude && NotUs)
                e1sval->value(value);
            break;

        case ENVELOPEINSERT::control::releaseTime:
            if (NotUs)
            {
                switch (param)
                {
                    case TOPLEVEL::insertType::amplitude:
                        e1rdt->value(value);
                        break;
                    case TOPLEVEL::insertType::frequency:
                        e2rdt->value(value);
                        break;
                    case TOPLEVEL::insertType::filter:
                        e3rdt->value(value);
                        break;
                    case TOPLEVEL::insertType::bandwidth:
                        e4rdt->value(value);
                        break;
                }
            }
            break;

        case ENVELOPEINSERT::control::releaseLevel:
            if (NotUs)
            {
                switch (param)
                {
                    case TOPLEVEL::insertType::frequency:
                        e2rval->value(value);
                        break;
                    case TOPLEVEL::insertType::filter:
                        e3rval->value(value);
                        break;
                    case TOPLEVEL::insertType::bandwidth:
                        e4rval->value(value);
                        break;
                }
            }
            break;

        case ENVELOPEINSERT::control::stretch:
            switch (param)
            {
                case TOPLEVEL::insertType::amplitude:
                    e1envstretch->value(value);
                    break;
                case TOPLEVEL::insertType::frequency:
                    e2envstretch->value(value);
                    break;
                case TOPLEVEL::insertType::filter:
                    e3envstretch->value(value);
                    break;
                case TOPLEVEL::insertType::bandwidth:
                    e4envstretch->value(value);
                    break;
            }
            envstretchdial->value(value);
            change = false;
            break;

        case ENVELOPEINSERT::control::forcedRelease:
            switch (param)
            {
                case TOPLEVEL::insertType::amplitude:
                    e1forcedrelease->value(value_bool);
                    break;
                case TOPLEVEL::insertType::frequency:
                    e2forcedrelease->value(value_bool);
                    break;
                case TOPLEVEL::insertType::filter:
                    e3forcedrelease->value(value_bool);
                    break;
                case TOPLEVEL::insertType::bandwidth:
                    e4forcedrelease->value(value_bool);
                    break;
            }
            forcedreleasecheck->value(value_bool);
            change = false;
            break;

        case ENVELOPEINSERT::control::linearEnvelope:
            if (param == TOPLEVEL::insertType::amplitude)
            {
                e1linearenvelope->value(value_bool);
                linearenvelopecheck->value(value_bool);
            }
            change = false;
            break;

        case ENVELOPEINSERT::control::enableFreeMode:
            reinitcore(value_bool);
            break;

        case ENVELOPEINSERT::control::sustainPoint:
            if (isFreemode && NotUs)
                sustaincounter->value(value_int);
            break;
    }
    if (change)
        freeedit->redraw();} {}
  }
  Function {init(EnvelopeParams *env_, int npart_, int kititem_, int engine_, int group_)} {} {
    code {//
    env=env_;
    synth = env->getSynthEngine();
    npart = npart_;
    kititem = kititem_;
    engine = engine_;
    group = group_;
    lastfreeX = lastfreeY = lastfreeW = 0xffff;
    make_ADSR_window();
    make_ASR_window();
    make_ADSRfilter_window();
    make_ASRbw_window();
    make_free_window();
    make_freemode_edit_window();

    envwindow=NULL;

    if (env->Envmode == PART::envelope::groupmode::frequency) envfreegroup->label("Frequency Env");
    if (env->Envmode == PART::envelope::groupmode::filter) envfreegroup->label("Filter Envelope");
    if (env->Envmode == PART::envelope::groupmode::bandwidth) envfreegroup->label("Bandwidth Env");

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

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

    refresh();} {}
  }
  Function {reinitcore(bool freemode)} {} {
    code {//
    if (freemode)
        freemodebutton->value(1);
    else
        freemodebutton->value(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 (freemode)
    {
        freemodebutton->value(1);
        addpoint->show();
        deletepoint->show();
        forcedreleasecheck->show();
    }
    else
    {
        freemodebutton->value(0);
        addpoint->hide();
        deletepoint->hide();
        forcedreleasecheck->hide();
}} {}
  }
  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(PART::envelope::groupmode::amplitudeLin):
            case(PART::envelope::groupmode::amplitudeLog):
                e1adt->value(env->PA_dt);
                e1ddt->value(env->PD_dt);
                e1sval->value(env->PS_val);
                setAmpSusVType(env->Plinearenvelope);
                e1rdt->value(env->PR_dt);
                e1envstretch->value(env->Penvstretch);
                e1linearenvelope->value(env->Plinearenvelope);
                e1forcedrelease->value(env->Pforcedrelease);
                break;
            case(PART::envelope::groupmode::frequency):
                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(PART::envelope::groupmode::filter):
                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(PART::envelope::groupmode::bandwidth):
                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();
/*
    We now always initialse and position related groups as well as the freemode one
    This is to ensure that resizing will have the correct starting size and position
    even if a part was loaded specifying the freemode form.
*/
    //if (env->Pfreemode==0)
    {
        switch(env->Envmode)
        {
            case(PART::envelope::groupmode::amplitudeLin):
            case(PART::envelope::groupmode::amplitudeLog):
                envwindow=envADSR;
                break;
            case(PART::envelope::groupmode::frequency):
                envwindow=envASR;
                break;
            case(PART::envelope::groupmode::filter):
                envwindow=envADSRfilter;
                break;
            case(PART::envelope::groupmode::bandwidth):
                envwindow=envASRbw;
                break;
            default:
                break;
        }
        envwindow->resize(this->x(),this->y(),this->w(),this->h());
    }
    //else
    if (env->Pfreemode)
    {
        envwindow=envfree;
        envwindow->resize(this->x(),this->y(),this->w(),this->h());
    }

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

    envwindow->show();} {}
  }
  Function {showfree()} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "xEnvelope-free " + to_string(engine) + " " + to_string(group));

    if (fetchW < freeDW || fetchH < freeDH)
    {
        fetchW = freeDW;
        fetchH = freeDH;
    }
    checkSane(fetchX, fetchY, fetchW, fetchH, freeDW, freeDH);

    freemodeeditwindow->resize(fetchX, fetchY, fetchW, fetchH);
    freemodeeditwindow->show();
    envfreeRtext();} {}
  }
  Function {wincheck()} {} {
    code {//
    if (!freemodeeditwindow->visible())
        return;
    if (freemodeeditwindow->x() == lastfreeX && freemodeeditwindow->y() == lastfreeY && freemodeeditwindow->w() == lastfreeW)
        return;
    envfreeRtext();
    lastfreeX = freemodeeditwindow->x();
    lastfreeY = freemodeeditwindow->y();
    lastfreeW = freemodeeditwindow->w();} {}
  }
  Function {envfreeRtext()} {} {
    code {//
        int w = freemodeeditwindow->w();
        int h = freemodeeditwindow->h();
        float defW = 575;
        float defH = 180;
        float dW = w / defW;
        float dH = h / defH;
        float dScale;
        if (dW < dH)
            dScale = dW;
        else
            dScale = dH;
        if (dScale < 0.2f)
            dScale = 0.2f;

        int size = int(10 * dScale);
        int size11 = int(11 * dScale);
        int size12 = int(12 * dScale);

        freemodebutton->labelsize(size11);
        addpoint->labelsize(size11);
        deletepoint->labelsize(size11);
        sustaincounter->labelsize(size11);
            sustaincounter->textsize(size12);
        envstretchdial->labelsize(size);
        linearenvelopecheck->labelsize(size);
        forcedreleasecheck->labelsize(size);
        freecopy->labelsize(size);
        freepaste->labelsize(size);
        freeClose->labelsize(size12);} {}
  }
  Function {envRtext(float dScale)} {} {
    code {//
        int X = this->x();
        int Y = this->y();
        int W = this->w();
        int H = this->h();

        int size = int(dScale * 10);


        e1name->labelsize(size);
        e1adt->labelsize(size);
        e1ddt->labelsize(size);
        e1rdt->labelsize(size);
        e1sval->labelsize(size);
        e1forcedrelease->labelsize(size);
        e1envstretch->labelsize(size);
        e1E->labelsize(size);
        e1linearenvelope->labelsize(size);
        e1C->labelsize(size);
        e1P->labelsize(size);

        e2name->labelsize(size);
        e2aval->labelsize(size);
        e2adt->labelsize(size);
        e2rval->labelsize(size);
        e2rdt->labelsize(size);
        e2envstretch->labelsize(size);
        e2forcedrelease->labelsize(size);
        e2C->labelsize(size);
        e2P->labelsize(size);
        e2E->labelsize(size);

        e3name->labelsize(size);
        e3aval->labelsize(size);
        e3adt->labelsize(size);
        e3dval->labelsize(size);
        e3ddt->labelsize(size);
        e3rval->labelsize(size);
        e3rdt->labelsize(size);
        e3envstretch->labelsize(size);
        e3forcedrelease->labelsize(size);
        e3C->labelsize(size);
        e3P->labelsize(size);
        e3E->labelsize(size);

        e4name->labelsize(size);
        e4aval->labelsize(size);
        e4adt->labelsize(size);
        e4rval->labelsize(size);
        e4rdt->labelsize(size);
        e4envstretch->labelsize(size);
        e4forcedrelease->labelsize(size);
        e4C->labelsize(size);
        e4P->labelsize(size);
        e4E->labelsize(size);

        envfreegroup->labelsize(size);
        efC->labelsize(size);
        efP->labelsize(size);
        efE->labelsize(size);

        envfree->resize(X, Y, W, H);

        freeeditsmall->resize(int(X + 5*dScale), int(Y + 20*dScale), int(W - 9*dScale), int(H - 25*dScale));} {}
  }
  Function {setAmpSusVType(bool linear)} {return_type void
  } {
    code {//
    if (linear)
        e1sval->setValueType(VC_EnvelopeLinAmpSusVal);
    else
        e1sval->setValueType(VC_EnvelopeAmpSusVal);} {}
  }
  decl {EnvelopeParams *env;} {private local
  }
  decl {Fl_Group *envwindow;} {private local
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {int npart;} {private local
  }
  decl {int kititem;} {private local
  }
  decl {int engine;} {private local
  }
  decl {int group;} {private local
  }
  decl {int lastfreeX;} {private local
  }
  decl {int lastfreeY;} {private local
  }
  decl {int lastfreeW;} {private local
  }
  decl {int freeDW;} {private local
  }
  decl {int freeDH;} {private local
  }
}
