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

comment {PADNoteUI.cc} {in_source not_in_header
}

comment {Original ZynAddSubFX author Nasca Octavian Paul
Copyright (C) 2002-2005 Nasca Octavian Paul
Copyright 2009-2011, Alan Calvert
Copyright 2015-2021, Will Godfrey
Copyright 2022-2024, Ichthyostega, 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 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 derivative of ZynAddSubFX original code

} {selected in_source in_header
}

decl {\#include <FL/Fl_Box.H>
    \#include <FL/Fl_Group.H>
    \#include <FL/fl_draw.H>
    \#include "Params/PADnoteParameters.h"
    \#include "UI/MiscGui.h"
    \#include "PresetsUI.h"
    \#include "UI/WidgetPDial.h"
    \#include "UI/WidgetCheckButton.h"
    \#include "EnvelopeUI.h"
    \#include "LFOUI.h"
    \#include "FilterUI.h"} {private global
}

decl {\#include "ResonanceUI.h"
    \#include "OscilGenUI.h"} {public global
}

decl {\#include <memory>
    using std::unique_ptr;
    class PADStatus;} {public global
}

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

decl {\#include "Params/PADStatus.h"} {private local
}

decl {\#include "Misc/SynthHelper.h"
    using synth::getDetune;} {private local
}

decl {\#include "Misc/NumericFuncs.h"
    using func::decibel;
    using func::asDecibel;
    using func::power;} {private local
}

decl {\#include "Misc/TextMsgBuffer.h"

    namespace { // Implementation details...
        TextMsgBuffer& textMsgBuffer = TextMsgBuffer::instance();
    }} {private local
}

decl {\#include "Interface/TextLists.h"} {public local
}

class PADnoteHarmonicProfile {: {public Fl_Box}
} {
  Function {PADnoteHarmonicProfile(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
    code {pars=NULL;} {}
  }
  Function {init(PADnoteParameters *pars)} {} {
    code {this->pars=pars;} {}
  }
  Function {draw()} {} {
    code {//
        int ox = x(), oy = y(), lx =w (), ly = h() - 1;
        if (!visible()) return;

        std::vector<float> profile = pars->buildProfile(lx);
        float realbw = pars->calcProfileBandwith(profile);

        bool active = active_r();
        float scale =  lx / 430.0f;
        int rbw = int(realbw * (lx - 1.0) / 2.0);
        fl_color(pad_equiv_back);

        //draw the equivalent bandwidth
        if (active)
        {
            fl_line_style(0, int(1 * scale));
            for (int i = lx / 2 - rbw; i < (lx / 2 + rbw); i++)
                fl_line(ox+i, oy, ox+i, oy + ly - 1);
        }
        else
            fl_rectf(ox, oy, lx, ly);

        fl_color(pad_grid);
        for (int i = 1; i < 10; i++)
        {
            int kx = (int)(lx / 10.0 * i);
            fl_line(ox + kx, oy, ox + kx, oy + ly - 1);
        }
        for (int i = 1; i < 5; i++)
        {
            int ky = (int)(ly / 5.0 * i);
            fl_line(ox, oy + ly - ky, ox + lx, oy + ly - ky - 1);
        }

        int step = 2 * scale;
        fl_line_style(0, step);
        fl_color(pad_grid_centre);
        fl_line(ox + lx / 2, oy, ox + lx / 2, oy + ly);

        //draw the graph
        if (active)
        {
            for (int i = 0; i < lx; i += step)
            {
                int val = int((ly - 2) * profile[i]);
                fl_color(pad_prof_fill);
                if (val != 0)
                    fl_line(ox + i, oy + ly, ox + i, oy + ly - val);
            }
        }

        int oi = 0;
        float ov = 0;

        for (int i = 0; i < lx; i++)
        {
            int ni = ox + i;
            float nv = (ly - 2) * profile[i];

            if (active)
                fl_color(pad_prof_line);
            else
                fl_color(pad_prof_inactive);
            if (i > 0)
                fl_line(oi, oy + ly - ov, ni, oy + ly - nv);
            oi = ni;
            ov = nv;
        }

        if (active)
            fl_color(pad_prof_band);
        else
            fl_color(pad_prof_inactive);
        fl_line(ox + lx / 2 - rbw, oy, ox + lx / 2 - rbw, oy + ly - 1);
        fl_line(ox + lx / 2 + rbw, oy, ox + lx / 2 + rbw, oy + ly - 1);
        fl_line_style(0, 1);} {}
  }
  decl {PADnoteParameters *pars;} {public local
  }
}

class PADnoteOvertonePosition {: {public Fl_Box}
} {
  Function {PADnoteOvertonePosition(int x,int y, int w, int h, const char *label=0):Fl_Box(x,y,w,h,label)} {} {
    code {pars=NULL;} {}
  }
  Function {init(PADnoteParameters *pars)} {} {
    code {synth = & pars->getSynthEngine();
this->pars=pars;} {}
  }
  Function {draw()} {} {
    code {//
        if (!visible()) return;
        const int maxdb = 60;
        int ox = x(), oy = y(), lx = w(), ly = h();
        const int maxharmonic = 64;
        float scale = lx / 525;
        fl_line_style(0, 1 * scale);
        for (int i = 1; i < maxharmonic; i++)
        {
            fl_color(pad_grid);
            if (i % 10 == 0)
                fl_color(46);
            int kx = (int)(lx / (float)maxharmonic * i);
            fl_line(ox + kx, oy, ox + kx, oy + ly);
        }

        int n = synth->halfoscilsize;
        float spc[n];
        for (int i = 0; i < n; i++)
            spc[i] = 0.0;
        pars->oscilgen->getOscilSpectrumIntensities(n, spc);

        //normalize
        float max = 0;
        for (int i = 0; i < n; i++)
        {
            float x = fabsf(spc[i]);
            if (max < x)
                max=x;
        }
        if (max < 0.000001)
            max = 1.0;
        max = max * 1.05;

        float spectrum[lx];
        for (int i = 0; i < lx; i++)
            spectrum[i] = 0;

        for (int i = 0; i+1 < n; i++)
        {
            float nhr = pars->calcHarmonicPositionFactor(i);
            int kx = (int)(lx / (float)maxharmonic * nhr);
            if (kx < 0 || kx >= lx)
                continue;
            spectrum[kx] = spc[i] / max + 1e-9;
        }

        fl_color(pad_harmonic_line);

        if (pars->Pmode == 2)
        {
            int old = 0;
            for (int i = 1; i < lx; i++)
            {
                if ((spectrum[i] > 1e-10) || (i == (lx - 1)))
                {
                    int delta = i - old;
                    float val1 = spectrum[old];
                    float val2 = spectrum[i];
                    float idelta = 1.0 / delta;
                    for (int j = 0; j < delta; j++)
                    {
                        float x = idelta * j;
                        spectrum[old + j] = val1 * (1.0 - x) + val2 * x;
                    }
                    old = i;
                }
            }
        }
        fl_line_style(0, 2 * scale);
        for (int i = 0; i < lx; i++)
        {
            float x = spectrum[i];
            if (x > decibel(-maxdb))
                x = asDecibel(x) / maxdb + 1;
            else
                continue;
            int yy = (int)(x * ly);
            fl_line(ox+i,oy+ly-1-yy,ox+i,oy+ly-1);
        }
        fl_line_style(0, 1);} {}
  }
  decl {PADnoteParameters *pars;} {public local
  }
  decl {SynthEngine *synth;} {private local
  }
}

class PADnoteUI {: {public PresetsUI_}
} {
  Function {make_window()} {} {
    comment {randompan MUST be after panwidth} {in_source in_header
    }
    Fl_Window padnotewindow {
      label {PAD synth Parameters}
      callback {padClose->do_callback();}
      xywh {464 151 580 440} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("PadSynth"), npart, TOPLEVEL::windowTitle, kititem)).c_str());}
      code1 {padDW = o->w(); padDH = o->h();}
      code2 {padnotewindow->size_range(padDW, padDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Tabs {} {
        callback {//
            if (o->value() != harmonicstructuregroup)
            {
                applybutton->hide();
            }
            else
            {
                applybutton->show();}}
        xywh {0 0 580 405} labelcolor 64
      } {
        Fl_Group harmonicstructuregroup {
          label {Harmonic &Structure}
          xywh {0 20 580 385} box ENGRAVED_FRAME labelsize 12 labelcolor 64
        } {
          Fl_Group bwprofilegroup {
            xywh {5 25 90 270} box ENGRAVED_FRAME labelcolor 64
            code0 {if (pars->Pmode!=0) o->deactivate();}
          } {
            Fl_Choice hpbasetype {
              label {Base Type}
              callback {//
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::baseType, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Base shape used to widen and spread each harmonic.} xywh {15 42 75 15} down_box BORDER_BOX labelsize 10 labelcolor 64 align 1 textfont 1 textsize 10 textcolor 64
              code0 {o->add("Gauss");o->add("Square");o->add("DoubleExp");}
              code1 {o->value(pars->PProfile.base.type);}
            } {}
            Fl_Dial hpbasepar1 {
              label Width
              callback {//
              o->selection_color(setKnob(o->value(),80));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::baseWidth, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Spread of a single peak within the profile.} xywh {20 72 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PProfile.base.pwidth);}
              code1 {o->selection_color(setKnob(o->value(),80));}
              class WidgetPDial
            }
            Fl_Dial hpfreqmult {
              label Repeat
              callback {//
              o->selection_color(setKnob(o->value(),0));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::frequencyMultiplier, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Repeat the same base shape multiple times in the generated profile.} xywh {55 72 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PProfile.freqmult);}
              code1 {o->selection_color(setKnob(o->value(),0));}
              class WidgetPDial
            }
            Fl_Dial hpmpar1 {
              label Str
              callback {//
              o->selection_color(setKnob(o->value(),0));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::modulatorStretch, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Modulate and spread the base shape} xywh {15 112 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PProfile.modulator.pstretch);}
              code1 {o->selection_color(setKnob(o->value(),0));}
              class WidgetPDial
            }
            Fl_Dial hpmfreq {
              label Freq
              callback {//
              o->selection_color(setKnob(o->value(),30));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::modulatorFrequency, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Frequency of peaks within modulation of base shape.} xywh {40 112 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PProfile.modulator.freq);}
              code1 {o->selection_color(setKnob(o->value(),30));}
              class WidgetPDial
            }
            Fl_Dial hpwidth {
              label Scale
              callback {//
              o->selection_color(setKnob(o->value(),127));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::size, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Squeeze or stretch the profile as a whole. Note: effective only when Autoscale is off} xywh {65 112 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PProfile.width);}
              code1 {o->selection_color(setKnob(o->value(),127));}
              class WidgetPDial
            }
            Fl_Choice hponehalf {
              label Profile
              callback {//
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::harmonicSidebands, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Which part of the profile to use: Full, or only the upper or lower half.} xywh {10 147 80 15} down_box BORDER_BOX labelsize 10 labelcolor 64 align 1 textfont 1 textsize 10 textcolor 64
              code0 {o->add("Full");o->add("Upper Half");o->add("Lower Half");}
              code1 {o->value(pars->PProfile.onehalf);}
            } {}
            Fl_Group ampgroup {
              xywh {10 164 80 105} box BORDER_BOX labelcolor 64
            } {
              Fl_Choice hpampmode {
                label AmpMode
                callback {//
                send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::amplitudeMode, o->value(), TOPLEVEL::type::Integer);}
                tooltip {How to combine secondary modulation with the profile: Sum: XFade, Mult: Filter, Div1: profile/modulator, Div2: modulator/profile} xywh {15 209 70 15} down_box BORDER_BOX labelsize 10 labelcolor 64 align 1 textfont 1 textsize 10 textcolor 64
                code0 {o->add("Sum");o->add("Mult");o->add("Div1");o->add("Div2");}
                code1 {o->value(pars->PProfile.amp.mode);}
              } {}
              Fl_Dial hpamppar1 {
                label Par1
                callback {//
                o->selection_color(setKnob(o->value(),80));
                send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::spectralWidth, o->value(), TOPLEVEL::type::Integer);}
                tooltip {Squeeze or spread the secondary modulating shape.} xywh {15 239 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
                code0 {o->value(pars->PProfile.amp.par1);}
                code1 {o->selection_color(setKnob(o->value(),80));}
                class WidgetPDial
              }
              Fl_Dial hpamppar2 {
                label Par2
                callback {//
                o->selection_color(setKnob(o->value(),64));
                send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::spectralAmplitude, o->value(), TOPLEVEL::type::Integer);}
                tooltip {Degree to fade or combine secondary modulation with the harmonic profile.} xywh {55 239 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
                code0 {o->value(pars->PProfile.amp.par2);}
                code1 {o->selection_color(setKnob(o->value(),64));}
                class WidgetPDial
              }
            }
            Fl_Choice hpamptype {
              label AmpMultiplier
              callback {//
                send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::amplitudeMultiplier, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Apply a secondary amplitude modulation on top of the profile built thus far.} xywh {15 179 70 15} down_box BORDER_BOX labelsize 10 labelcolor 64 align 5 textfont 1 textsize 10 textcolor 64
              code0 {o->add("Off");o->add("Gauss");o->add("Sine");o->add("Flat");}
              code1 {o->value(pars->PProfile.amp.type);}
              code2 {if (_SYS_::F2B(o->value())) ampgroup->activate(); else ampgroup->deactivate();}
            } {}
            Fl_Check_Button hpautoscale {
              label Autoscale
              callback {//
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::autoscale, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Automatically stretch the profile, so that all shapes yield the same perceptual blurring effect.} xywh {10 274 74 15} down_box DOWN_BOX selection_color 64 labelsize 11 labelcolor 64
              code0 {o->value(pars->PProfile.autoscale);}
              class Fl_Check_Button2
            }
          }
          Fl_Group {} {
            xywh {100 155 315 135} box THIN_DOWN_BOX color 57 labelcolor 49 align 6
            code0 {osc=new Oscilloscope(o->x(),o->y(),o->w(),o->h(), 130,"");}
            code1 {osc->init(pars->oscilgen.get(), synth);}
          } {}
          Fl_Box cbwidget {
            label {Harmonic Content}
            callback {//
            overtonepos->redraw();}
            xywh {125 135 205 20} labelsize 12 labelcolor 64 align 16
          }
          Fl_Button resonance {
            label Resonance
            callback {//
            resui->resonancewindow->redraw();
            resui->Show();
            resui->applybutton->show();
            if ((Fl::event_button() == 3))
                padnotewindow->hide();}
            xywh {451 246 85 20} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 12 labelcolor 64
          }
          Fl_Button waveform {
            label Waveform
            callback {//
            if (oscui!=NULL)
                delete (oscui);
            lastWaveW = 0;
            bool forPAD = true;
            oscui = new OscilEditor(pars->POscil.get(), osc, cbwidget, applybutton, synth, npart, kititem, PART::engine::padSynth, forPAD);
            if ((Fl::event_button() == 3))
                padnotewindow->hide();}
            tooltip {Right click: also close this} xywh {451 272 85 20} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 12 labelcolor 64
          }
          Fl_Dial bwdial {
            label BandWidth
            callback {//
            o->selection_color(setKnob(o->value(),500));
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::bandwidth, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Effective Bandwidth of the harmonic profile in cents: Transition from the precise waveform to a sonic cloud.} xywh {20 307 35 35} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 1000 step 1
            code0 {o->value(pars->Pbandwidth);}
            code1 {if (pars->Pmode!=0) o->deactivate();}
            code2 {o->setValueType(VC_BandWidth);}
            code3 {o->selection_color(setKnob(o->value(),500));}
            class WidgetPDial
          }
          Fl_Value_Output bwcents {
            label cents
            xywh {60 320 55 15} labelsize 10 labelcolor 64 align 5 maximum 10000 textsize 11 textcolor 64
            code0 {o->step(0.1, 1);}
            code1 {o->value(pars->getBandwithInCent());}
            code2 {if (pars->Pmode!=0) o->deactivate();}
          }
          Fl_Choice bwscale {
            label {Bandwidth Scale}
            callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::bandwidthScale, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Adjust Bandwidth with the increasing frequency of each harmonic. Normal: proportional, EqualHz: constant, InvHalf: reversed decreasing...} xywh {125 315 80 20} down_box BORDER_BOX selection_color 64 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 11 textcolor 64
            code0 {o->add("Normal");o->add("EqualHz");o->add("Quarter");o->add("Half");o->add("75%");o->add("150%");o->add("Double");o->add("Inv.Half");}
            code1 {o->value(pars->Pbwscale);}
            code2 {if (pars->Pmode!=0) o->deactivate();}
          } {}
          Fl_Choice spectrummode {
            label {Spectrum Mode}
            callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::spectrumMode, o->value(), TOPLEVEL::type::Integer);}
            tooltip {How to generate the spectrum: Bandwidth: widen each harmonic by a profile, Discrete: no blurring, similar to AddSynth, Continuous: connect outline of all harmonics into a continuous noisy distribution.} xywh {265 315 90 20} down_box BORDER_BOX selection_color 64 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 11 textcolor 64
            code0 {o->add("Bandwidth");o->add("Discrete");o->add("Continuous");}
            code1 {o->value(pars->Pmode);}
          } {}
          Fl_Group hrgroup {
            xywh {360 296 215 50} box ENGRAVED_FRAME
          } {
            Fl_Dial hrpospar1 {
              label Par1
              callback {//
              o->selection_color(setKnob(o->value(),64));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::overtoneParameter1, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Spread upper harmonics according to the 'OvertonesPosition' type.} xywh {470 315 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 255 step 1 deactivate
              code0 {o->value(pars->Phrpos.par1);}
              code1 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Dial hrpospar2 {
              label Par2
              callback {//
              o->selection_color(setKnob(o->value(),64));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::overtoneParameter2, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Further variation on the harmonics spread: threshold (ShiftU/L), exponent (Power), frequency (Sine).} xywh {505 315 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 255 step 1 deactivate
              code0 {o->value(pars->Phrpos.par2);}
              code1 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Dial hrpospar3 {
              label ForceH
              callback {//
              o->selection_color(setKnob(o->value(),0));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::overtoneForceHarmonics, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Increasingly force each partial towards the next regular harmonic position, reduce the noisiness.} xywh {540 315 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 255 step 1 deactivate
              code0 {o->value(pars->Phrpos.par3);}
              code1 {o->setValueType(VC_percent255);}
              code2 {o->selection_color(setKnob(o->value(),0));}
              class WidgetPDial
            }
          }
          Fl_Choice hrpostype {
            label OvertonesPosition
            callback {//
                  send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::overtonePosition, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Shift overtones to non-harmonic positions, to create metallic and noisy flavours.} xywh {370 315 85 20} down_box BORDER_BOX selection_color 64 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 11 textcolor 64
            code0 {o->add("Harmonic");o->add("ShiftU");o->add("ShiftL");o->add("PowerU");o->add("PowerL");o->add("Sine");o->add("Power");o->add("Shift");}
            code1 {o->value(pars->Phrpos.type);}
            code2 {if (int(o->value() > 0) && int(o->value() < 7)) hrpospar2->activate(); else hrpospar2->deactivate();}
          } {}
          Fl_Group overtonepos {
            xywh {5 350 570 45} box FLAT_BOX color 254 labelcolor 49
            code0 {PADnoteOvertonePosition *opui=new PADnoteOvertonePosition(o->x(),o->y(),o->w(),o->h(),"");}
            code1 {opui->init(pars);}
          } {}
          Fl_Choice qbasenote {
            label base
            callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::harmonicBase, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Note value for the lowest wavetable generated.} xywh {419 155 48 20} down_box BORDER_BOX selection_color 64 labelsize 11 labelcolor 64 align 5 textfont 1 textsize 12 textcolor 64
            code0 {o->add("C-2");o->add("G-2");o->add("C-3");o->add("G-3");o->add("C-4");o->add("G-4");o->add("C-5");o->add("G-5");o->add("G-6");}
            code1 {o->value(pars->Pquality.basenote);}
          } {}
          Fl_Choice qsmpoct {
            label {smp/oct}
            callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::samplesPerOctave, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Number of wavetables generated within each octave.} xywh {472 155 48 20} down_box BORDER_BOX selection_color 64 labelsize 11 labelcolor 64 align 5 textfont 1 textsize 12 textcolor 64
            code0 {o->add("0.5");o->add("1");o->add("2");o->add("3");o->add("4");o->add("6");o->add("12");}
            code1 {o->value(pars->Pquality.smpoct);}
          } {}
          Fl_Choice qoct {
            label {no.oct}
            callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::numberOfOctaves, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Number of octaves to cover with dedicated wavetables; other note values will sample up/down.} xywh {525 155 50 20} down_box BORDER_BOX selection_color 64 labelsize 11 labelcolor 64 align 5 textfont 1 textsize 12 textcolor 64
            code0 {o->add("1");o->add("2");o->add("3");o->add("4");o->add("5");o->add("6");o->add("7");o->add("8");}
            code1 {o->value(pars->Pquality.oct);}
          } {}
          Fl_Box sampleFrame {
            xywh {418 178 157 64} box EMBOSSED_FRAME labelcolor 64
          }
          Fl_Choice qsamplesize {
            label {Sample Size}
            callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::sampleSize, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Size/Resolution of the generated wavetable(s). 128k -> 2.6sec, 1M -> 21sec until repetition of patterns.} xywh {425 193 94 20} down_box BORDER_BOX selection_color 64 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 11 textcolor 64
            code0 {o->add("16k (Tiny)");o->add("32k");o->add("64k (Small)");o->add("128k");o->add("256k");o->add("512k");o->add("1M (Big)");}
            code1 {o->value(pars->Pquality.samplesize);}
          } {}
          Fl_Dial xFadeDial {
            label Crossfade
            callback {//
            o->selection_color(setKnob(int(o->value()),2301));
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::xFadeUpdate, logDial2millisec(o->value()), TOPLEVEL::type::Integer);}
            tooltip {cross fade after building new Wavetable} xywh {530 201 32 32} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 minimum -1 maximum 4301 step 1
            code0 {int dialSetting = millisec2logDial(pars->PxFadeUpdate);
                   o->value(dialSetting);}
            code1 {o->selection_color(setKnob(o->value(),2301));}
            code2 {o->setValueType(VC_XFadeUpdate);}
            class WidgetPDial
          }
          Fl_Button randWalkUI {
            label Retrigger
            callback {//
              show_randWalk();
              if ((Fl::event_button() == 3))
                  padnotewindow->hide();}
            xywh {425 217 94 20} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 12 labelcolor 64
          }
          Fl_Group hprofile {
            xywh {100 45 475 90} box FLAT_BOX color 254 selection_color 218 labelcolor 63
            code0 {PADnoteHarmonicProfile *hpui=new PADnoteHarmonicProfile(o->x(),o->y(),o->w(),o->h(),"");}
            code1 {hpui->init(pars);}
            code2 {if (pars->Pmode!=0) { o->deactivate(); o->color(48);};}
          } {}
          Fl_Box harmonicprofile {
            label {Profile of One Harmonic (Frequency Distribution)}
            xywh {160 25 315 20} labelsize 12 labelcolor 64
          }
        }
        Fl_Group envelopes {
          label {Envelopes and &LFOs}
          xywh {0 20 580 385} box GTK_THIN_UP_BOX labelsize 12 labelcolor 64 hide
        } {
          Fl_Box {} {
            xywh {10 27 275 68} box PLASTIC_UP_BOX color 223 labelcolor 64
          }
          Fl_Group ampgrp {
            xywh {5 25 285 250} box THIN_UP_FRAME labelfont 1 labelsize 11 labelcolor 64 align 17
          } {
            Fl_Dial volume {
              label Volume
              callback {//
              o->selection_color(setKnob(o->value(),90));
              send_data(0, PADSYNTH::control::volume, o->value(), TOPLEVEL::type::Integer);}
              tooltip Volume xywh {30 43 34 34} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 127 step 1
              code0 {o->setValueType(VC_InstrumentVolume);}
              code1 {o->value(pars->PVolume);}
              code2 {o->selection_color(setKnob(o->value(),90));}
              class WidgetPDial
            }
            Fl_Dial vsns {
              label {Vel Sens}
              callback {//
              o->selection_color(setKnob(o->value(),64));
              send_data(0, PADSYNTH::control::velocitySense, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Velocity Sensing Function (rightmost to disable)} xywh {85 43 34 34} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 127 step 1
              code0 {o->value(pars->PAmpVelocityScaleFunction);}
              code1 {o->setValueType(VC_AmpVelocitySense);}
              code2 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Dial pan {
              label Pan
              callback {//
              o->selection_color(setKnob(o->value(),64));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::panning, o->value(), TOPLEVEL::type::Integer);}
              tooltip Panning xywh {155 43 34 34} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 127 step 1
              code0 {o->setValueType(VC_PanningStd);}
              code1 {o->value(pars->PPanning);}
              code2 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Dial panwidth {
              label Width
              callback {//
        o->selection_color(setKnob(o->value(),63));
        send_data(0, PADSYNTH::control::randomWidth, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Random width} xywh {235 43 35 35} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 63 step 1 value 63
              code0 {o->setValueType(VC_PanningRandom);}
              code1 {o->value(pars->PWidth);}
              code2 {o->selection_color(setKnob(o->value(),63));}
              class WidgetPDial
            }
            Fl_Check_Button randompan {
              label Rand
              callback {//
        int tmp = o->value();
        if (tmp == 0)
            panwidth->deactivate();
        else
            panwidth->activate();
        send_data(0, PADSYNTH::control::enableRandomPan, tmp, TOPLEVEL::type::Integer);}
              tooltip {Enable random panning} xywh {205 53 15 15} down_box DOWN_BOX color 48 selection_color 64 labelsize 11 labelcolor 64 align 1
              code0 {o->value(pars->PRandom);}
              code1 {if (o->value() == 0) panwidth->deactivate(); else panwidth->activate();}
              class Fl_Check_Button2
            }
            Fl_Check_Button stereo {
              label { Stereo}
              callback {//
              pars->PStereo =(o->value()) ? true : false; hprofile->redraw();
              send_data(0, PADSYNTH::control::stereo, o->value(), TOPLEVEL::type::Integer);}
              xywh {16 249 61 15} down_box DOWN_BOX selection_color 64 labelfont 3 labelsize 11 labelcolor 226
              code0 {o->value(pars->PStereo);}
              class Fl_Check_Button2
            }
            Fl_Dial dpop {
              label {D.Pop}
              callback {//
              o->selection_color(setKnob(o->value(),20));
              send_data(0, PADSYNTH::control::dePop, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Pop Suppression} xywh {130 247 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->Fadein_adjustment);}
              code1 {o->selection_color(setKnob(o->value(),20));}
              class WidgetPDial
            }
            Fl_Dial pstr {
              label {P.Str.}
              callback {//
              o->selection_color(setKnob(o->value(),0));
              send_data(0, PADSYNTH::control::punchStrength, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Punch Strength} xywh {170 247 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PPunchStrength);}
              code1 {o->selection_color(setKnob(o->value(),0));}
              class WidgetPDial
            }
            Fl_Dial pt {
              label {P.t.}
              callback {//
              o->selection_color(setKnob(o->value(),60));
              send_data(0, PADSYNTH::control::punchDuration, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Punch Time (duration)} xywh {200 247 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PPunchTime);}
              code1 {o->selection_color(setKnob(o->value(),60));}
              class WidgetPDial
            }
            Fl_Dial pstc {
              label {P.Stc.}
              callback {//
              o->selection_color(setKnob(o->value(),64));
              send_data(0, PADSYNTH::control::punchStretch, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Punch Stretch} xywh {230 247 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PPunchStretch);}
              code1 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Dial pvel {
              label {P.Vel.}
              callback {//
              o->selection_color(setKnob(o->value(),72));
              send_data(0, PADSYNTH::control::punchVelocity, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Punch Velocity Sensing} xywh {260 247 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(pars->PPunchVelocitySensing);}
              code1 {o->selection_color(setKnob(o->value(),72));}
              class WidgetPDial
            }
            Fl_Group ampenv {
              label {Yoshimi : PadSynth - Amplitude Envelope}
              xywh {10 95 275 70} box FLAT_BOX color 51 labelsize 12 align 144
              code0 {o->init(pars->AmpEnvelope.get(), npart, kititem, PART::engine::padSynth, 0);}
              class EnvelopeUI
            } {}
            Fl_Group amplfo {
              label {Amplitude LFO     }
              xywh {10 165 275 70} box FLAT_BOX color 47 labelfont 1 labelsize 12 align 144
              code0 {o->init(synth, npart, kititem, PART::engine::padSynth, TOPLEVEL::insertType::amplitude);}
              class LFOUI
            } {}
            Fl_Box {} {
              xywh {135 42 4 46} box THIN_DOWN_FRAME
            }
            Fl_Box amplabel {
              label AMPLITUDE
              xywh {124 28 35 17} labelfont 1 labelsize 11 labelcolor 64
            }
          }
          Fl_Group filtergrp {
            xywh {290 25 285 250} box THIN_UP_BOX labelfont 1 labelsize 11 labelcolor 64 align 17
          } {
            Fl_Group filterenv {
              label {Yoshimi : PadSynth - Filter Envelope}
              xywh {295 130 275 70} box FLAT_BOX color 51 labelsize 12 align 144
              code0 {o->init(pars->FilterEnvelope.get(), npart, kititem, PART::engine::padSynth, 2);}
              class EnvelopeUI
            } {}
            Fl_Group filterlfo {
              label {Filter LFO     }
              xywh {295 200 275 70} box FLAT_BOX color 47 labelfont 1 labelsize 12 align 144
              code0 {o->init(synth, npart, kititem, PART::engine::padSynth, TOPLEVEL::insertType::filter);}
              class LFOUI
            } {}
            Fl_Group filterui {
              label {Yoshimi : PadSynth - Filter}
              xywh {295 55 275 75} box FLAT_BOX color 50 labelsize 12 align 144
              code0 {o->init(pars->GlobalFilter.get(), &pars->PFilterVelocityScale,&pars->PFilterVelocityScaleFunction, npart, kititem, PART::engine::padSynth);}
              class FilterUI
            } {}
            Fl_Box filterlabel {
              label FILTER
              xywh {416 29 35 17} labelfont 1 labelsize 11
            }
          }
          Fl_Group frequencygrp {
            label FREQUENCY
            xywh {5 275 570 125} box THIN_UP_BOX labelfont 1 labelsize 11 labelcolor 64 align 17
          } {
            Fl_Group freqenv {
              label {Yoshimi : PadSynth - Frequency Envelope}
              xywh {10 325 205 70} box FLAT_BOX color 51 labelsize 12 align 144
              code0 {o->init(pars->FreqEnvelope.get(), npart, kititem, PART::engine::padSynth, 1);}
              class EnvelopeUI
            } {}
            Fl_Group freqlfo {
              label {Frequency LFO     }
              xywh {215 325 275 70} box FLAT_BOX color 47 labelsize 12 align 144
              code0 {o->init(synth, npart, kititem, PART::engine::padSynth, TOPLEVEL::insertType::frequency);}
              class LFOUI
            } {}
            Fl_Dial bend {
              label Bend
              callback {//
              o->selection_color(setKnob(o->value(),88));
              send_data(0, PADSYNTH::control::pitchBendAdjustment, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Pitch bend range scaling} xywh {80 280 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 8 maximum 127 step 1
              code0 {o->value(pars->PBendAdjust);}
              code1 {o->setValueType(VC_PitchBend);}
              code2 {o->selection_color(setKnob(o->value(),88));}
              class WidgetPDial
            }
            Fl_Dial offset {
              label Offset
              callback {//
              o->selection_color(setKnob(o->value(),64));
              send_data(0, PADSYNTH::control::pitchBendOffset, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Offset of the frequency in Hz.} xywh {140 280 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 8 maximum 127 step 1
              code0 {o->value(pars->POffsetHz);}
              code1 {o->setValueType(VC_FreqOffsetHz);}
              code2 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Check_Button hz440 {
              label 440Hz
              callback {//
              int x = (int) o->value();
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::baseFrequencyAs440Hz, x, TOPLEVEL::type::Integer);}
              tooltip {set the base frequency to 440Hz} xywh {410 284 50 15} down_box DOWN_BOX selection_color 64 labelfont 1 labelsize 10 labelcolor 64
              code0 {o->value(pars->Pfixedfreq);}
              class Fl_Check_Button2
            }
            Fl_Dial fixedfreqetdial {
              label {Eq.T.}
              callback {//
              o->selection_color(setKnob(o->value(),0));
              send_data(0, PADSYNTH::control::equalTemperVariation, o->value(), TOPLEVEL::type::Integer);}
              tooltip {How the frequency varies according to the keyboard (leftmost for fixed frequency)} xywh {465 280 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 8 maximum 127 step 1
              code0 {o->value(pars->PfixedfreqET);}
              code1 {if (pars->Pfixedfreq==0) o->deactivate();}
              code2 {o->setValueType(VC_FixedFreqET);}
              code3 {o->selection_color(setKnob(o->value(),0));}
              class WidgetPDial
            }
            Fl_Slider detune {
              callback {//
              o->selection_color(setSlider(o->value(),0));
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::detuneFrequency, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Fine Detune (cents)} xywh {57 305 433 15} type {Horz Knob} box THIN_DOWN_BOX labelcolor 64 minimum -8192 maximum 8191 step 1
              code0 {o->value(pars->PDetune-8192);}
              code1 {o->selection_color(setSlider(o->value(),0));}
              class mwheel_slider_rev
            }
            Fl_Value_Output detunevalueoutput {
              label Detune
              callback {o->value(getDetune(pars->PDetuneType,0,pars->PDetune));}
              xywh {12 305 45 15} labelsize 10 labelcolor 64 align 5 minimum -5000 maximum 5000 textfont 1 textsize 10 textcolor 64
              code0 {o->step(0.01, 1);}
              code1 {o->value(getDetune(pars->PDetuneType,0,pars->PDetune));}
            }
            Fl_Text_Display octavetext {
              label Octave
              xywh {511 305 50 11} box NO_BOX labelfont 3 labelsize 10 labelcolor 226
            }
            Fl_Counter octave {
              callback {//
              send_data(0, PADSYNTH::control::octave, o->value(), TOPLEVEL::type::Integer);}
              tooltip Octave xywh {504 305 62 15} type Simple selection_color 49 labelsize 10 labelcolor 64 align 1 minimum -8 maximum 7 step 1 textfont 1 textsize 11 textcolor 64
              code0 {int k=pars->PCoarseDetune/1024;}
              code1 {if (k>=8) k-=16;}
              code2 {o->value(k);}
            }
            Fl_Choice detunetype {
              label {Detune Type}
              callback {//
              send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::detuneType, o->value() + 1, TOPLEVEL::type::Integer);}
              xywh {495 342 75 15} down_box BORDER_BOX selection_color 64 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 10 textcolor 64
              code0 {o->add("L35cents");o->add("L10cents");o->add("E100cents");o->add("E1200cents");}
              code1 {o->value(pars->PDetuneType - 1);}
            } {}
            Fl_Counter coarsedet {
              label {Coarse det.}
              callback {//
              send_data(0, PADSYNTH::control::coarseDetune, o->value(), TOPLEVEL::type::Integer);}
              tooltip {Coarse Detune} xywh {495 375 76 15} selection_color 64 labelsize 10 labelcolor 64 align 5 minimum -64 maximum 63 step 1 textfont 1 textsize 11 textcolor 64
              code0 {int k=pars->PCoarseDetune%1024;}
              code1 {if (k>=512) k-=1024;}
              code2 {o->value(k);}
              code3 {o->lstep(10);}
            }
          }
        }
      }
      Fl_Button padExport {
        label Export
        callback {//
        string filename = setfiler(synth,"", "PadSynth", true, TOPLEVEL::XML::PadSample);
        if (filename.empty())
            return;
        send_data(TOPLEVEL::action::forceUpdate, MAIN::control::exportPadSynthSamples, 0, TOPLEVEL::type::Integer, npart, textMsgBuffer.push(filename));}
        tooltip {Export samples as wav file} xywh {15 410 123 24} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 12 labelcolor 64 align 128
      }
      Fl_Button applybutton {
        label {Apply Changes}
        callback {//
        send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::applyChanges, 1, TOPLEVEL::type::Integer);}
        tooltip {Rebuild wavetable to render the currently defined spectrum and line shape; also re-randomise phases} xywh {242 412 128 22} box GTK_THIN_UP_BOX color 82 labelfont 1 labelsize 12 labelcolor 64
      }
      Fl_Button padCopy {
        label C
        callback {//
    synth->getGuiMaster()->getPresetsUi()->Ucopy(npart, kititem, PART::engine::padSynth);}
        xywh {415 414 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 197
      }
      Fl_Button padPaste {
        label P
        callback {//
  synth->getGuiMaster()->getPresetsUi()->Upaste(npart, kititem, PART::engine::padSynth);}
        xywh {449 414 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 197
      }
      Fl_Button padClose {
        label &Close
        callback {//
        saveWin(synth, padnotewindow->w(), padnotewindow->h(), padnotewindow->x(), padnotewindow->y(), false, "PadSynth");
        padSeen = false;
        resui->resonancewindow->hide();
        if (randWalkWindow)
            randWalkWindow->hide();
        padnotewindow->hide();
        if ((Fl::event_button() == 3))
        {
            if (synth->getGuiMaster()->partui->partKitOn)
                synth->getGuiMaster()->partui->instrumentkitlist->show();
            else
                synth->getGuiMaster()->partui->instrumenteditwindow->show();
        }}
        tooltip {Right click: also reopen previous} xywh {505 410 61 24} box THIN_UP_BOX color 196 labelfont 1 labelsize 12 labelcolor 64
      }
    }
  }
  Function {make_randWalkWindow()} {} {
    Fl_Window randWalkWindow {
      label {Yoshimi : PadSynth - Random Walk}
      xywh {858 154 240 155} type Double hide resizable
      code0 {randDW = o->w(); randDH = o->h();}
      code1 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Random Walk"), npart, TOPLEVEL::windowTitle, kititem)).c_str());}
      code2 {o->size_range(randDW, randDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Group randomProp {
        xywh {0 0 240 154}
      } {
        Fl_Box plinth {
          xywh {6 6 58 58} box UP_BOX color 48
        }
        Fl_Dial rebuildTrigger {
          label Retrigger
          callback {//
            int dialSetting = o->value();
            if (dialSetting >= 0)
                dialSetting += 2300;
            // remove a socket of 200ms from the dial setting, i.e. the editable time in the UI starts > 200ms
            // smaller values would be pointless and overload the system. (60sec = 4779, 200ms = 2300, thus max = 4779-2300 = 2479)
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::rebuildTrigger, logDial2millisec(dialSetting), TOPLEVEL::type::Integer);}
          tooltip {Trigger rebuild of PAD Wavetable after generating this amount of sample time; possibly randomise the other parameters on each rebuild. WARNING: expensive!} xywh {20 25 30 30} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 minimum -1 maximum 2479 step 1
          code0 {//
            int dialSetting = millisec2logDial(pars->PrebuildTrigger);
            if (dialSetting >= 2300)
                 dialSetting -= 2300;
            else dialSetting = -1;
            o->value(dialSetting);}
          code2 {o->setValueType(VC_Retrigger);}
          class WidgetPDial
        }
        Fl_Dial randWalkDetune {
          label Detune
          callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::randWalkDetune, o->value(), TOPLEVEL::type::Integer);}
          tooltip {Let the voice detuning perform a random walk on each wavetable rebuild, within this spread..} xywh {100 25 30 30} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(pars->PrandWalkDetune);}
          code2 {o->setValueType(VC_RandWalkSpread);}
          class WidgetPDial
        }
        Fl_Dial randWalkFilterFreq {
          label {Filter Freq}
          callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::randWalkFilterFreq, o->value(), TOPLEVEL::type::Integer);}
          tooltip {Filter cutoff freq random walk on wavetable rebuild, within this spread..} xywh {180 25 30 30} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(pars->PrandWalkFilterFreq);}
          code2 {o->setValueType(VC_RandWalkSpread);}
          class WidgetPDial
        }
        Fl_Dial randWalkBandwidth {
          label Bandwidth
          callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::randWalkBandwidth, o->value(), TOPLEVEL::type::Integer);}
          tooltip {Bandwidth random walk on wavetable rebuild, within this spread..} xywh {20 85 30 30} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(pars->PrandWalkBandwidth);}
          code2 {o->setValueType(VC_RandWalkSpread);}
          class WidgetPDial
        }
        Fl_Dial randWalkProfileWidth {
          label {Line Width}
          callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::randWalkProfileWidth, o->value(), TOPLEVEL::type::Integer);}
          tooltip {Profile width parameter random walk on wavetable rebuild, within this spread..} xywh {100 85 30 30} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(pars->PrandWalkProfileWidth);}
          code2 {o->setValueType(VC_RandWalkSpread);}
          class WidgetPDial
        }
        Fl_Dial randWalkProfileStretch {
          label {Profile Stretch}
          callback {//
            send_data(TOPLEVEL::action::forceUpdate, PADSYNTH::control::randWalkProfileStretch, o->value(), TOPLEVEL::type::Integer);}
          tooltip {Profile stretch parameter random walk on wavetable rebuild, within this spread..} xywh {180 85 30 30} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(pars->PrandWalkProfileStretch);}
          code2 {o->setValueType(VC_RandWalkSpread);}
          class WidgetPDial
        }
        Fl_Button randClose {
          label Close
          callback {//
              if (randSeen)
                  saveWin(synth, randWalkWindow->w(), randWalkWindow->h(), randWalkWindow->x(), randWalkWindow->y(), false, string("padRandWalk"));
              randWalkWindow->hide();
              randSeen = false;
              if ((Fl::event_button() == 3))
                  synth->getGuiMaster()->partui->padnoteui->padnotewindow->show();}
          xywh {175 124 50 20} box THIN_UP_BOX color 196 labelsize 12 labelcolor 64
        }
      }
    }
  }
  Function {show_randWalk()} {} {
    code {//
      int fetchW, fetchH, fetchX, fetchY, fetchO;
      loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, string("padRandWalk"));

      if (fetchW < randDW || fetchH < randDH)
      {
          fetchW = randDW;
          fetchH = randDH;
      }
      checkSane(fetchX, fetchY, fetchW, fetchH, randDW, randDH);

      randWalkWindow->resize(fetchX, fetchY, fetchW, fetchH);
      randWalkWindow->show();
      randRtext();
      randSeen = true;} {}
  }
  Function {randRtext()} {} {
    code {//
          int w = randWalkWindow->w();
          int h = randWalkWindow->h();
          float dW = w / float(randDW);
          float dH = h / float(randDH);
          float dScale;
          if (dW < dH)
              dScale = dW;
          else
              dScale = dH;
          if (dScale < 0.2f)
              dScale = 0.2f;

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

          rebuildTrigger->labelsize(size10);
          randWalkDetune->labelsize(size10);
          randWalkBandwidth->labelsize(size10);
          randWalkFilterFreq->labelsize(size10);
          randWalkProfileWidth->labelsize(size10);
          randWalkProfileStretch->labelsize(size10);
          randClose->labelsize(size12);

          randWalkWindow->redraw();} {}
  }
  Function {Showpad()} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "PadSynth");
    if (fetchW < padDW || fetchH < padDH)
    {
        fetchW = padDW;
        fetchH = padDH;
    }
    checkSane(fetchX, fetchY, fetchW, fetchH, padDW, padDH);

    padnotewindow->resize(fetchX, fetchY, fetchW, fetchH);
    padnotewindow->show();
    lastpadW = 0;
    padSeen = true;} {}
  }
  Function {padRtext()} {} {
    code {//
    if (oscui)
    {
        if (oscui->osceditUI->visible() && lastWaveW != oscui->osceditUI->w())
        {
            lastWaveW = oscui->osceditUI->w();
            oscui->waveRtext();
        }
    }

    if (randWalkWindow->visible() && lastRandW != randWalkWindow->w())
    {
        randRtext();
        lastRandW = randWalkWindow->w();
    }

    if (resui->resonancewindow->visible() && lastResuiW != resui->resonancewindow->w())
    {
        resui->resonanceRtext();
        lastResuiW = resui->resonancewindow->w();
    }

    ampenv->wincheck();
    freqenv->wincheck();
    filterenv->wincheck();

    if (padnotewindow->w() == lastpadW)
        return;

    lastpadW = padnotewindow->w();

    float dScale = padnotewindow->w() / float(padDW);
    if (dScale < 0.2f)
        dScale = 0.2f;

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

    amplfo->lfoRtext(dScale);
    freqlfo->lfoRtext(dScale);
    filterlfo->lfoRtext(dScale);

    ampenv->envRtext(dScale);
    freqenv->envRtext(dScale);
    filterenv->envRtext(dScale);

    filterui->filterRtext(dScale);

    harmonicstructuregroup->labelsize(size12);
    harmonicprofile->labelsize(size12);
    hpbasetype->labelsize(size);
        hpbasetype->textsize(size);
    hpbasepar1->labelsize(size);
    hpfreqmult->labelsize(size);
    hpmpar1->labelsize(size);
    hpmfreq->labelsize(size);
    hpwidth->labelsize(size);
    hponehalf->labelsize(size);
        hponehalf->textsize(size);

    hpampmode->labelsize(size);
        hpampmode->textsize(size);
    hpamppar1->labelsize(size);
    hpamppar2->labelsize(size);
    hpamptype->labelsize(size);
        hpamptype->textsize(size);
    hpautoscale->labelsize(size11);

    bwdial->labelsize(size);
    bwcents->labelsize(size);
        bwcents->textsize(size11);

    bwscale->labelsize(size);
        bwscale->textsize(size);

    spectrummode->labelsize(size);
        spectrummode->textsize(size);

    hrpospar1->labelsize(size);
    hrpospar2->labelsize(size);
    hrpospar3->labelsize(size);
    hrpostype->labelsize(size);
        hrpostype->textsize(size11);

    qbasenote->labelsize(size11);
        qbasenote->textsize(size12);
    qsmpoct->labelsize(size11);
        qsmpoct->textsize(size12);
    qoct->labelsize(size11);
        qoct->textsize(size12);

    qsamplesize->labelsize(size);
        qsamplesize->textsize(size11);
    xFadeDial->labelsize(size);
    randWalkUI->labelsize(size12);

    resonance->labelsize(size12);
    waveform->labelsize(size12);

    filterlabel->labelsize(size11);

    envelopes->labelsize(size12);
    amplabel->labelsize(size11);
    volume->labelsize(size);
    vsns->labelsize(size);
    pan->labelsize(size);
    panwidth->labelsize(size);
    randompan->labelsize(size11);
    stereo->labelsize(size11);
    dpop->labelsize(size);
    pstr->labelsize(size);
    pt->labelsize(size);
    pstc->labelsize(size);
    pvel->labelsize(size);

    frequencygrp->labelsize(size11);
    bend->labelsize(size);
    offset->labelsize(size);
    hz440->labelsize(size);
    fixedfreqetdial->labelsize(size);
    detune->labelsize(size);
        detunevalueoutput->labelsize(size);
            detunevalueoutput->textsize(size);
    octavetext->labelsize(size);
        octave->textsize(size11);
    detunetype->labelsize(size);
        detunetype->textsize(size);
    coarsedet->labelsize(size);
        coarsedet->textsize(size11);

    padExport->labelsize(size12);
    applybutton->labelsize(size12);
    padCopy->labelsize(size11);
    padPaste->labelsize(size11);
    padClose->labelsize(size12);

    padnotewindow->redraw();} {}
  }
  Function {theme()} {} {
    code {//
        if (padnotewindow->visible())
        {
            lastpadW = 0;
            padRtext();
        }
        if (randWalkWindow)
        {
            if (randWalkWindow->visible())
            {
                randRtext();
            }
        }
        if (oscui)
        {
            if (oscui->osceditUI->visible())
            {
                lastWaveW = 0;
                oscui->waveRtext();
            }
        }
        if (resui->resonancewindow->visible())
        {
            lastResuiW = 0;
            resui->resonanceRtext();
        }

        ampenv->theme();
        freqenv->theme();
        filterenv->theme();
        filterui->theme();
        ;} {}
  }
  Function {send_data(int action, int control, float value, int type, int insert = UNUSED, int miscmsg = UNUSED)} {} {
    code {//
    unsigned char partnum = npart;
    if (miscmsg != UNUSED)
    {
        partnum = TOPLEVEL::section::main;
        action = TOPLEVEL::action::lowPrio;
    }
    type |= TOPLEVEL::type::Write;
    collect_writeData(synth, value, action, type, control, partnum, kititem, PART::engine::padSynth, insert, UNUSED, UNUSED, miscmsg);} {}
  }
  Function {returns_update(CommandBlock *getData)} {} {
    code {//
    float value = getData->data.value;
    bool value_bool = _SYS_::F2B(value);
    bool wasFromHere = ((getData->data.source & TOPLEVEL::action::noAction) == TOPLEVEL::action::fromGUI);
    unsigned char control = getData->data.control;
    unsigned char miscmsg = getData->data.miscmsg;
    float result;
    string name;

    switch(control)
    {
        case PADSYNTH::control::volume:
            volume->value(value);
            volume->selection_color(setKnob(value,90));
            break;

        case PADSYNTH::control::velocitySense:
            vsns->value(value);
            vsns->selection_color(setKnob(value,64));
            break;

        case PADSYNTH::control::panning:
            pan->value(value);
            pan->selection_color(setKnob(value,64));
            break;
        case PADSYNTH::control::enableRandomPan:
            randompan->value(value_bool);
            if (value_bool)
                panwidth->activate();
            else
                panwidth->deactivate();
            break;

        case PADSYNTH::control::randomWidth:
            panwidth->value(value);
            panwidth->selection_color(setKnob(value,63));
            break;

        case PADSYNTH::control::bandwidth:
            bwdial->value(value);
            bwdial->selection_color(setKnob(lrint(value),500));
            result = powf(value / 1000.0f, 1.1f);
            result = power<10>(result * 4.0f) * 0.25f;
            bwcents->value(result);
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::bandwidthScale:
            bwscale->value(lrint(value));
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::spectrumMode:
            spectrummode->value(lrint(value));
            if (pars->Pmode == 0)
            {
                bwprofilegroup->activate();
                bwdial->activate();
                bwcents->activate();
                hprofile->activate();
                hprofile->color(254);
                bwscale->activate();
            }
            else
            {
                bwprofilegroup->deactivate();
                bwdial->deactivate();
                bwcents->deactivate();
                hprofile->deactivate();
                hprofile->color(48);
                bwscale->deactivate();
            }
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::xFadeUpdate:
            {
                int dialSetting = millisec2logDial(value);
                xFadeDial->value(dialSetting);
                xFadeDial->selection_color(setKnob(dialSetting,2301));
                cbwidget->do_callback();
            }
            break;

        case PADSYNTH::control::rebuildTrigger:
            {
                int dialSetting = millisec2logDial(value);
                // remove a socket of 200ms from the dial setting, editable time in the UI starts > 200ms
                if (dialSetting >= 2300) dialSetting -= 2300;
                else dialSetting = -1;
                rebuildTrigger->value(dialSetting);
                rebuildTrigger->selection_color(setKnob(dialSetting,-1));
                cbwidget->do_callback();
            }
            break;

        case PADSYNTH::control::detuneFrequency:
            detune->value(lrint(value));
            detune->selection_color(setSlider(lrint(value),0));
            detunevalueoutput->do_callback();
            break;

        case PADSYNTH::control::equalTemperVariation:
            fixedfreqetdial->value(lrint(value));
            fixedfreqetdial->selection_color(setKnob(lrint(value),0));
            break;

        case PADSYNTH::control::baseFrequencyAs440Hz:
            hz440->value(value_bool);
            if (value_bool)
                fixedfreqetdial->activate();
            else
                fixedfreqetdial->deactivate();
            break;

        case PADSYNTH::control::octave:
            octave->value(lrint(value));
            break;

        case PADSYNTH::control::detuneType:
            detunetype->value(lrint(value) - 1);
            break;

        case PADSYNTH::control::coarseDetune:
            coarsedet->value(lrint(value));
            break;

        case PADSYNTH::control::pitchBendAdjustment:
            bend->value(lrint(value));
            bend->selection_color(setKnob(lrint(value),88));
            break;

        case PADSYNTH::control::pitchBendOffset:
            offset->value(lrint(value));
            offset->selection_color(setKnob(lrint(value),64));
            break;

        case PADSYNTH::control::overtoneParameter1:
            hrpospar1->value(lrint(value));
            hrpospar1->selection_color(setKnob(lrint(value),64));
            overtonepos->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::overtoneParameter2:
            hrpospar2->value(lrint(value));
            hrpospar2->selection_color(setKnob(lrint(value),64));
            overtonepos->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::overtoneForceHarmonics:
            hrpospar3->value(lrint(value));
            hrpospar3->selection_color(setKnob(lrint(value),0));
            overtonepos->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::overtonePosition:
            hrpostype->value(lrint(value));
            if (hrpostype->value() > 0)
            {
                hrpospar1->activate();
                hrpospar3->activate();
                if (hrpostype->value() == 7)
                    hrpospar2->deactivate();
                else
                    hrpospar2->activate();
            }
            else
            {
                hrpospar1->deactivate();
                hrpospar2->deactivate();
                hrpospar3->deactivate();
            }
            overtonepos->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::baseWidth:
            hpbasepar1->value(lrint(value));
            hpbasepar1->selection_color(setKnob(lrint(value),80));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::frequencyMultiplier:
            hpfreqmult->value(lrint(value));
            hpfreqmult->selection_color(setKnob(lrint(value),0));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::modulatorStretch:
            hpmpar1->value(lrint(value));
            hpmpar1->selection_color(setKnob(lrint(value),0));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::modulatorFrequency:
            hpmfreq->value(lrint(value));
            hpmfreq->selection_color(setKnob(lrint(value),30));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::size:
            hpwidth->value(lrint(value));
            hpwidth->selection_color(setKnob(lrint(value),127));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::baseType:
            hpbasetype->value(lrint(value));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::harmonicSidebands:
            hponehalf->value(lrint(value));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::spectralWidth:
            hpamppar1->value(value);
            hpamppar1->selection_color(setKnob(value,80));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::spectralAmplitude:
            hpamppar2->value(value);
            hpamppar2->selection_color(setKnob(value,64));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::amplitudeMultiplier:
            hpamptype->value(lrint(value));
            if (value_bool)
                ampgroup->activate();
            else
                ampgroup->deactivate();
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::amplitudeMode:
            hpampmode->value(lrint(value));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::autoscale:
            hpautoscale->value(lrint(value));
            hprofile->redraw();
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::harmonicBase:
            qbasenote->value(lrint(value));
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::samplesPerOctave:
            qsmpoct->value(lrint(value));
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::numberOfOctaves:
            qoct->value(lrint(value));
            cbwidget->do_callback();
            break;

        case PADSYNTH::control::sampleSize:
            qsamplesize->value(lrint(value));
            cbwidget->do_callback();
            break;

        case MAIN::control::exportPadSynthSamples:
            name = textMsgBuffer.fetch(miscmsg);
            if (name.find("FAILED") == 1)
            {
                if (wasFromHere)
                    alert(synth, "Some samples have failed.");
            }
            padStatus->activateStage(PADStatus::CLEAN);
            break;

        case PADSYNTH::control::stereo:
            stereo->value(value_bool);
            break;

        case PADSYNTH::control::dePop:
            dpop->value(value);
                dpop->selection_color(setKnob(value,20));
            break;

        case PADSYNTH::control::punchStrength:
            pstr->value(value);
                pstr->selection_color(setKnob(value,0));
            break;

        case PADSYNTH::control::punchDuration:
            pt->value(value);
                pt->selection_color(setKnob(value,60));
            break;

        case PADSYNTH::control::punchStretch:
            pstc->value(value);
                pstc->selection_color(setKnob(value,64));
            break;

        case PADSYNTH::control::punchVelocity:
            pvel->value(value);
                pvel->selection_color(setKnob(value,72));
            break;

        case PADSYNTH::control::randWalkDetune:
            randWalkDetune->value(value);
                randWalkDetune->selection_color(setKnob(value,0));
            break;

        case PADSYNTH::control::randWalkBandwidth:
            randWalkBandwidth->value(value);
                randWalkBandwidth->selection_color(setKnob(value,0));
            break;

        case PADSYNTH::control::randWalkFilterFreq:
            randWalkFilterFreq->value(value);
                randWalkFilterFreq->selection_color(setKnob(value,0));
            break;

        case PADSYNTH::control::randWalkProfileWidth:
            randWalkProfileWidth->value(value);
                randWalkProfileWidth->selection_color(setKnob(value,0));
            break;

        case PADSYNTH::control::randWalkProfileStretch:
            randWalkProfileStretch->value(value);
                randWalkProfileStretch->selection_color(setKnob(value,0));
            break;

        case PADSYNTH::control::applyChanges:
            if (lrint(value) == 0 and getData->data.offset != UNUSED)
                padStatus->handleStateMessage(*getData);
            break;

    }} {}
  }
  Function {paste(CommandBlock *getData)} {} {
    code {//
        switch (getData->data.insert)
        {
            case TOPLEVEL::insert::resonanceGroup:
            {
                if (resui)
                        resui->refresh();
                break;
            }
        }
        //std::cout << "in paddsynth" << std::endl;
        ;} {}
  }
  Function {applyButton(Fl_Color colour, const char *const text)} {} {
    code {//
    applybutton->color(colour);
    applybutton->label(text);
    applybutton->redraw();
    if (oscui)
    {
        oscui->applybutton->color(colour);
        // not changing text due to limited space
        oscui->applybutton->redraw();
    }
    if (resui)
    {
        resui->applybutton->color(colour);
        resui->applybutton->redraw();
    }} {}
  }
  Function {PADnoteUI(PADnoteParameters *parameters)} {} {
    code {//
    synth = & parameters->getSynthEngine();
    pars = parameters;
    npart = parameters->partID;
    kititem = parameters->kitID;
    padSeen = false;
    randSeen = false;
    lastWaveW = 0;
    lastRandW = 0;
    lastpadW = 0;
    oscui = NULL;
    lastResuiW = 0;
    resui = new ResonanceUI(pars->resonance.get(), npart, kititem, PART::engine::padSynth);
    make_randWalkWindow();
    make_window();
    padStatus.reset(new PADStatus(npart,kititem));
    // setup handler to indicate PADSynth wavetable build status
    padStatus->on(PADStatus::CLEAN,   [&]() { applyButton(pad_built, "Rebuilt Wave"); });
    padStatus->on(PADStatus::FADING,  [&]() { applyButton(pad_fading, "fading..."); });
    padStatus->on(PADStatus::PENDING, [&]() { applyButton(pad_pending, "pending Wave"); });
    padStatus->on(PADStatus::BUILDING,[&]() { applyButton(pad_building, "rebuilding..."); });
    padStatus->on(PADStatus::DIRTY,   [&]() { applyButton(pad_apply, "Apply Changes"); });} {}
  }
  Function {refresh()} {} {
    code {//
        volume->value(pars->PVolume);
            volume->selection_color(setKnob(volume->value(), 90));
        vsns->value(pars->PAmpVelocityScaleFunction);
            vsns->selection_color(setKnob(vsns->value(), 64));
        pan->value(pars->PPanning);
            pan->selection_color(setKnob(pan->value(), 64));
        stereo->value((pars->PStereo) ? 1 : 0);

        pstr->value(pars->PPunchStrength);
            pstr->selection_color(setKnob(pstr->value(), 0));
        pt->value(pars->PPunchTime);
            pt->selection_color(setKnob(pt->value(), 60));
        pstc->value(pars->PPunchStretch);
            pstc->selection_color(setKnob(pstc->value(), 64));
        pvel->value(pars->PPunchVelocitySensing);
            pvel->selection_color(setKnob(pan->value(), 72));

        detunevalueoutput->value(getDetune(pars->PDetuneType,0,pars->PDetune));
        detune->value(pars->PDetune-8192);
            detune->selection_color(setSlider(detune->value(), 0));

        int k=pars->PCoarseDetune/1024;if (k>=8) k-=16;
        octave->value(k);

        detunetype->value(pars->PDetuneType-1);
        k=pars->PCoarseDetune%1024;if (k>=512) k-=1024;
        coarsedet->value(k);

        hz440->value(pars->Pfixedfreq);
        fixedfreqetdial->value(pars->PfixedfreqET);
            fixedfreqetdial->selection_color(setKnob(fixedfreqetdial->value(), 0));

        amplfo->refresh();
        freqlfo->refresh();
        filterlfo->refresh();

        ampenv->refresh();
        freqenv->refresh();
        filterenv->refresh();
        filterui->refresh();

        /* harmonic structure parameters */

        resui->refresh();
        if (oscui!=NULL) oscui->refresh();

        hpbasetype->value(pars->PProfile.base.type);
        hpbasepar1->value(pars->PProfile.base.pwidth);
            hpbasepar1->selection_color(setKnob(hpbasepar1->value(), 80));
        hpfreqmult->value(pars->PProfile.freqmult);
            hpfreqmult->selection_color(setKnob(hpfreqmult->value(), 0));

        hpmpar1->value(pars->PProfile.modulator.pstretch);
            hpmpar1->selection_color(setKnob(hpmpar1->value(), 0));
        hpmfreq->value(pars->PProfile.modulator.freq);
            hpmfreq->selection_color(setKnob(hpmfreq->value(), 30));
        hpwidth->value(pars->PProfile.width);
            hpwidth->selection_color(setKnob(hpwidth->value(), 127));

        hponehalf->value(pars->PProfile.onehalf);
        hpamptype->value(pars->PProfile.amp.type);
        hpampmode->value(pars->PProfile.amp.mode);
        hpamppar1->value(pars->PProfile.amp.par1);
            hpamppar1->selection_color(setKnob(hpamppar1->value(), 80));
        hpamppar2->value(pars->PProfile.amp.par2);
            hpamppar2->selection_color(setKnob(hpamppar2->value(), 64));
        hpautoscale->value(pars->PProfile.autoscale);

        bwdial->value(pars->Pbandwidth);
            bwdial->selection_color(setKnob(bwdial->value(), 500));
        if (pars->Pmode==0)
        {
           bwprofilegroup->activate();
           bwdial->activate();
           bwcents->activate();
           hprofile->activate();
           hprofile->color(54);
           bwscale->activate();
        }
        else
        {
           bwprofilegroup->deactivate();
           bwdial->deactivate();
           bwcents->deactivate();
           hprofile->deactivate();
           hprofile->color(48);
           bwscale->activate();
        }

        spectrummode->value(pars->Pmode);

        qbasenote->value(pars->Pquality.basenote);
        qsmpoct->value(pars->Pquality.smpoct);
        qoct->value(pars->Pquality.oct);
        qsamplesize->value(pars->Pquality.samplesize);

        hrpostype->value(pars->Phrpos.type);
        if (hrpostype->value() > 0)
        {
            hrpospar1->activate();
            hrpospar3->activate();
            if (hrpostype->value() == 7)
                hrpospar2->deactivate();
            else
                hrpospar2->activate();
        }
        else
        {
            hrpospar1->deactivate();
            hrpospar2->deactivate();
            hrpospar3->deactivate();
        }
        hrpospar1->value(pars->Phrpos.par1);
            hrpospar1->selection_color(setKnob(hrpospar1->value(), 64));
        hrpospar2->value(pars->Phrpos.par2);
            hrpospar2->selection_color(setKnob(hrpospar2->value(), 64));
        hrpospar3->value(pars->Phrpos.par3);
            hrpospar3->selection_color(setKnob(hrpospar3->value(), 0));

        hprofile->redraw();
        overtonepos->redraw();
        xFadeDial->value(millisec2logDial(pars->PxFadeUpdate));
            xFadeDial->selection_color(setKnob(xFadeDial->value(),2301));

        int dialSetting = millisec2logDial(pars->PrebuildTrigger);
        if (dialSetting >= 2300)
            dialSetting -= 2300;
        else
            dialSetting = -1;
        rebuildTrigger->value(dialSetting);
            rebuildTrigger->selection_color(setKnob(rebuildTrigger->value(),-1));
        randWalkDetune->value(pars->PrandWalkDetune);
            randWalkDetune->selection_color(setKnob(randWalkDetune->value(),0));
        randWalkFilterFreq->value(pars->PrandWalkFilterFreq);
            randWalkFilterFreq->selection_color(setKnob(randWalkFilterFreq->value(),0));
        randWalkBandwidth->value(pars->PrandWalkBandwidth);
            randWalkBandwidth->selection_color(setKnob(randWalkBandwidth->value(),0));
        randWalkProfileWidth->value(pars->PrandWalkProfileWidth);
            randWalkProfileWidth->selection_color(setKnob(randWalkProfileWidth->value(),0));
        randWalkProfileStretch->value(pars->PrandWalkProfileStretch);
            randWalkProfileStretch->selection_color(setKnob(randWalkProfileStretch->value(),0));

        osc->redraw();
        //pars->applyparameters(false);
        //applybutton->color(FL_GRAY);
        //applybutton->parent()->redraw();} {}
  }
  Function {~PADnoteUI()} {return_type virtual
  } {
    code {//
    if (oscui)
        delete(oscui);
    if (resui)
        delete(resui);
    if (randWalkWindow)
    {
        if (randSeen)
            saveWin(synth, randWalkWindow->w(), randWalkWindow->h(), randWalkWindow->x(), randWalkWindow->y(),randWalkWindow->visible(), string("padRandWalk"));
        randWalkWindow->hide();
        delete (randWalkWindow);
    }
    if (padSeen)
        saveWin(synth, padnotewindow->w(), padnotewindow->h(), padnotewindow->x(), padnotewindow->y(), padSeen, "PadSynth");
    padnotewindow->hide();
    delete(padnotewindow);} {}
  }
  decl {PADnoteParameters *pars;} {public local
  }
  decl {OscilEditor *oscui;} {public local
  }
  decl {Oscilloscope *osc;} {public local
  }
  decl {ResonanceUI *resui;} {public local
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {int npart;} {private local
  }
  decl {int kititem;} {private local
  }
  decl {float padDW;} {private local
  }
  decl {float padDH;} {private local
  }
  decl {float randDW;} {private local
  }
  decl {float randDH;} {private local
  }
  decl {int lastpadW;} {private local
  }
  decl {bool padSeen;} {private local
  }
  decl {bool randSeen;} {private local
  }
  decl {int lastWaveW;} {private local
  }
  decl {int lastRandW;} {private local
  }
  decl {int lastResuiW;} {private local
  }
  decl {unique_ptr<PADStatus> padStatus;} {private local
  }
}
