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

comment {PartUI.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 2014-2023, Will Godfrey
Copyright 2024 Kristian Amlie, 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_ask.H>
    \#include <iostream>
    \#include "Misc/Config.h"
    \#include "Misc/SynthEngine.h"} {private global
}

decl {\#include "UI/MiscGui.h"
    \#include "EffUI.h"
    \#include "BankUI.h"
    \#include "ADnoteUI.h"
    \#include "SUBnoteUI.h"
    \#include "PADnoteUI.h"
    \#include "UI/WidgetMWSlider.h"
    \#include "UI/WidgetSpinner.h"
    \#include "UI/WidgetCheckButton.h"
    \#include "Params/Controller.h"} {public global
}

decl {\#include "Misc/Part.h"
    \#define MAX_INFO_TEXT_SIZE 256} {public local
}

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

decl {\#include "Misc/FormatFuncs.h"
    using func::asString;} {private local
}

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

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

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

class PartUI_ {} {
  Function {showparameters(int /* kititem */,int /* engine */)} {return_type virtual
  } {
    code {;} {}
  }
}

class PartKitItem {: {public Fl_Group}
} {
  Function {make_window()} {} {
    Fl_Window partkititem {
      xywh {141 95 670 20} type Double box NO_BOX hide
      class Fl_Group
    } {
      Fl_Group partkititemgroup {
        xywh {55 4 605 20}
        code0 {if (part->kit[n].Penabled == 0) o->deactivate();}
      } {
        Fl_Check_Button mutedcheck {
          callback {//
          send_data(0, PART::control::kitItemMute, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          xywh {60 4 15 15} down_box DOWN_BOX color 7 selection_color 64 labelfont 1 labelsize 11 labelcolor 64
          code0 {o->value(part->kit[n].Pmuted);}
          class Fl_Check_Button2
        }
        Fl_Button labelbutton {
          label {Bass Drum}
          callback {//
          string tmp = input_text(synth, "Kit item name:", part->kit[n].Pname);
          if (tmp != "" && tmp != part->kit[n].Pname)
          {
              send_data(TOPLEVEL::action::lowPrio, PART::control::instrumentName, 0, TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup, UNUSED, textMsgBuffer.push(tmp));
              o->copy_label(tmp.c_str());
          }}
          xywh {90 4 130 14} box THIN_DOWN_BOX down_box FLAT_BOX color 7 labelfont 1 labelsize 10 labelcolor 64 align 20
          code0 {o->copy_label(part->kit[n].Pname.c_str());}
        }
        Fl_Counter minkcounter {
          callback {//
          int tmp = o->value();
          int other = maxkcounter->value();
          if (tmp >= other)
          {
              tmp = other;
              o->value(tmp);
          }

          send_data(0, PART::control::minNote, tmp, TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          xywh {225 4 70 14} type Simple labelcolor 64 minimum 0 maximum 127 step 1 textfont 1 textsize 12 textcolor 64
          code0 {o->value(part->kit[n].Pminkey);}
        }
        Fl_Button setmin {
          label m
          callback {//
          int last = part->getLastNote();
          if (last <= 0)
              return;
          int tmp;
          int other = maxkcounter->value();
          if (last >= other)
              tmp = other;
          else
              tmp = last;
          minkcounter->value(tmp);

          send_data(0, PART::control::minToLastKey, tmp, TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          tooltip {set the minimum key to the last pressed key} xywh {300 5 15 12} box THIN_UP_BOX labelsize 10 labelcolor 64
        }
        Fl_Button setmax {
          label M
          callback {//
          int last = part->getLastNote();
          if (last <= 0)
              return;
          int tmp;
          int other = minkcounter->value();
          if (last <= other)
              tmp = other;
          else
              tmp = last;
          maxkcounter->value(tmp);

          send_data(0, PART::control::maxToLastKey, tmp, TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          tooltip {set the maximum key to the last pressed key} xywh {330 5 15 12} box THIN_UP_BOX labelsize 10 labelcolor 64
        }
        Fl_Button setfull {
          label R
          callback {//
          minkcounter->value(0);
          maxkcounter->value(127);

          send_data(0, PART::control::resetMinMaxKey, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          tooltip {reset the minimum key to 0 and maximum key to 127} xywh {315 5 15 12} box THIN_UP_BOX labelfont 1 labelsize 10 labelcolor 64
        }
        Fl_Counter maxkcounter {
          callback {//
          int tmp = o->value();
          int other = minkcounter->value();
          if (tmp <= other)
          {
              tmp = other;
              o->value(tmp);
          }
          send_data(0, PART::control::maxNote, tmp, TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          xywh {350 4 70 14} type Simple labelcolor 64 minimum 0 maximum 127 step 1 textfont 1 textsize 12 textcolor 64
          code0 {o->value(part->kit[n].Pmaxkey);}
        }
        Fl_Button adeditbutton {
          label edit
          callback {//
          partui->showparameters(n,PART::engine::addSynth);
          if ((Fl::event_button() == 3))
              synth->getGuiMaster()->partui->instrumentkitlist->hide();}
          xywh {442 4 40 15} box GTK_THIN_UP_BOX color 198 labelsize 11 labelcolor 64
          code0 {if (part->kit[n].Padenabled==0) o->deactivate();}
        }
        Fl_Check_Button adcheck {
          callback {//

          send_data(TOPLEVEL::action::forceUpdate, PART::control::enableAdd, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          xywh {426 4 15 15} down_box DOWN_BOX color 7 selection_color 64 labelfont 1 labelsize 11 labelcolor 64
          code0 {o->value(part->kit[n].Padenabled);}
          class Fl_Check_Button2
        }
        Fl_Button subeditbutton {
          label edit
          callback {//
          partui->showparameters(n,PART::engine::subSynth);
          if ((Fl::event_button() == 3))
              synth->getGuiMaster()->partui->instrumentkitlist->hide();}
          xywh {507 4 40 15} box GTK_THIN_UP_BOX color 198 labelsize 11 labelcolor 64
          code0 {if (part->kit[n].Psubenabled==0) o->deactivate();}
        }
        Fl_Check_Button subcheck {
          callback {//

          send_data(TOPLEVEL::action::forceUpdate, PART::control::enableSub, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          xywh {491 4 15 15} down_box DOWN_BOX color 7 selection_color 64 labelfont 1 labelsize 11 labelcolor 64
          code0 {o->value(part->kit[n].Psubenabled);}
          class Fl_Check_Button2
        }
        Fl_Button padeditbutton {
          label edit
          callback {//
          partui->showparameters(n,PART::engine::padSynth);
          if ((Fl::event_button() == 3))
              synth->getGuiMaster()->partui->instrumentkitlist->hide();}
          xywh {570 4 40 15} box GTK_THIN_UP_BOX color 198 labelsize 11 labelcolor 64
          code0 {if (part->kit[n].Ppadenabled==0) o->deactivate();}
        }
        Fl_Check_Button padcheck {
          callback {//

          send_data(TOPLEVEL::action::forceUpdate, PART::control::enablePad, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          xywh {555 4 15 15} down_box DOWN_BOX color 7 selection_color 64 labelfont 1 labelsize 11 labelcolor 64
          code0 {o->value(part->kit[n].Ppadenabled);}
          class Fl_Check_Button2
        }
        Fl_Choice sendtoeffect {
          callback {//
          send_data(0, PART::control::kitEffectNum, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
          xywh {615 4 45 15} down_box BORDER_BOX labelsize 10 labelcolor 64 align 5 textfont 1 textsize 10 textcolor 64
          code0 {o->add("OFF"); char nrstr[10]; for (int i = 0; i < NUM_PART_EFX; i++) {sprintf(nrstr,"FX%d",i+1);o->add(nrstr);};}
          code1 {o->value(part->kit[n].Psendtoparteffect+1);if (part->kit[n].Psendtoparteffect==127) o->value(0);}
        } {}
      }
      Fl_Check_Button enabledcheck {
        label 01
        callback {//
        int answer = 1;
        if (o->value() == 0)
            answer = (choice(synth, "", "Yes", "No", "Delete the item?\\nThis action can't be reversed and will erase the 'undo' list.") > 1);
        if (answer != 0)
        {
            if (o->value() == 0)
                clearLine();
            else
                partkititemgroup->activate();
            o->redraw();
            partui->showparameters(n, -1); // use to delete the ui, if it is not to item 0
        }
        else
            o->value(1);
        send_data(0, PART::control::enableKitLine, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);}
        xywh {30 4 20 15} down_box DOWN_BOX selection_color 64 labeltype EMBOSSED_LABEL labelfont 1 labelsize 12 labelcolor 64 align 4
        code0 {snprintf(label,10,"%d",(n&15)+1);o->label(label);}
        code1 {o->value(part->kit[n].Penabled);}
        code2 {if (n==0) o->hide();}
        code3 {if (o->value() == 0) labelbutton->color(gen_text_back);}
        class Fl_Check_Button2
      }
    }
  }
  Function {send_data(int action, int control, float value, int type, int kititem = UNUSED, int engine = UNUSED, int insert = UNUSED, int parameter = UNUSED, int miscmsg = UNUSED)} {} {
    code {//
        int partToUse = collect_readData(synth, 0, MAIN::control::partNumber, TOPLEVEL::main, kititem); // make sure it's the right one!
        type |= TOPLEVEL::type::Write;
        collect_writeData(synth, value, action, type, control, partToUse, kititem, engine, insert, parameter, UNUSED, miscmsg);
        ;} {}
  }
  Function {PartKitItem(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} {
    code {//
    n=0;part=NULL;} {}
  }
  Function {clearLine()} {} {
    code {//
    partkititemgroup->deactivate();
    mutedcheck->value(0);
    labelbutton->copy_label("");
    minkcounter->value(0);
    maxkcounter->value(127);
    adcheck->value(0);
    adeditbutton->deactivate();
    subcheck->value(0);
    subeditbutton->deactivate();
    padcheck->value(0);
    padeditbutton->deactivate();
    sendtoeffect->value(1);} {}
  }
  Function {init(Part *part_, int n_, int npart_, PartUI_ *partui_)} {} {
    code {//
    synth = part_->getSynthEngine();
    part = part_;
    n = n_;
    npart = npart_;
    partui = partui_;
    make_window();
    end();} {}
  }
  Function {itemRtext(float dScale)} {} {
    code {//
    int size = int(10 * dScale);
    int size11 = int(11 * dScale);
    int size12 = int(12 * dScale);

    enabledcheck->labelsize(size12);
    mutedcheck->labelsize(size11);
    labelbutton->labelsize(size);
    minkcounter->textsize(size12);
    setmin->labelsize(size);
    setmax->labelsize(size);
    setfull->labelsize(size);
    maxkcounter->textsize(size12);
    adeditbutton->labelsize(size11);
    adcheck->labelsize(size11);
    subeditbutton->labelsize(size11);
    subcheck->labelsize(size11);
    padeditbutton->labelsize(size11);
    padcheck->labelsize(size11);
    sendtoeffect->labelsize(size);
         sendtoeffect->textsize(size);} {}
  }
  Function {~PartKitItem()} {} {
    code {//
    partkititem->hide();} {}
  }
  decl {Part *part;} {public local
  }
  decl {int n;} {private local
  }
  decl {int npart;} {private local
  }
  decl {char label[10];} {private local
  }
  decl {PartUI_ *partui;} {private local
  }
  decl {SynthEngine *synth;} {private local
  }
}

class PartUI {: {public Fl_Group, PartUI_}
} {
  Function {make_window()} {} {
    Fl_Window instrumenteditwindow {
      label {Instrument Edit}
      callback {editClose->do_callback();}
      xywh {1051 172 395 385} type Double hide resizable
      code0 {seteditname();}
      code1 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Edit"), npart, TOPLEVEL::windowTitle)).c_str());}
      code2 {editDW = 395; editDH = 385;}
      code3 {o->size_range(editDW, editDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Group {} {
        xywh {0 222 395 162} box GTK_THIN_UP_BOX
      } {
        Fl_Group ADD {
          label ADDsynth
          xywh {5 246 94 72} box ENGRAVED_FRAME labelfont 1 labelcolor 64
        } {
          Fl_Check_Button adsynenabledcheck {
            label Enabled
            callback {//

            send_data(TOPLEVEL::action::forceUpdate, PART::control::enableAdd, o->value(), TOPLEVEL::type::Integer, npart);}
            tooltip {enable/disable ADsynth} xywh {12 252 80 24} box PLASTIC_UP_BOX down_box DOWN_BOX color 228 selection_color 64 labelfont 3 labelsize 11 labelcolor 226
            code1 {o->value(part->kit[0].Padenabled);}
            class Fl_Check_Button2
          }
          Fl_Box addbox {
            xywh {8 226 84 18} box FLAT_BOX
            code1 {if (adsynenabledcheck->value() != 0 && engine != 0) o->color(add_back); else o->color(FL_BACKGROUND_COLOR);}
          }
          Fl_Button adeditbutton {
            label {Edit &Add}
            callback {//
            showparameters(0,PART::engine::addSynth);
            //checkEngines();
            seteditname();
            if ((Fl::event_button() == 3))
            {
                instrumenteditwindow->hide();}}
            tooltip {Right click: also close this} xywh {12 280 80 32} box GTK_THIN_UP_BOX color 198 selection_color 64 labelfont 1 labelcolor 64 align 128
            code0 {if (part->kit[0].Padenabled==0) o->deactivate();}
          }
        }
        Fl_Group SUB {
          label SUBsynth
          xywh {100 246 94 72} box ENGRAVED_FRAME labelfont 1 labelcolor 64
        } {
          Fl_Check_Button subsynenabledcheck {
            label Enabled
            callback {//

            send_data(TOPLEVEL::action::forceUpdate, PART::control::enableSub, o->value(), TOPLEVEL::type::Integer, npart);}
            tooltip {enable/disable SUBsynth} xywh {107 252 80 24} box PLASTIC_UP_BOX down_box DOWN_BOX color 228 selection_color 64 labelfont 3 labelsize 11 labelcolor 226
            code1 {o->value(part->kit[0].Psubenabled);}
            class Fl_Check_Button2
          }
          Fl_Box subbox {
            xywh {103 226 84 18} box FLAT_BOX
            code1 {if (subsynenabledcheck->value() != 0 && engine != 0) o->color(sub_back); else o->color(FL_BACKGROUND_COLOR);}
          }
          Fl_Button subeditbutton {
            label {Edit &Sub}
            callback {//
            showparameters(0,PART::engine::subSynth);
            //checkEngines();
            seteditname();
            if ((Fl::event_button() == 3))
            {
                instrumenteditwindow->hide();}}
            tooltip {Right click: also close this} xywh {107 280 80 32} box GTK_THIN_UP_BOX color 198 selection_color 64 labelfont 1 labelcolor 64 align 128
            code0 {if (part->kit[0].Psubenabled==0) o->deactivate();}
          }
        }
        Fl_Group PAD {
          label PADsynth
          xywh {195 246 94 72} box ENGRAVED_FRAME labelfont 1 labelcolor 64
        } {
          Fl_Check_Button padsynenabledcheck {
            label Enabled
            callback {//

            send_data(TOPLEVEL::action::forceUpdate, PART::control::enablePad, o->value(), TOPLEVEL::type::Integer, npart);}
            tooltip {enable/disable PADsynth} xywh {202 252 80 24} box PLASTIC_UP_BOX down_box DOWN_BOX color 228 selection_color 64 labelfont 3 labelsize 11 labelcolor 226
            code1 {o->value(part->kit[0].Ppadenabled);}
            class Fl_Check_Button2
          }
          Fl_Box padbox {
            xywh {198 226 84 18} box FLAT_BOX
            code1 {if (padsynenabledcheck->value() != 0 && engine != 0) o->color(pad_back); else o->color(FL_BACKGROUND_COLOR);}
          }
          Fl_Button padeditbutton {
            label {Edit &Pad}
            callback {//
            showparameters(0,PART::engine::padSynth);
            //checkEngines();
            seteditname();
            if ((Fl::event_button() == 3))
            {
                instrumenteditwindow->hide();}}
            tooltip {Right click: also close this} xywh {202 280 80 32} box GTK_THIN_UP_BOX color 198 selection_color 64 labelfont 1 labelcolor 64 align 128
            code0 {if (part->kit[0].Ppadenabled==0) o->deactivate();}
          }
        }
        Fl_Button kitedit {
          label {&Kit Edit}
          callback {//
          Showkit();
          if ((Fl::event_button() == 3))
          {
              instrumenteditwindow->hide();}}
          tooltip {Right click: also close this} xywh {295 227 94 28} box GTK_THIN_UP_BOX color 198 selection_color 64 labelfont 1 labelcolor 64 align 128
        }
        Fl_Button effects {
          label {&Effects}
          callback {//
          Showefx();
          if ((Fl::event_button() == 3))
          {
              instrumenteditwindow->hide();}}
          tooltip {Right click: also close this} xywh {295 258 94 28} box GTK_THIN_UP_BOX color 198 labelfont 1 labelcolor 64
        }
        Fl_Button editAT {
          label {After&touch}
          callback {//
                ShowAT();
                atSeen = 2;
                if ((Fl::event_button() == 3))
                    instrumenteditwindow->hide();}
          xywh {295 290 94 28} box GTK_THIN_UP_BOX color 198 labelfont 1 labelcolor 64
        }
        Fl_Button instrumentReset {
          label {&Reset}
          callback {//
         if (!fetchData(0, PART::control::enable, npart))
         {
             alert(synth, "Selected part is disabled");
             return;
         }

         if (Fl::event_state(FL_CTRL))
         {
             if (choice(synth, "", "Yes", "No", "Set entire part " + std::to_string(npart + 1) + " controls to default values ?") > 1)
                 send_data(TOPLEVEL::action::forceUpdate, MAIN::control::defaultPart, npart, TOPLEVEL::type::Integer, TOPLEVEL::section::main);
             return;
         }
         if (choice(synth, "", "Yes", "No", "Set part " + std::to_string(npart + 1) + " instrument to 'Simple Sound' ?") > 1)
                send_data(TOPLEVEL::action::forceUpdate, MAIN::control::defaultInstrument, npart, TOPLEVEL::type::Integer, TOPLEVEL::section::main);}
          tooltip {Revert to default instrument
 +Ctrl, clear entire part} xywh {283 327 100 26} box PLASTIC_UP_BOX color 89 labelfont 1 labelcolor 64
        }
        Fl_Button editClose {
          label {&Close}
          callback {//
                  saveWin(synth, instrumenteditwindow->w(), instrumenteditwindow->h(), instrumenteditwindow->x(),instrumenteditwindow->y(), false, "Part-edit");
                  editSeen = false;
                  lasteditW = 0;
                  instrumenteditwindow->hide();
                  o->parent()->show();}
          xywh {283 357 100 24} box THIN_UP_BOX color 196 labelfont 1 labelcolor 64
        }
      }
      Fl_Group {} {
        xywh {0 2 395 216} box ENGRAVED_FRAME labelcolor 64
      } {
        Fl_Text_Display A_C_display {
          label {Author and Copyright}
          xywh {171 44 148 4} box NO_BOX labelsize 12 labelcolor 64
        }
        Fl_Button A_C_default {
          label Default
          callback {//
            int param = 0;
            if (Fl::event_state(FL_CTRL))
            param = 1;
            send_data(TOPLEVEL::action::lowPrio | TOPLEVEL::action::forceUpdate, PART::control::defaultInstrumentCopyright, 0, TOPLEVEL::type::Integer, npart, UNUSED, UNUSED, UNUSED, param);}
          tooltip {Load default author & copyright
 + Ctrl: save current text as default} xywh {327 25 63 20} labelsize 12 labelcolor 64
        }
        Fl_Input copyright {
          callback {//
           send_data(TOPLEVEL::action::lowPrio, PART::control::instrumentCopyright, 0, TOPLEVEL::type::Integer, npart, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(string(o->value())));}
          xywh {5 49 385 55} type Multiline color 182 labelsize 12 labelcolor 64 align 9 textcolor 64
          code0 {o->maximum_size(MAX_INFO_TEXT_SIZE);}
          code1 {o->value(part->info.Pauthor.c_str());}
        }
        Fl_Input commentField {
          label Comments
          callback {//
          send_data(TOPLEVEL::action::lowPrio, PART::control::instrumentComments, 0, TOPLEVEL::type::Integer, npart, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(string(o->value())));}
          xywh {5 123 385 91} type Multiline color 182 labelsize 12 labelcolor 64 align 5 textcolor 64
          code0 {o->maximum_size(MAX_INFO_TEXT_SIZE);}
          code1 {o->value(part->info.Pcomments.c_str());}
        }
        Fl_Choice instrumentType {
          label {Type:}
          callback {//
              send_data(TOPLEVEL::action::lowPrio, PART::control::instrumentType, o->value(), TOPLEVEL::type::Integer, npart);}
          xywh {5 25 155 20} down_box BORDER_BOX labelfont 1 labelsize 11 labelcolor 64 align 5 textfont 1 textsize 11 textcolor 64
          code0 {fillInstrumentType();}
          code1 {o->value(part->info.Ptype);}
        } {}
      }
      Fl_Box humaniseBox {
        xywh {0 324 272 58} box ENGRAVED_FRAME labelfont 1 align 8
      }
      Fl_Text_Display humanise_display {
        label Humanise
        xywh {102 342 78 7} box NO_BOX labelfont 1 labelcolor 64
      }
      Fl_Value_Slider humanise {
        label Detune
        callback {//
        o->selection_color(setSlider(o->value(),0));
        send_data(0, PART::control::humanise, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Random detune of whole part in cents} xywh {12 342 202 16} type {Horz Knob} box THIN_DOWN_BOX labelsize 12 labelcolor 64 align 8 maximum 50 step 1 textcolor 64
        code1 {o->setValueType(VC_PartHumaniseDetune);o->useCustomTip(true);}
        code2 {o->selection_color(setSlider(o->value(),0));}
        class mwheel_slider_rev
      }
      Fl_Value_Slider velocityhumanise {
        label Velocity
        callback {//
        o->selection_color(setSlider(o->value(),0));
        send_data(0, PART::control::humanvelocity, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Random velocity attenuation of whole part} xywh {12 362 202 16} type {Horz Knob} box THIN_DOWN_BOX labelsize 12 labelcolor 64 align 8 maximum 50 step 1 textcolor 64
        code1 {o->setValueType(VC_PartHumaniseVelocity);o->useCustomTip(true);}
        code2 {o->selection_color(setSlider(o->value(),0));}
        class mwheel_slider_rev
      }
      Fl_Text_Display originalname {
        label {Derived From}
        xywh {200 108 1 15} box NO_BOX labelfont 1 labelsize 12 labelcolor 64 align 4 textsize 11 textcolor 64 hide
      }
      Fl_Text_Display originaltext {
        label text
        xywh {198 108 1 15} box NO_BOX labelfont 1 labelsize 12 labelcolor 225 align 8 textsize 11 hide
      }
    }
    Fl_Window instrumentkitlist {
      label {Instrument Kit}
      callback {//
    saveWin(synth, instrumentkitlist->w(), instrumentkitlist->h(), instrumentkitlist->x(), instrumentkitlist->y(), false, "Part-kit");
    instrumentkitlist->hide();
    kitSeen = false;}
      xywh {373 285 670 370} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Kit List"), npart, TOPLEVEL::windowTitle)).c_str());}
      code2 {kitDW = o->w(); kitDH = o->h();}
      code3 {o->size_range(kitDW, kitDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Group kitlist {
        xywh {4 20 662 324} box THIN_UP_FRAME
      } {
        Fl_Pack kitpack {
          xywh {0 21 670 322}
          code0 {for (int i=0;i<NUM_KIT_ITEMS;i++){partkititem[i]=new PartKitItem(0,0,670,20,"");partkititem[i]->init(part, i, npart, this);}}
        } {}
      }
      Fl_Box kitnum {
        label {No.}
        xywh {10 0 25 15} labelfont 1 labelsize 11 labelcolor 64 align 18
      }
      Fl_Box kitmute {
        label Mute
        xywh {56 15 22 8} labelfont 3 labelsize 11 labelcolor 226 align 1
      }
      Fl_Box kitID {
        label Name
        xywh {137 0 40 15} labelfont 1 labelsize 11 labelcolor 64 align 18
      }
      Fl_Box kitminkey {
        label {Min key}
        xywh {236 0 40 15} labelfont 1 labelsize 11 labelcolor 64 align 18
      }
      Fl_Box kitmaxkey {
        label {Max key}
        xywh {364 0 40 15} labelfont 1 labelsize 11 labelcolor 64 align 18
      }
      Fl_Text_Display addON {
        label On
        xywh {423 15 22 8} box NO_BOX labelfont 3 labelsize 11 labelcolor 226
      }
      Fl_Box kitadd {
        label ADD
        xywh {446 0 34 15} labelfont 1 labelsize 11 labelcolor 64 align 18
      }
      Fl_Text_Display subON {
        label On
        xywh {489 15 22 9} box NO_BOX labelfont 3 labelsize 11 labelcolor 226
      }
      Fl_Box kitsub {
        label SUB
        xywh {507 0 40 15} labelfont 1 labelsize 11 labelcolor 64 align 18
      }
      Fl_Text_Display padON {
        label On
        xywh {554 15 22 10} box NO_BOX labelfont 3 labelsize 11 labelcolor 226
      }
      Fl_Box kitpad {
        label PAD
        xywh {572 0 37 15} labelfont 1 labelsize 11 labelcolor 64 align 18
      }
      Fl_Box kitfxnum {
        label {FX.r.}
        xywh {620 0 30 15} labelfont 1 labelsize 11 labelcolor 64 align 18
      }
      Fl_Choice kitMode {
        label Mode
        callback {//
        int tmp = o->value();
        partKitOn = tmp > 0;
        if (partKitOn)
            kitlist->activate();
        else
            kitlist->deactivate();

        send_data(0, PART::control::kitMode, tmp, TOPLEVEL::type::Integer, npart);}
        tooltip {Single = only 1st item in defined note range sounds} xywh {41 348 88 19} down_box BORDER_BOX labelsize 11 labelcolor 64 textfont 1 textsize 11 textcolor 64
        code0 {o->add("Off");o->add("Multi");o->add("Single");o->add("Crossfade");}
        code1 {if (part->PkitfadeType == 1) {o->value(3);} else {o->value(part->Pkitmode);}}
        code2 {partKitOn = o->value() > 0;}
        code3 {if (!partKitOn) kitlist->deactivate();}
      } {}
      Fl_Check_Button drumMode {
        label {Drum mode}
        callback {//
        send_data(TOPLEVEL::action::forceUpdate, PART::control::drumMode, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Disables microtonal tuning} xywh {285 350 15 15} down_box DOWN_BOX selection_color 64 labelsize 11 labelcolor 64
        code0 {o->value(part->Pdrummode);}
        class Fl_Check_Button2
      }
      Fl_Button kitClose {
        label {&Close}
        callback {//
        saveWin(synth, instrumentkitlist->w(), instrumentkitlist->h(), instrumentkitlist->x(), instrumentkitlist->y(), false, "Part-kit");
        instrumentkitlist->hide();
        kitSeen = false;
        if ((Fl::event_button() == 3))
        synth->getGuiMaster()->partui->instrumenteditwindow->show();}
        tooltip {Right click: also reopen previous} xywh {569 348 63 20} box THIN_UP_BOX color 196 labelcolor 64
      }
    }
    Fl_Window partfx {
      label {Part's Insert Effects}
      callback {//
    saveWin(synth, partfx->w(), partfx->h(),  partfx->x(),  partfx->y(), false, "Part-effects");
    partfx->hide();}
      xywh {520 67 385 160} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Effects"), npart, TOPLEVEL::windowTitle)).c_str());}
      code1 {fxDW = o->w(); fxDH = o->h();}
      code2 {o->size_range(fxDW, fxDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Spinner inseffnocounter {
        callback {//
            int effNum = o->value() - 1;
            send_data(TOPLEVEL::action::forceUpdate, PART::control::effectNumber, effNum, TOPLEVEL::type::Integer, npart, UNUSED, effNum, TOPLEVEL::insert::partEffectSelect);}
        tooltip {Effect No.} xywh {20 8 35 22} labelsize 12 labelcolor 64 maximum 3 textsize 12 textcolor 64
        code0 {o->range(1, NUM_PART_EFX);}
        code1 {o->value(1);}
        class WidgetSpinner
      }
      Fl_Choice insefftype {
        callback {//
            uchar effNum = inseffectui->effNum();
            uchar effType = o->value();
            send_data(TOPLEVEL::action::forceUpdate, PART::control::effectType, effType, TOPLEVEL::type::Integer, npart, UNUSED, effNum, TOPLEVEL::insert::partEffectSelect);}
        tooltip {Effect Type} xywh {86 8 92 22} box UP_BOX down_box BORDER_BOX labelsize 11 labelcolor 64 textfont 1 textsize 12 textcolor 64
        code0 {o->add("No Effect");o->add("Reverb");o->add("Echo");o->add("Chorus");o->add("Phaser");o->add("AlienWah");o->add("Distortion");o->add("EQ");o->add("DynFilter");}
        code1 {o->value(0); // initially "No Effect"}
      } {}
      Fl_Group inseffectuigroup {
        xywh {3 37 380 96} box FLAT_BOX color 48
      } {
        Fl_Group inseffectui {
          xywh {5 38 379 95}
          code0 {InterfaceAnchor& anchor = synth->getGuiMaster()->anchor;
                 o->init(synth, anchor.partEffectParam, anchor.partEffectEQ, npart);}
          class EffUI
        } {}
      }
      Fl_Choice sendtochoice {
        label To
        callback {//
            uchar effNum = inseffectui->effNum();
            send_data(TOPLEVEL::action::forceUpdate, PART::control::effectDestination, o->value(), TOPLEVEL::type::Integer, npart, UNUSED, effNum, TOPLEVEL::insert::partEffectSelect);}
        xywh {225 8 102 22} down_box BORDER_BOX labelfont 1 labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
        code0 {o->add("Next Effect");o->add("Part Out");o->add("Dry Out");}
        code1 {o->value(0);}
      } {}
      Fl_Button effCopy {
        label C
        callback {//
        synth->getGuiMaster()->getPresetsUi()->Ucopy(npart, 16, inseffnocounter->value()-1);
        ;}
        xywh {346 3 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 197
      }
      Fl_Button effPaste {
        label P
        callback {//
        synth->getGuiMaster()->getPresetsUi()->Upaste(npart, 16, inseffnocounter->value()-1);
        ;}
        xywh {346 19 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 197
      }
      Fl_Check_Button bypasseff {
        label Bypass
        callback {//
            uchar effNum = inseffectui->effNum();
            send_data(TOPLEVEL::action::forceUpdate, PART::control::effectBypass, o->value(), TOPLEVEL::type::Integer, npart, UNUSED, effNum, TOPLEVEL::insert::partEffectSelect);}
        tooltip {if the effect is not used (is bypassed)} xywh {20 135 63 21} down_box DOWN_BOX selection_color 64 labelfont 3 labelsize 12 labelcolor 226
        code0 {o->value(false);}
        class Fl_Check_Button2
      }
      Fl_Button effClose {
        label {&Close}
        callback {//
        saveWin(synth, partfx->w(), partfx->h(),  partfx->x(),  partfx->y(), false, "Part-effects");
        if(inseffectui->filterwindow != NULL)
            inseffectui->filterwindow->hide();
        fxSeen = false;
        partfx->hide();
        if ((Fl::event_button() == 3))
            synth->getGuiMaster()->partui->instrumenteditwindow->show();}
        tooltip {Right click: also reopen previous} xywh {307 136 60 20} box THIN_UP_BOX color 196 labelcolor 64
      }
    }
    comment {ctlmidi, ctlwindow, aftertouch control MUST be that order} {in_source in_header
    }
    Fl_Window ctlmidi {
      label {MIDI Controls}
      xywh {591 324 365 60} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("MIDI Controls"), npart, TOPLEVEL::windowTitle)).c_str());}
      code1 {midiDW = o->w(); midiDH = o->h();}
      code2 {o->size_range(midiDW, midiDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Dial modulation {
        label Modulation
        callback {//
        o->selection_color(setKnob(o->value(),64));
        send_data(0, PART::control::midiModWheel, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Modulation Wheel} xywh {20 10 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->modwheel.data);}
        code1 {o->setValueType(VC_percent127);}
        code2 {o->selection_color(setKnob(o->value(),64));}
        class WidgetPDial
      }
      Fl_Dial expression {
        label Expression
        callback {//
        o->selection_color(setKnob(o->value(),127));
        send_data(0, PART::control::midiExpression,  o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip Expression xywh {80 10 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->expression.data);}
        code1 {o->setValueType(VC_percent127);}
        code2 {o->selection_color(setKnob(o->value(),127));}
        class WidgetPDial
      }
      Fl_Dial filterq {
        label {Filter Q}
        callback {//
        o->selection_color(setKnob(o->value(),64));
        send_data(0, PART::control::midiFilterQ, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Filter Q} xywh {140 10 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->filterq.data);}
        code1 {o->setValueType(VC_percent127);}
        code2 {o->selection_color(setKnob(o->value(),64));}
        class WidgetPDial
      }
      Fl_Dial filtercutoff {
        label {Filter Cutoff}
        callback {//
        o->selection_color(setKnob(o->value(),64));
        send_data(0, PART::control::midiFilterCutoff, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Filter Cutoff} xywh {200 10 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->filtercutoff.data);}
        code1 {o->setValueType(VC_percent127);}
        code2 {o->selection_color(setKnob(o->value(),64));}
        class WidgetPDial
      }
      Fl_Dial masterbandwidth {
        label Bandwidth
        callback {//
        o->selection_color(setKnob(o->value(),64));
        send_data(0, PART::control::midiBandwidth, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Master Bandwidth} xywh {260 10 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->bandwidth.data);}
        code1 {o->setValueType(VC_percent127);}
        code2 {o->selection_color(setKnob(o->value(),64));}
        class WidgetPDial
      }
      Fl_Button ctlmidiclose {
        label {&Close}
        callback {//
                saveWin(synth,  ctlmidi->w(),  ctlmidi->h(), ctlmidi->x(), ctlmidi->y(), false, "Part-ctlmidi");
                ctlmidiSeen = false;
                ctlmidi->hide();}
        xywh {309 35 50 20} box THIN_UP_BOX color 196 labelcolor 64
      }
    }
    Fl_Window ctlwindow {
      label Controllers
      callback {ctlclose->do_callback();}
      xywh {418 167 505 130} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Controllers"), npart, TOPLEVEL::windowTitle)).c_str());}
      code1 {ctlDW = o->w(); ctlDH = o->h();}
      code2 {o->size_range(ctlDW, ctlDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Dial volrng {
        label {Vol Rng}
        callback {//
        o->selection_color(setKnob(o->value(),96));
        send_data(0, PART::control::volumeRange, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Volume Range} xywh {132 55 30 30} labelsize 10 labelcolor 64 minimum 64 maximum 127 step 1
        code0 {o->value(part->ctl->volume.data);}
        code1 {o->selection_color(setKnob(o->value(),96));}
        class WidgetPDial
      }
      Fl_Check_Button vol {
        label Vol
        callback {//
        send_data(0, PART::control::volumeEnable, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Volume enable} xywh {175 81 45 18} box THIN_UP_BOX down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64
        code0 {o->value(part->ctl->volume.receive);}
        class Fl_Check_Button2
      }
      Fl_Dial panwidth {
        label PanWdth
        callback {//
        o->selection_color(setKnob(o->value(),64));
        send_data(0, PART::control::panningWidth, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Panning Width} xywh {10 55 30 30} labelsize 10 labelcolor 64 maximum 64 step 1
        code0 {o->value(part->ctl->panning.depth);}
        code1 {o->selection_color(setKnob(o->value(),64));}
        class WidgetPDial
      }
      Fl_Dial modwh {
        label ModWh
        callback {//
        o->selection_color(setKnob(o->value(),80));
        send_data(0, PART::control::modWheelDepth, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Modulation Wheel depth} xywh {50 10 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->modwheel.depth);}
        code1 {o->selection_color(setKnob(o->value(),80));}
        class WidgetPDial
      }
      Fl_Check_Button expmwh {
        label {Exp MWh}
        callback {//
        send_data(0, PART::control::exponentialModWheel, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Exponential modulation wheel} xywh {10 15 40 25} down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64 align 148
        code0 {o->value(part->ctl->modwheel.exponential);}
        class Fl_Check_Button2
      }
      Fl_Dial bwdpth {
        label BwDpth
        callback {//
        o->selection_color(setKnob(o->value(),64));
        send_data(0, PART::control::bandwidthDepth, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {BandWidth depth} xywh {132 10 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->bandwidth.depth);}
        code1 {o->selection_color(setKnob(o->value(),64));}
        class WidgetPDial
      }
      Fl_Check_Button expbw {
        label {Exp BW}
        callback {//
        send_data(0, 134, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Exponential BandWidth Controller} xywh {92 15 35 25} down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64 align 148
        code0 {o->value(part->ctl->bandwidth.exponential);}
        class Fl_Check_Button2
      }
      Fl_Check_Button expr {
        label Expr
        callback {//
        send_data(0, 135, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Expression enable} xywh {175 59 45 18} box THIN_UP_BOX down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64
        code0 {o->value(part->ctl->expression.receive);}
        class Fl_Check_Button2
      }
      Fl_Check_Button fmamp {
        label FMamp
        callback {//
        send_data(0, PART::control::FMamplitudeEnable, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {FM amplitude enable} xywh {225 59 60 18} box THIN_UP_BOX down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64
        code0 {o->value(part->ctl->fmamp.receive);}
        class Fl_Check_Button2
      }
      Fl_Check_Button sustain {
        label Sustain
        callback {//
        send_data(0, PART::control::sustainPedalEnable, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Sustain pedal enable} xywh {225 81 60 18} box THIN_UP_BOX down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64
        code0 {o->value(part->ctl->sustain.receive);}
        class Fl_Check_Button2
      }
      Fl_Check_Button breath {
        label Breath
        callback {//
        send_data(0, 141, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Breath Control enable} xywh {225 38 60 18} box THIN_UP_BOX down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64
        code0 {o->value(part->PbreathControl == MIDI::CC::breath);}
        class Fl_Check_Button2
      }
      Fl_Box pwheelrnglabel {
        label {PWheel Rng (cents)}
        xywh {170 1 117 16} labelfont 3 labelsize 10 labelcolor 226
      }
      Fl_Counter pwheelbrng {
        callback {//
        send_data(0, PART::control::pitchWheelRange, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Pitch Wheel Bend Range (cents)} xywh {168 16 119 18} labelcolor 64 align 1 minimum -6400 maximum 6400 step 1 textcolor 64
        code0 {o->value(part->ctl->pitchwheel.bendrange);}
        code1 {o->lstep(100);}
      }
      Fl_Dial filtq {
        label FltQ
        callback {//
        o->selection_color(setKnob(o->value(),64));
        send_data(0, PART::control::filterQdepth, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Filter Q depth} xywh {50 55 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->filterq.depth);}
        code1 {o->selection_color(setKnob(o->value(),64));}
        class WidgetPDial
      }
      Fl_Dial fltcut {
        label FltCut
        callback {//
        o->selection_color(setKnob(o->value(),64));
        send_data(0, PART::control::filterCutoffDepth, o->value(), TOPLEVEL::type::Integer, npart);}
        tooltip {Filter Cutoff depth} xywh {90 55 30 30} labelsize 10 labelcolor 64 maximum 127 step 1
        code0 {o->value(part->ctl->filtercutoff.depth);}
        code1 {o->selection_color(setKnob(o->value(),64));}
        class WidgetPDial
      }
      Fl_Group ctlresonance {
        label Resonance
        xywh {290 15 45 85} box GTK_THIN_UP_BOX labelfont 1 labelsize 10 labelcolor 64 align 5
      } {
        Fl_Dial cfdpth {
          label CFdpth
          callback {//
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::resonanceCenterFrequencyDepth, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {Center Frequency controller Depth} xywh {300 20 25 25} labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->value(part->ctl->resonancecenter.depth);}
          code1 {o->selection_color(setKnob(o->value(),64));}
          class WidgetPDial
        }
        Fl_Dial rbwdpth {
          label BWdpth
          callback {//
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::resonanceBandwidthDepth, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {BandWidth controller depth} xywh {300 60 25 25} labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->value(part->ctl->resonancebandwidth.depth);}
          code1 {o->selection_color(setKnob(o->value(),64));}
          class WidgetPDial
        }
      }
      Fl_Box threshlabel {
        label Thresh
        xywh {400 36 48 14} labelfont 3 labelsize 10 labelcolor 226
      }
      Fl_Group ctlportamento {
        label Portamento
        xywh {340 15 160 85} box ENGRAVED_FRAME labelfont 1 labelsize 10 labelcolor 64
      } {
        Fl_Box ctlx100 {
          label {x100 cnt.}
          xywh {400 47 55 15} labelfont 3 labelsize 10 labelcolor 226 align 16
        }
        Fl_Dial prtime {
          label time
          callback {//
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::portamentoTime, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {Portamento time} xywh {345 60 25 25} labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->value(part->ctl->portamento.time);}
          code1 {o->selection_color(setKnob(o->value(),64));}
          class WidgetPDial
        }
        Fl_Dial timedu {
          label {t.dn/up}
          callback {//
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::portamentoTimeStretch, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {Portamento time stretch (up/down)} xywh {375 60 25 25} labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->value(part->ctl->portamento.updowntimestretch);}
          code1 {o->selection_color(setKnob(o->value(),64));}
          class WidgetPDial
        }
        Fl_Counter thresh {
          callback {//
          send_data(0, PART::control::portamentoThreshold, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {Minimum or max. difference of the notes in order to do the portamento (x 100 cents)} xywh {388 20 72 16} type Simple labelcolor 64 minimum 0 maximum 127 step 1
          code0 {o->value(part->ctl->portamento.pitchthresh);}
        }
        Fl_Check_Button thtype {
          label {th.type}
          callback {//
          send_data(0, PART::control::portamentoThresholdType, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {Threshold type (min/max)} xywh {425 68 15 15} down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64 align 2
          code0 {o->value(part->ctl->portamento.pitchthreshtype);}
          class Fl_Check_Button2
        }
        Fl_Dial propta {
          label {Prp.Rate}
          callback {//
          o->selection_color(setKnob(o->value(),80));
          send_data(0, PART::control::proportionalPortamentoRate, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {Distance required to double change from nonpropotinal portamento time} xywh {463 20 25 25} labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->value(part->ctl->portamento.propRate);}
          code1 {o->selection_color(setKnob(o->value(),80));}
          class WidgetPDial
        }
        Fl_Dial proptb {
          label {Prp.Dpth}
          callback {//
          o->selection_color(setKnob(o->value(),90));
          send_data(0, PART::control::proportionalPortamentoDepth, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {The difference from nonproportinal portamento} xywh {463 60 25 25} labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->value(part->ctl->portamento.propDepth);}
          code1 {o->selection_color(setKnob(o->value(),90));}
          class WidgetPDial
        }
        Fl_Check_Button rcv {
          label Rcv
          callback {//
          send_data(0, PART::control::receivePortamento, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {Receive Portamento Controllers} xywh {345 20 40 18} box THIN_UP_BOX down_box DOWN_BOX selection_color 64 labelsize 10 labelcolor 64
          code0 {o->value(part->ctl->portamento.receive);}
          class Fl_Check_Button2
        }
        Fl_Check_Button proprt {
          label {Proprt.}
          callback {//
          if (o->value())
          {
              propta->activate();
              proptb->activate();
          }
          else
          {
              propta->deactivate();
              proptb->deactivate();
          }
          send_data(0, PART::control::enableProportionalPortamento, o->value(), TOPLEVEL::type::Integer, npart);}
          tooltip {Enable Proportional Portamento (over fixed Portamento)} xywh {345 40 50 18} box THIN_UP_BOX down_box DOWN_BOX selection_color 64 labelsize 9 labelcolor 64
          code0 {o->value(part->ctl->portamento.proportional);}
          code1 {if (o->value()){propta->activate();proptb->activate();}}
          code2 {else {propta->deactivate();proptb->deactivate();}}
          class Fl_Check_Button2
        }
      }
      Fl_Button resetallctl {
        label {&Reset all controllers}
        callback {//
        send_data(TOPLEVEL::action::forceUpdate, PART::control::resetAllControllers, o->value(), TOPLEVEL::type::Integer, npart);}
        xywh {5 105 210 20} box PLASTIC_UP_BOX color 228 labelcolor 64
      }
      Fl_Button aftertouch {
        label {&Aftertouch}
        callback {//;
                ShowAT();
                atSeen = 1;
                if ((Fl::event_button() == 3))
                    ctlwindow->hide();}
        xywh {245 105 130 20} box GTK_THIN_UP_BOX color 198 labelcolor 64
      }
      Fl_Button ctlclose {
        label {&Close}
        callback {//;
        saveWin(synth, ctlwindow->w(), ctlwindow->h(), ctlwindow->x(), ctlwindow->y(), false, "Part-controllers");
        ctlSeen = false;
        lastctlW = 0;
        ctlwindow->hide();}
        xywh {405 105 95 20} box THIN_UP_BOX color 196 labelcolor 64
      }
    }
    Fl_Window aftertouchcontrol {
      label Aftertouch
      callback {//
    saveWin(synth, aftertouchcontrol->w(), aftertouchcontrol->h(), aftertouchcontrol->x(), aftertouchcontrol->y(), false, "Part-aftertouch");
    aftertouchcontrol->hide();}
      xywh {569 115 485 180} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Aftertouch"), npart, TOPLEVEL::windowTitle)).c_str());}
      code1 {atDW = o->w(); atDH = o->h();}
      code2 {o->size_range(atDW, atDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Box {} {
        xywh {9 5 228 171} box ENGRAVED_FRAME
      }
      Fl_Box {} {
        xywh {241 5 234 143} box ENGRAVED_FRAME
      }
      Fl_Box ATchan {
        label Channel
        xywh {95 13 35 17} labelfont 1 labelcolor 64
      }
      Fl_Button channeloff {
        label Off
        callback {//
                channelfiltercutoff->value(0);
                channelfilterCminus->value(0);
                channelfilterCminus->deactivate();
                channelfilterQ->value(0);
                channelfilterQminus->value(0);
                channelfilterQminus->deactivate();
                channelpitchbend->value(0);
                channelpitchBminus->value(0);
                channelpitchBminus->deactivate();
                channelmodulation->value(0);
                channelvolume->value(0);
                setATchannel(PART::aftertouchType::off, true);}
        xywh {55 40 48 20} box PLASTIC_UP_BOX color 228 labelcolor 64
      }
      Fl_Check_Button channelfiltercutoff {
        label {Filter Cutoff}
        callback {//
                if (o->value())
                    channelfilterCminus->activate();
                else
                {
                    channelfilterCminus->value(0);
                    channelfilterCminus->deactivate();
                }
                setATchannel(PART::aftertouchType::filterCutoff, o->value());}
        tooltip {Between current MIDI setting and max.} xywh {25 65 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Check_Button channelfilterCminus {
        label Down
        callback {//
                setATchannel(PART::aftertouchType::filterCutoffDown, o->value());}
        tooltip {Between current MIDI setting and zero} xywh {150 65 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64 deactivate
        class Fl_Check_Button2
      }
      Fl_Check_Button channelfilterQ {
        label {Filter Q}
        callback {//
                if (o->value())
                    channelfilterQminus->activate();
                else
                {
                    channelfilterQminus->value(0);
                    channelfilterQminus->deactivate();
                }
                setATchannel(PART::aftertouchType::filterQ, o->value());}
        tooltip {Between current MIDI setting and max.} xywh {25 85 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Check_Button channelfilterQminus {
        label Down
        callback {//
                setATchannel(PART::aftertouchType::filterQdown, o->value());}
        tooltip {Between current MIDI setting and zero} xywh {150 85 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64 deactivate
        class Fl_Check_Button2
      }
      Fl_Check_Button channelpitchbend {
        label {Pitch Bend}
        callback {//
                if (o->value())
                    channelpitchBminus->activate();
                else
                {
                    channelpitchBminus->value(0);
                    channelpitchBminus->deactivate();
                }
                setATchannel(PART::aftertouchType::pitchBend, o->value());}
        tooltip {Between current pitch wheel position and max.} xywh {25 105 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Check_Button channelpitchBminus {
        label Down
        callback {//
                setATchannel(PART::aftertouchType::pitchBendDown, o->value());}
        tooltip {Between current pitch wheel position and min.} xywh {150 105 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64 deactivate
        class Fl_Check_Button2
      }
      Fl_Check_Button channelmodulation {
        label Modulation
        callback {//
                setATchannel(PART::aftertouchType::modulation, o->value());}
        tooltip {Between zero and Add/Pad frequency LFO depth} xywh {25 125 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Check_Button channelvolume {
        label Volume
        callback {//
                setATchannel(PART::aftertouchType::volume, o->value());}
        tooltip {Between current part volume and max.} xywh {25 145 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Box ATkey {
        label Key
        xywh {328 13 35 17} labelfont 1 labelcolor 64
      }
      Fl_Button polyoff {
        label Off
        callback {//
                polyfiltercutoff->value(0);
                polyfilterCminus->value(0);
                polyfilterCminus->deactivate();
                polyfilterQ->value(0);
                polyfilterQminus->value(0);
                polyfilterQminus->deactivate();
                polypitchbend->value(0);
                polypitchBminus->value(0);
                polypitchBminus->deactivate();
                polymodulation->value(0);
                setATkey(PART::aftertouchType::off, true);}
        xywh {300 40 48 20} box PLASTIC_UP_BOX color 228 labelcolor 64
      }
      Fl_Check_Button polyfiltercutoff {
        label {Filter Cutoff}
        callback {//
                if (o->value())
                    polyfilterCminus->activate();
                else
                {
                    polyfilterCminus->value(0);
                    polyfilterCminus->deactivate();
                }
                setATkey(PART::aftertouchType::filterCutoff, o->value());}
        tooltip {Between current MIDI setting and max.} xywh {270 65 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Check_Button polyfilterCminus {
        label Down
        callback {//
                setATkey(PART::aftertouchType::filterCutoffDown, o->value());}
        tooltip {Between current MIDI setting and zero} xywh {395 65 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64 deactivate
        class Fl_Check_Button2
      }
      Fl_Check_Button polyfilterQ {
        label {Filter Q}
        callback {//
                if (o->value())
                    polyfilterQminus->activate();
                else
                {
                    polyfilterQminus->value(0);
                    polyfilterQminus->deactivate();
                }
                setATkey(PART::aftertouchType::filterQ, o->value());}
        tooltip {Between current MIDI setting and max.} xywh {270 85 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Check_Button polyfilterQminus {
        label Down
        callback {//
                setATkey(PART::aftertouchType::filterQdown, o->value());}
        tooltip {Between current MIDI setting and zero} xywh {395 85 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64 deactivate
        class Fl_Check_Button2
      }
      Fl_Check_Button polypitchbend {
        label {Pitch Bend}
        callback {//
                if (o->value())
                    polypitchBminus->activate();
                else
                {
                    polypitchBminus->value(0);
                    polypitchBminus->deactivate();
                }
                setATkey(PART::aftertouchType::pitchBend, o->value());}
        tooltip {Between current pitch wheel position and max.} xywh {270 105 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Check_Button polypitchBminus {
        label Down
        callback {//
                setATkey(PART::aftertouchType::pitchBendDown, o->value());}
        tooltip {Between current pitch wheel position and min.} xywh {395 105 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64 deactivate
        class Fl_Check_Button2
      }
      Fl_Check_Button polymodulation {
        label Modulation
        callback {//
                setATkey(PART::aftertouchType::modulation, o->value());}
        tooltip {Between zero and Add/Pad frequency LFO depth} xywh {270 125 70 15} down_box DOWN_BOX selection_color 64 labelcolor 64
        class Fl_Check_Button2
      }
      Fl_Button atClose {
        label {&Close}
        callback {//
        saveWin(synth, aftertouchcontrol->w(), aftertouchcontrol->h(), aftertouchcontrol->x(), aftertouchcontrol->y(), false, "Part-aftertouch");
        if ((Fl::event_button() == 3))
        {
            if (atSeen > 1)
                instrumenteditwindow->show();
            else
                ctlwindow->show();
        }
        atSeen = 0;
        aftertouchcontrol->hide();}
        xywh {420 154 50 20} box THIN_UP_BOX color 196 labelcolor 64
      }
    }
  }
  Function {send_data(int action, int control, float value, int type, int npart, int kititem = UNUSED, int engine = UNUSED, int insert = UNUSED, int parameter = UNUSED, int miscmsg = UNUSED)} {} {
    code {//
        type |= TOPLEVEL::type::Write;
        collect_writeData(synth, value, action, type, control, npart, kititem, engine, insert, parameter, UNUSED, miscmsg);} {}
  }
  Function {fetchData(float value, int control, int part, int kititem = UNUSED, int engine = UNUSED, int insert = UNUSED, int parameter = UNUSED, int offset = UNUSED, int miscmsg = UNUSED, int request = UNUSED)} {return_type float
  } {
    code {//
        return collect_readData(synth, value, control, part, kititem, engine, insert, parameter, offset, miscmsg, request);} {}
  }
  Function {returns_update(CommandBlock *getData)} {} {
    code {//
    float value = getData->data.value;
    unsigned char control = getData->data.control;
    unsigned char newpart = getData->data.part;
    unsigned char kititem = getData->data.kit;
    unsigned char engine = getData->data.engine;
    unsigned char insert = getData->data.insert;
    unsigned char parameter = getData->data.parameter;
    unsigned char miscmsg = getData->data.miscmsg;
    bool valBool = _SYS_::F2B(value);
    int valInt = lrint(value);
    string text;
    if (miscmsg != NO_MSG)
        text = textMsgBuffer.fetch(miscmsg);
    if (npart != newpart)
        return;

    bool forCurrentEff = (engine == inseffectui->effNum());
    bool kitType = (insert == TOPLEVEL::insert::kitGroup);
    if (!kitType)
        kititem = 0;
    switch(control)
    {
        case PART::control::enableAdd:
            partkititem[kititem]->adcheck->value(valBool);
            if (valBool)
            {
                partkititem[kititem]->adeditbutton->activate();
                if (kititem == 0)
                {
                    adsynenabledcheck->value(1);
                    adeditbutton->activate();
                }
            }
            else
            {
                partkititem[kititem]->adeditbutton->deactivate();
                if (kititem == 0)
                {
                    adsynenabledcheck->value(0);
                    adeditbutton->deactivate();
                }
            }
            break;
        case PART::control::enableSub:
            partkititem[kititem]->subcheck->value(valBool);
            if (valBool)
            {
                partkititem[kititem]->subeditbutton->activate();
                if (kititem == 0)
                {
                    subsynenabledcheck->value(1);
                    subeditbutton->activate();
                }
            }
            else
            {
                partkititem[kititem]->subeditbutton->deactivate();
                if (kititem == 0)
                {
                    subsynenabledcheck->value(0);
                    subeditbutton->deactivate();
                }
            }
            break;
        case PART::control::enablePad:
            partkititem[kititem]->padcheck->value(valBool);
            if (valBool)
            {
                partkititem[kititem]->padeditbutton->activate();
                if (kititem ==0)
                {
                    padsynenabledcheck->value(1);
                    padeditbutton->activate();
                }
            }
            else
            {
                partkititem[kititem]->padeditbutton->deactivate();
                if (kititem ==0)
                {
                    padsynenabledcheck->value(0);
                    padeditbutton->deactivate();
                }
            }
            break;
        case PART::control::enableKitLine:
            partkititem[kititem]->enabledcheck->value(valBool);
            if (valBool)
                partkititem[kititem]->partkititemgroup->activate();
            else
                partkititem[kititem]->clearLine();
            break;
        case PART::control::channelATset:
            channelATselection = valInt;
            fetchChannel();
            if (parameter != UNUSED)
            {
                keyATselection = parameter;
                fetchKey();
            }
            break;
        case PART::control::keyATset:
            keyATselection = valInt;
            fetchKey();
            if (parameter != UNUSED)
            {
                channelATselection = parameter;
                fetchChannel();
            }
            break;

        case PART::control::kitItemMute:
            partkititem[kititem]->mutedcheck->value(valBool);
            break;
        case PART::control::minNote:
        case PART::control::minToLastKey: // this will have been modified for last key press
            partkititem[kititem]->minkcounter->value(valInt);
            break;

        case PART::control::maxNote:
        case PART::control::maxToLastKey: // this will have been modified for last key press
            partkititem[kititem]->maxkcounter->value(valInt);
            break;

        case PART::control::resetMinMaxKey:
            partkititem[kititem]->minkcounter->value(0);
            partkititem[kititem]->maxkcounter->value(127);
            break;

        case PART::control::kitEffectNum:
            partkititem[kititem]->sendtoeffect->value(valInt);
            break;

        case PART::control::humanise:
            humanise->value(valInt);
            humanise->selection_color(setSlider(humanise->value(),0));
            break;

        case PART::control::humanvelocity:
            velocityhumanise->value(valInt);
            velocityhumanise->selection_color(setSlider(velocityhumanise->value(),0));
            break;


        case PART::control::drumMode:
            drumMode->value(valBool);
            break;

        case PART::control::kitMode:
            if (part->PkitfadeType == 1)
            {
                kitMode->value(3);
            }
            else
            {
                kitMode->value(valInt);
            }
            partKitOn =  (kitMode->value() > 0);
            if (partKitOn > 0)
                kitlist->activate();
            else
                kitlist->deactivate();
            break;

        case PART::control::effectNumber:
            refreshEffUI();
            if (forCurrentEff)
                inseffectui->UpdatePresetColour(parameter, insefftype->value());
            else
            {
                lastfxW = 0;
                lastDynFiltW = 0;
            }
            break;

        case PART::control::effectType:
            if (forCurrentEff)
            {   // changing effect type always sets default values
                refreshEffUI();
                inseffectui->UpdatePresetColour(0, insefftype->value());
                fxRtext();
            }
            break;

        case PART::control::effectDestination:
            if (forCurrentEff)
                sendtochoice->value(inseffectui->getPartFxRouting());
            break;

        case PART::control::effectBypass:
            if (forCurrentEff)
                bypasseff->value(inseffectui->getPartFxBypass());
            break;

// controllers
        case PART::control::volumeRange:
            volrng->value(valInt);
            volrng->selection_color(setKnob(valInt,96));
            break;

        case PART::control::volumeEnable:
            vol->value(valInt);
            break;

        case PART::control::panningWidth:
            panwidth->value(valInt);
            panwidth->selection_color(setKnob(valInt,64));
            break;

        case PART::control::modWheelDepth:
            modwh->value(valInt);
            modwh->selection_color(setKnob(valInt,80));
            break;

        case PART::control::exponentialModWheel:
            expmwh->value(valInt);
            break;

        case PART::control::bandwidthDepth:
            bwdpth->value(valInt);
            bwdpth->selection_color(setKnob(valInt,64));
            break;

        case PART::control::exponentialBandwidth:
            expbw->value(valInt);
            break;

        case PART::control::expressionEnable:
            expr->value(valInt);
            break;

        case PART::control::FMamplitudeEnable:
            fmamp->value(valInt);
            break;

        case PART::control::sustainPedalEnable:
            sustain->value(valInt);
            break;

        case PART::control::pitchWheelRange:
            pwheelbrng->value(valInt);
            break;

        case PART::control::filterQdepth:
            filtq->value(valInt);
            filtq->selection_color(setKnob(valInt,64));
            break;

        case PART::control::filterCutoffDepth:
            fltcut->value(valInt);
            fltcut->selection_color(setKnob(valInt,64));
            break;

        case PART::control::breathControlEnable:
            breath->value(valBool);
            break;

        case PART::control::resonanceCenterFrequencyDepth:
            cfdpth->value(valInt);
            cfdpth->selection_color(setKnob(valInt,64));
            break;

        case PART::control::resonanceBandwidthDepth:
            rbwdpth->value(valInt);
            rbwdpth->selection_color(setKnob(valInt,64));
            break;

        case PART::control::portamentoTime:
            prtime->value(valInt);
            prtime->selection_color(setKnob(valInt,64));
            break;

        case PART::control::portamentoTimeStretch:
            timedu->value(valInt);
            timedu->selection_color(setKnob(valInt,64));
            break;

        case PART::control::portamentoThreshold:
            thresh->value(valInt);
            break;

        case PART::control::portamentoThresholdType:
            thtype->value(valInt);
            break;

        case PART::control::enableProportionalPortamento:
            proprt->value(valInt);
            if (value != 0)
            {
                propta->activate();
                proptb->activate();
            }
            else
            {
                propta->deactivate();
                proptb->deactivate();
            }
            break;

        case PART::control::proportionalPortamentoRate:
            propta->value(valInt);
            propta->selection_color(setKnob(valInt,80));
            break;

        case PART::control::proportionalPortamentoDepth:
            proptb->value(valInt);
            proptb->selection_color(setKnob(valInt,90));
            break;

        case PART::control::receivePortamento:
            rcv->value(valInt);
            break;

        case PART::control::midiModWheel:
            modulation->value(value);
            modulation->selection_color(setKnob(value,64));
            break;
        case PART::control::midiExpression:
            expression->value(value);
            expression->selection_color(setKnob(value,127));
            break;
        case PART::control::midiFilterQ:
            filterq->value(value);
            filterq->selection_color(setKnob(value,64));
            break;
        case PART::control::midiFilterCutoff:
            filtercutoff->value(value);
            filtercutoff->selection_color(setKnob(value,64));
            break;
        case PART::control::midiBandwidth:
            masterbandwidth->value(value);
            masterbandwidth->selection_color(setKnob(value,64));
            break;

        case PART::control::instrumentCopyright:
            copyright->value(text.c_str());
            break;
        case PART::control::instrumentComments:
            commentField->value(text.c_str());
            break;
        case PART::control::instrumentName:
            partkititem[kititem]->labelbutton->copy_label(text.c_str());
            break;
        case PART::control::instrumentType:
            instrumentType->value(value);
            break;
        case PART::control::defaultInstrumentCopyright:
            if (parameter == 0)
                copyright->value(text.c_str());
            break;
        case PART::control::resetAllControllers:
            controllersrefresh();
            break;
        default:
            break;
    }
    if (control == PART::control::enableAdd || control == PART::control::enableSub || control == PART::control::enablePad)
        checkEngines();
    ;} {}
  }
  Function {paste(CommandBlock *getData)} {} {
    code {//
        int kititem = getData->data.kit;
        int engine = getData->data.engine;
        int insert = getData->data.insert;

        if (kititem >= EFFECT::type::none && kititem < EFFECT::type::count)
        {
            bool show = partfx->visible() && engine == inseffectui->effNum();
            effectsrefresh();
            if (show)
                partfx->show();
            return;
        }

        if (kititem != lastkititem)
            return; // only update engines if current kititem;
        if (engine >= PART::engine::addVoice1 && engine < PART::engine::addVoiceModEnd)
        {
            int voiceNum = (engine - PART::engine::addVoice1);
            //std::cout << "voice " << voiceNum << std::endl;
            if (insert == TOPLEVEL::insert::oscillatorGroup)
            {
                adnoteui->advoice->paste();
                return;
            }

            if (voiceNum == adnoteui->nvoice)
            {
                if(adnoteui->ADnoteVoice->visible())
                {
                    adnoteui->editVoice(voiceNum);
                }
            }
            return;
        }

        if (engine == PART::engine::addSynth)
        {
            if (getData->data.insert == TOPLEVEL::insert::resonanceGroup)
            {
                //std::cout << "in Resonance" << std::endl;
                if (adnoteui)
                    adnoteui->paste(getData);
                return;
            }
            //std::cout << "add top level " << engine << std::endl;
            if (adnoteui != NULL)
            {
                if (adnoteui->ADnoteGlobalParameters->visible())
                    adnoteui ->refresh();
            }
            return;
        }
        //std::cout << "Next section" << std::endl;

        if (engine == PART::engine::subSynth)
        {

            //std::cout << "sub top level" << std::endl;
            if (subnoteui != NULL)
            {
                if (subnoteui->SUBparameters->visible())
                    subnoteui->refresh();
            }
            return;
        }

        if (engine == PART::engine::padSynth)
        {
            if (getData->data.insert == TOPLEVEL::insert::resonanceGroup)
            {
                if (padnoteui)
                    padnoteui->paste(getData);
                return;
            }
            //std::cout << "pad top level" << std::endl;
            if (padnoteui != NULL)
            {
                if(padnoteui->padnotewindow->visible())
                    padnoteui->refresh();
            }
            return;
        }

        std::cout << "invalid paste" << std::endl;} {}
  }
  Function {PartUI(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} {
    code {//
    part = NULL;
    adnoteui = NULL;
    subnoteui = NULL;
    padnoteui = NULL;
    editSeen = false;
    fxSeen = false;
    kitSeen = false;
    ctlSeen = false;
    ctlmidiSeen = false;
    atSeen = false;
    lastfxW = 0;
    lastDynFiltW = 0;
    lastkitW = 0;
    lastmidiW = 0;
    lastatW = 0;
    lastkititem = -1;} {}
  }
  Function {rebuild(int npart_)} {} {
    code {//
        if (adnoteui != NULL)
        {
            delete adnoteui;
            adnoteui = NULL;
        }
        if (subnoteui != NULL)
        {
            delete subnoteui;
            subnoteui = NULL;
        }
        if (padnoteui != NULL)
        {
            delete padnoteui;
            padnoteui = NULL;
        }
        npart = npart_;
        part = synth->part[npart];
        lastkey = -1;

        if (part->kit[0].adpars)
            adnoteui = new ADnoteUI(part->kit[0].adpars, npart, 0);
        if (part->kit[0].subpars)
            subnoteui = new SUBnoteUI(part->kit[0].subpars, npart, 0);
        if (part->kit[0].padpars)
            padnoteui = new PADnoteUI(part->kit[0].padpars);

        checkEngines();
        editrefresh();
        effectsrefresh();
        kitrefresh();
        controllersrefresh();
        ctlmidirefresh();
        ATrefresh();} {}
  }
  Function {fillInstrumentType()} {} {
    code {//

        int i = 0;
        string entry = type_list[i];
        while (entry != "@end")
        {
            instrumentType->add(entry.c_str());
            ++ i;
            entry = type_list[i];
        }} {}
  }
  Function {editrefresh()} {} {
    code {//
        instrumenteditwindow->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Edit"), npart, TOPLEVEL::windowTitle)).c_str());
        setinstrumentlabel();
        instrumenteditwindow->redraw();
        fillInstrumentType();
        copyright->value(part->info.Pauthor.c_str());
        commentField->value(part->info.Pcomments.c_str());
        string name = part->Poriginal;
        if (!name.empty() && name != UNTITLED && part->Pname != name)
        {
            originaltext->copy_label(name.c_str());
            originalname->show();
            originaltext->show();
        }
        else
        {
            originalname->hide();
            originaltext->hide();
        }
        instrumentType->value(part->info.Ptype);
        humanise->value(fetchData(0, PART::control::humanise, npart));
            humanise->selection_color(setSlider(humanise->value(),0));
        velocityhumanise->value(fetchData(0, PART::control::humanvelocity, npart));
            velocityhumanise->selection_color(setSlider(velocityhumanise->value(),0));} {}
  }
  Function {effectsrefresh()} {} {
    code {//
        partfx->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Effects"), npart, TOPLEVEL::windowTitle)).c_str());
        refreshEffUI();
        bool isChanged = inseffectui->isChanged();
        inseffectui->UpdatePresetColour(isChanged, insefftype->value());
        lastfxW = 0;
        lastDynFiltW = 0;} {}
  }
  Function {kitrefresh()} {} {
    code {//
        instrumentkitlist->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Kit List"), npart, TOPLEVEL::windowTitle)).c_str());
        drumMode->value(part->Pdrummode);
            if (part->PkitfadeType == 1)
            {
                kitMode->value(3);
            }
            else
            {
                kitMode->value(part->Pkitmode);
            }
        if (kitMode->value())
        {
            partKitOn = true;
            kitlist->activate();
        }
        else
        {
            partKitOn = false;
            kitlist->deactivate();
        }
        lastkititem = -1;
        for (int i = 0; i < NUM_KIT_ITEMS; ++i)
        {
            if (part->kit[i].Penabled)
            {
                partkititem[i]->enabledcheck->value(1);
                partkititem[i]->partkititemgroup->activate();
                partkititem[i]->mutedcheck->value(!part->kit[i].Penabled);

                partkititem[i]->adcheck->value(part->kit[i].Padenabled);
                if (partkititem[i]->adcheck->value())
                    partkititem[i]->adeditbutton->activate();
                else
                    partkititem[i]->adeditbutton->deactivate();
                partkititem[i]->subcheck->value(part->kit[i].Psubenabled);
                if (partkititem[i]->subcheck->value())
                    partkititem[i]->subeditbutton->activate();
                else
                    partkititem[i]->subeditbutton->deactivate();
                partkititem[i]->padcheck->value(part->kit[i].Ppadenabled);
                if (partkititem[i]->padcheck->value())
                    partkititem[i]->padeditbutton->activate();
                else
                    partkititem[i]->padeditbutton->deactivate();
            }
            else
            {
                partkititem[i]->enabledcheck->value(0);
                partkititem[i]->partkititemgroup->deactivate();
                partkititem[i]->mutedcheck->value(0);
                partkititem[i]->adcheck->value(0);
                partkititem[i]->adeditbutton->deactivate();
                partkititem[i]->subcheck->value(0);
                partkititem[i]->subeditbutton->deactivate();
                partkititem[i]->padcheck->value(0);
                partkititem[i]->padeditbutton->deactivate();
            }
            partkititem[i]->labelbutton->copy_label(part->kit[i].Pname.c_str());
            partkititem[i]->minkcounter->value(part->kit[i].Pminkey);
            partkititem[i]->maxkcounter->value(part->kit[i].Pmaxkey);
            int effnum = part->kit[i].Psendtoparteffect + 1;
            if (effnum > 3)
                effnum = 0;
            partkititem[i]->sendtoeffect->value(effnum);
        }} {}
  }
  Function {controllersrefresh()} {} {
    code {//
    ctlwindow->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Controllers"), npart, TOPLEVEL::windowTitle)).c_str());
    expmwh->value(part->ctl->modwheel.exponential);
    modwh->value(part->ctl->modwheel.depth);
        modwh->selection_color(setKnob(modwh->value(),80));
    expbw->value(part->ctl->bandwidth.exponential);
    bwdpth->value(part->ctl->bandwidth.depth);
        bwdpth->selection_color(setKnob(bwdpth->value(),64));
    pwheelbrng->value(part->ctl->pitchwheel.bendrange);
    panwidth->value(part->ctl->panning.depth);
        panwidth->selection_color(setKnob(panwidth->value(),64));
    filtq->value(part->ctl->filterq.depth);
        filtq->selection_color(setKnob(filtq->value(),64));
    fltcut->value(part->ctl->filtercutoff.depth);
        fltcut->selection_color(setKnob(fltcut->value(),64));
    volrng->value(part->ctl->volume.data);
        volrng->selection_color(setKnob(volrng->value(),96));
    expr->value(part->ctl->expression.receive);
    fmamp->value(part->ctl->fmamp.receive);
    vol->value(part->ctl->volume.receive);
    sustain->value(part->ctl->sustain.receive);
    breath->value(part->PbreathControl == MIDI::CC::breath);

    cfdpth->value(part->ctl->resonancecenter.depth);
        cfdpth->selection_color(setKnob(cfdpth->value(),64));
    rbwdpth->value(part->ctl->resonancebandwidth.depth);
        rbwdpth->selection_color(setKnob(rbwdpth->value(),64));

    rcv->value(part->ctl->portamento.receive);
    thresh->value(part->ctl->portamento.pitchthresh);
    propta->value(part->ctl->portamento.propRate);
        propta->selection_color(setKnob(propta->value(),80));
    proprt->value(part->ctl->portamento.proportional);
    if (proprt->value())
    {
        propta->activate();
        proptb->activate();
    }
    else
    {
        propta->deactivate();
        proptb->deactivate();
    }
    prtime->value(part->ctl->portamento.time);
        prtime->selection_color(setKnob(prtime->value(),64));
    timedu->value(part->ctl->portamento.updowntimestretch);
        timedu->selection_color(setKnob(timedu->value(),64));
    thtype->value(part->ctl->portamento.pitchthreshtype);
    proptb->value(part->ctl->portamento.propDepth);
            proptb->selection_color(setKnob(proptb->value(),90));} {}
  }
  Function {ctlmidirefresh()} {} {
    code {//
        ctlmidi->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("MIDI Controls"), npart, TOPLEVEL::windowTitle)).c_str());
        modulation->value(part->ctl->modwheel.data);
            modulation->selection_color(setKnob(modulation->value(),64));
        expression->value(part->ctl->expression.data);
            expression->selection_color(setKnob(expression->value(),127));
        filterq->value(part->ctl->filterq.data);
            filterq->selection_color(setKnob(filterq->value(),64));
        filtercutoff->value(part->ctl->filtercutoff.data);
            filtercutoff->selection_color(setKnob(filtercutoff->value(),64));
        masterbandwidth->value(part->ctl->bandwidth.data);
            masterbandwidth->selection_color(setKnob(masterbandwidth->value(),64));} {}
  }
  Function {ATrefresh()} {} {
    code {//
    aftertouchcontrol->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Aftertouch"), npart, TOPLEVEL::windowTitle)).c_str());


    channelATselection = int(fetchData(0, PART::control::channelATset, npart));
    fetchChannel();
    keyATselection = int(fetchData(0, PART::control::keyATset, npart));
    fetchKey();} {}
  }
  Function {fetchChannel()} {} {
    code {//
            channelfiltercutoff->value(0); // clear settings first
            channelfilterCminus->value(0);
            channelfilterCminus->deactivate();
            channelfilterQ->value(0);
            channelfilterQminus->value(0);
            channelfilterQminus->deactivate();
            channelpitchbend->value(0);
            channelpitchBminus->value(0);
            channelpitchBminus->deactivate();
            channelmodulation->value(0);
            channelvolume->value(0);


    if (channelATselection & PART::aftertouchType::filterCutoff)
    {
         channelfiltercutoff->value(1);
         channelfilterCminus->activate();
         if (channelATselection & PART::aftertouchType::filterCutoffDown)
             channelfilterCminus->value(1);
    }
    if (channelATselection & PART::aftertouchType::filterQ)
    {
         channelfilterQ->value(1);
         channelfilterQminus->activate();
         if (channelATselection & PART::aftertouchType::filterQdown)
             channelfilterQminus->value(1);
    }
    if (channelATselection & PART::aftertouchType::pitchBend)
    {
        channelpitchbend->value(1);
         channelpitchBminus->activate();
        if (channelATselection & PART::aftertouchType::pitchBendDown)
            channelpitchBminus->value(1);
    }
    if (channelATselection & PART::aftertouchType::modulation)
        channelmodulation->value(1);
    if (channelATselection & PART::aftertouchType::volume)
        channelvolume->value(1);} {}
  }
  Function {fetchKey()} {} {
    code {//
            polyfiltercutoff->value(0); // clear settings first
            polyfilterCminus->value(0);
            polyfilterCminus->deactivate();
            polyfilterQ->value(0);
            polyfilterQminus->value(0);
            polyfilterQminus->deactivate();
            polypitchbend->value(0);
            polypitchBminus->value(0);
            polypitchBminus->deactivate();
            polymodulation->value(0);

    if (keyATselection & PART::aftertouchType::filterCutoff)
    {
         polyfiltercutoff->value(1);
         polyfilterCminus->activate();
         if (keyATselection & PART::aftertouchType::filterCutoffDown)
             polyfilterCminus->value(1);
    }
    if (keyATselection & PART::aftertouchType::filterQ)
    {
         polyfilterQ->value(1);
         polyfilterQminus->activate();
         if (keyATselection & PART::aftertouchType::filterQdown)
             polyfilterQminus->value(1);
    }
    if (keyATselection & PART::aftertouchType::pitchBend)
    {
        polypitchbend->value(1);
         polypitchBminus->activate();
        if (keyATselection & PART::aftertouchType::pitchBendDown)
            polypitchBminus->value(1);
    }
    if (keyATselection & PART::aftertouchType::modulation)
        polymodulation->value(1);} {}
  }
  Function {setATchannel(int type, int state)} {} {
    code {//
        if (type == PART::aftertouchType::off)
            channelATselection = 0;
        else
        {
            if (state > 0)
            {
                channelATselection |= type;
                if (keyATselection & type)
                {
                    keyATselection &= ~type;
                    fetchKey();
                }

            }
            else
            {
                channelATselection &= ~type;
                if (type == PART::aftertouchType::filterCutoff)
                    channelATselection &= ~PART::aftertouchType::filterCutoffDown;
                else if (type == PART::aftertouchType::filterQ)
                    channelATselection &= ~PART::aftertouchType::filterQdown;
                else if (type == PART::aftertouchType::pitchBend)
                    channelATselection &= ~PART::aftertouchType::pitchBendDown;
            }
        }
        send_data(0, PART::channelATset, channelATselection, TOPLEVEL::type::Integer, npart);} {}
  }
  Function {setATkey(int type, int state)} {} {
    code {//
        if (type == PART::aftertouchType::off)
            keyATselection = 0;
        else
        {
            if (state > 0)
            {
                keyATselection |= type;
                if (channelATselection & type)
                {
                    channelATselection &= ~type;
                    fetchChannel();
                }
            }
            else
            {
                keyATselection &= ~type;
                if (type == PART::aftertouchType::filterCutoff)
                    keyATselection &= ~PART::aftertouchType::filterCutoffDown;
                else if (type == PART::aftertouchType::filterQ)
                    keyATselection &= ~PART::aftertouchType::filterQdown;
                else if (type == PART::aftertouchType::pitchBend)
                    keyATselection &= ~PART::aftertouchType::pitchBendDown;
            }
        }
        send_data(0, PART::keyATset, keyATselection, TOPLEVEL::type::Integer, npart);} {}
  }
  Function {init(Part *part_,int npart_,BankUI *bankui_)} {} {
    code {//
    synth = part_->getSynthEngine();
    bankui = bankui_;
    part = part_;
    npart = npart_;
    plgroup = &synth->getGuiMaster()->panelgroup;
    make_window();
    end();} {}
  }
  Function {checkEngines(string instrumentName = "")} {} {
    code {//
    engine = 0;
    if (instrumentName == "")
        instrumentName = part->Pname;
    partname = instrumentName;

    if (part->kit[0].Padenabled)
    {
        engine |= 1;
        adsynenabledcheck->value(1);
        adeditbutton->activate();
        addbox->color(add_back);
    }
    else
    {
        adsynenabledcheck->value(0);
        adeditbutton->deactivate();
        addbox->color(FL_BACKGROUND_COLOR);
    }
    if (part->kit[0].Psubenabled)
    {
        engine |= 2;
        subsynenabledcheck->value(1);
        subeditbutton->activate();
        subbox->color(sub_back);
    }
    else
    {
        subsynenabledcheck->value(0);
        subeditbutton->deactivate();
        subbox->color(FL_BACKGROUND_COLOR);
    }
    if (part->kit[0].Ppadenabled)
    {
        engine |= 4;
        padsynenabledcheck->value(1);
        padeditbutton->activate();
        padbox->color(pad_back);
    }
    else
    {
        padsynenabledcheck->value(0);
        padeditbutton->deactivate();
        padbox->color(FL_BACKGROUND_COLOR);
    }
    engine = collect_readData(synth, 0, PART::control::instrumentEngines, npart);
    synth->getGuiMaster()->updateEngines(engine, instrumentName);} {}
  }
  Function {showparameters(int kititem, int engine)} {} {
    code {//
    kitname = part->kit[kititem].Pname;
    if (engine == -1)
    {   // this is used if I want to clear the engine from the part
        if (kititem == lastkititem)
            kititem = -1;
        else
            kititem = lastkititem;
    }
    checkEngines();

    if (kititem != lastkititem)
    {
        if (adnoteui != NULL)
            delete adnoteui;
        if (subnoteui != NULL)
            delete subnoteui;
        if (padnoteui != NULL)
            delete padnoteui;
        adnoteui = NULL;
        subnoteui = NULL;
        padnoteui = NULL;
        lastkititem = kititem;
        if (kititem >= NUM_KIT_ITEMS)
            return; // bad kit item
        if (kititem < 0)
            return;

        if (part->kit[kititem].adpars)
            adnoteui = new ADnoteUI(part->kit[kititem].adpars, npart, lastkititem);

        if (part->kit[kititem].subpars)
            subnoteui = new SUBnoteUI(part->kit[kititem].subpars, npart, lastkititem);

        if (part->kit[kititem].padpars)
            padnoteui = new PADnoteUI(part->kit[kititem].padpars);
    }

    if (engine == 0 && adnoteui != NULL)
        adnoteui->ShowGlobal();
    if (engine == 1 && subnoteui != NULL)
        subnoteui->Showsub();
    if (engine == 2 && padnoteui != NULL)
        padnoteui->Showpad();} {}
  }
  Function {setinstrumentlabel(string text = "")} {} {
    code {//
    engine = 0;

    for (int i = 0; i < NUM_KIT_ITEMS; ++i)
    {
        if (part->kit[i].Padenabled)
            engine |= 1;
        if (part->kit[i].Psubenabled)
            engine |= 2;
        if (part->kit[i].Ppadenabled)
            engine |= 4;
    }
    if (engine & 1)
        synth->getGuiMaster()->instrumentaddbox->color(add_back);
    else
        synth->getGuiMaster()->instrumentaddbox->color(bank_back_used);

    if (engine & 2)
        synth->getGuiMaster()->instrumentsubbox->color(sub_back);
    else
        synth->getGuiMaster()->instrumentsubbox->color(bank_back_used);

    if (engine & 4)
        synth->getGuiMaster()->instrumentpadbox->color(pad_back);
    else
        synth->getGuiMaster()->instrumentpadbox->color(bank_back_used);

    if (part->PyoshiType)
        synth->getGuiMaster()->instrumentlabel->labelcolor(yoshi_ins_typ);
    else
        synth->getGuiMaster()->instrumentlabel->labelcolor(gen_text);
    if (text == "")
        text = part->Pname.c_str();
    partname = text;
    synth->getGuiMaster()->instrumentlabel->copy_label(text.c_str());} {}
  }
  Function {refreshEffUI()} {} {
    code {//
        insefftype->value(inseffectui->effType());
        inseffnocounter->value(inseffectui->effNum() + 1);
        inseffectui->refresh(npart);
        bypasseff->value(inseffectui->getPartFxBypass());
        sendtochoice->value(inseffectui->getPartFxRouting());} {}
  }
  Function {seteditname()} {} {
    code {//
    instrumenteditwindow->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Edit"), npart, TOPLEVEL::windowTitle)).c_str());} {}
  }
  Function {Showedit()} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Part-edit");

    if (fetchW < editDW || fetchH < editDH)
    {
        fetchW = editDW;
        fetchH = editDH;
    }
    checkSane(fetchX, fetchY, fetchW, fetchH, editDW, editDH);

    instrumenteditwindow->resize(fetchX, fetchY, fetchW, fetchH);
    lasteditW = 0;
    instrumenteditwindow->show();
    editSeen = true;} {}
  }
  Function {Showctl()} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Part-controllers");

    if (fetchW < ctlDW || fetchH < ctlDH)
    {
        fetchW = ctlDW;
        fetchH = ctlDH;
    }
    checkSane(fetchX, fetchY, fetchW, fetchH, ctlDW, ctlDH);

    ctlwindow->resize(fetchX, fetchY, fetchW, fetchH);
    lastctlW = 0;
    ctlwindow->show();
    ctlSeen = true;} {}
  }
  Function {ShowAT()} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Part-aftertouch");

    if (fetchW < atDW || fetchH < atDH)
    {
        fetchW = atDW;
        fetchH = atDH;
    }
    checkSane(fetchX, fetchY, fetchW, fetchH, atDW, atDH);

    aftertouchcontrol->resize(fetchX, fetchY, fetchW, fetchH);
    aftertouchcontrol->show();} {}
  }
  Function {Showctlmidi()} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Part-ctlmidi");

    if (fetchW < midiDW || fetchH < midiDH)
    {
        fetchW = midiDW;
        fetchH = midiDH;
    }
    checkSane(fetchX, fetchY, fetchW, fetchH, midiDW, midiDH, true);

    ctlmidi->resize(fetchX, fetchY, fetchW, fetchH);
    ctlmidi->show();
    ctlmidiSeen = true;} {}
  }
  Function {Showefx()} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Part-effects");

    if (fetchW < fxDW || fetchH < fxDH)
    {
        fetchW = fxDW;
        fetchH = fxDH;
    }
    checkSane(fetchX, fetchY, fetchW, fetchH, fxDW, fxDH);

    partfx->resize(fetchX, fetchY, fetchW, fetchH);
    partfx->show();
    fxSeen = true;} {}
  }
  Function {Showkit()} {} {
    code {//
    int fetchW, fetchH, fetchX, fetchY, fetchO;
    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Part-kit");

    if (fetchW < kitDW || fetchH < kitDH)
    {
        fetchW = kitDW;
        fetchH = kitDH;
    }
    checkSane(fetchX, fetchY, fetchW, fetchH, kitDW, kitDH);

    instrumentkitlist->resize(fetchX, fetchY, fetchW, fetchH);
    instrumentkitlist->show();
    kitSeen = true;} {}
  }
  Function {wincheck()} {} {
    code {//
    if (instrumenteditwindow->visible())
        editRtext();
    if (partfx->visible())
    {
        if (insefftype->value() == (EFFECT::type::dynFilter - EFFECT::type::none))
        {
            if(inseffectui->filterwindow != NULL)
            {
                if(inseffectui->filterwindow->visible())
                {
                    if (lastDynFiltW != inseffectui->filterwindow->w())
                    {
                      inseffectui->filtRtext();
                      lastDynFiltW = inseffectui->filterwindow->w();
                    }
                }
            }
        }
        fxRtext();
    }
    if (instrumentkitlist->visible() && instrumentkitlist->w() != lastkitW)
    {
        kitRtext();
        lastkitW = instrumentkitlist->w();
    }
    if (ctlwindow->visible())
        ctlRtext();

    if (ctlmidi->visible() && ctlmidi->w() != lastmidiW)
    {
        ctlmidiRtext();
        lastmidiW = ctlmidi->w();
    }
    if (aftertouchcontrol->visible() && aftertouchcontrol->w() != lastatW)
    {
        ATRtext();
        lastatW = aftertouchcontrol->w();
    }

    if (adnoteui)
        adnoteui->wincheck();
    if (subnoteui)
        subnoteui->subRtext();
    if (padnoteui)
        padnoteui->padRtext();} {}
  }
  Function {theme()} {} {
    code {//
        if (instrumenteditwindow->visible())
        {
            lasteditW=0;
            editRtext();
        }
        if (partfx->visible())
        {
            lastfxW = 0;
            fxRtext();
            if (insefftype->value() == (EFFECT::type::dynFilter - EFFECT::type::none))
            {
                if(inseffectui->filterwindow != NULL)
                {
                    if(inseffectui->filterwindow->visible())
                    {
                        inseffectui->filterwindow->redraw();
                    }
                    if(inseffectui->fwin_filterui)
                        inseffectui->fwin_filterui->theme();
                }
            }
        }
        if (instrumentkitlist->visible())
        {
            kitRtext();
        }
        if (ctlwindow->visible())
        {
            lastctlW = 0;
            ctlRtext();
        }
        if (ctlmidi->visible())
        {
            lastmidiW = 0;
            ctlmidiRtext();
        }
        if (aftertouchcontrol->visible())
        {
            ATRtext();
        }
        if (adnoteui)
            adnoteui->theme();
        if (subnoteui)
            subnoteui->theme();
        if (padnoteui)
            padnoteui->theme();
        ;} {}
  }
  Function {editRtext()} {} {
    code {//
    if (lasteditW == instrumenteditwindow->w())
        return;
    lasteditW = instrumenteditwindow->w();

    float dScale = instrumenteditwindow->w() / float(editDW);
    if (dScale < 0.2f)
        dScale = 0.2f;

    int size = int(10 * dScale);
    int size11 = int(11 * dScale);
    int size12 = int(12 * dScale);
    int size14 = int(14 * dScale);
    int boxY = int(227 * dScale);
    int boxWidth = int(89 * dScale);
    int boxHeight = int(18 * dScale);

    ADD->labelsize(size14);
    addbox->resize(int(8 * dScale), boxY, boxWidth, boxHeight);
    adsynenabledcheck->labelsize(size11);
    adeditbutton->labelsize(size14);

    SUB->labelsize(size14);
    subbox->resize(int(103 * dScale), boxY, boxWidth, boxHeight);
    subsynenabledcheck->labelsize(size11);
    subeditbutton->labelsize(size14);

    PAD->labelsize(size14);
    padbox->resize(int(198 * dScale), boxY, boxWidth, boxHeight);
    padsynenabledcheck->labelsize(size11);
    padeditbutton->labelsize(size14);

    kitedit->labelsize(size14);
    effects->labelsize(size14);
    editAT->labelsize(size14);

    A_C_display->labelsize(size12);
    A_C_default->labelsize(size12);
    copyright->labelsize(size12);
        copyright->textsize(size14);
    commentField->labelsize(size12);
        commentField->textsize(size14);
    originalname->labelsize(size12);
    originaltext->labelsize(size12);
    instrumentType->labelsize(size11);
        instrumentType->textsize(size11);

    humanise->labelsize(size12);
        humanise->textsize(size);
    velocityhumanise->labelsize(size12);
        velocityhumanise->textsize(size);

    instrumentReset->labelsize(size14);
    editClose->labelsize(size14);
;
    humanise_display->labelsize(size14);

    instrumenteditwindow->redraw();} {}
  }
  Function {ctlRtext()} {} {
    code {//
    if (lastctlW == ctlwindow->w())
        return;
    lastctlW = ctlwindow->w();

    float dScale =  ctlwindow->w() / float(ctlDW);
    if (dScale < 0.2f)
        dScale = 0.2f;

    int size = int(dScale * 10);
    int size14 = int(dScale * 14);

    volrng->labelsize(size);
    vol->labelsize(size);
    panwidth->labelsize(size);
    modwh->labelsize(size);
    expmwh->labelsize(size);
    bwdpth->labelsize(size);
    expbw->labelsize(size);
    expr->labelsize(size);
    fmamp->labelsize(size);
    sustain->labelsize(size);
    breath->labelsize(size);
    pwheelrnglabel->labelsize(size);
    pwheelbrng->textsize(size14);
    filtq->labelsize(size);
    fltcut->labelsize(size);

    ctlresonance->labelsize(size);
    cfdpth->labelsize(size);
    rbwdpth->labelsize(size);

    ctlportamento->labelsize(size);
    ctlx100->labelsize(size);
    prtime->labelsize(size);
    timedu->labelsize(size);
    threshlabel->labelsize(size);
    thresh->textsize(size14);
    thtype->labelsize(size);
    propta->labelsize(size);
    proptb->labelsize(size);
    rcv->labelsize(size);
    proprt->labelsize(size);

    resetallctl->labelsize(size14);
    aftertouch->labelsize(size14);
    ctlclose->labelsize(size14);
    ctlwindow->redraw();} {}
  }
  Function {ATRtext()} {} {
    code {//
    float dScale =  aftertouchcontrol->w() / float(atDW);
    if (dScale < 0.2f)
        dScale = 0.2f;

    int size14 = int(dScale * 14);

    ATchan->labelsize(size14);
    channeloff->labelsize(size14);
    channelfiltercutoff->labelsize(size14);
    channelfilterCminus->labelsize(size14);
    channelfilterQ->labelsize(size14);
    channelfilterQminus->labelsize(size14);
    channelpitchbend->labelsize(size14);
    channelpitchBminus->labelsize(size14);
    channelmodulation->labelsize(size14);
    channelvolume->labelsize(size14);

    ATkey->labelsize(size14);
    polyoff->labelsize(size14);
    polyfiltercutoff->labelsize(size14);
    polyfilterCminus->labelsize(size14);
    polyfilterQ->labelsize(size14);
    polyfilterQminus->labelsize(size14);
    polypitchbend->labelsize(size14);
    polypitchBminus->labelsize(size14);
    polymodulation->labelsize(size14);

    atClose->labelsize(size14);

    aftertouchcontrol->redraw();} {}
  }
  Function {ctlmidiRtext()} {} {
    code {//
    float dScale = ctlmidi->w() / float(midiDW);
    if (dScale < 0.2f)
        dScale = 0.2f;

    int size = int(dScale * 10);

    modulation->labelsize(size);
    expression->labelsize(size);
    filterq->labelsize(size);
    filtercutoff->labelsize(size);
    masterbandwidth->labelsize(size);
    ctlmidiclose->labelsize(int(dScale * 14)-1);

    ctlmidi->redraw();} {}
  }
  Function {fxRtext()} {} {
    code {//
    /*if (lastfxW < 6)
    {
        ++lastfxW;
        return;
    }*/
    if (lastfxW == partfx->w())
        return;
    lastfxW = partfx->w();

    float dScale =  lastfxW / float(fxDW);
    if (dScale < 0.2f)
        dScale = 0.2f;

    int size12 = int(12 * dScale);
    inseffnocounter->labelsize(size12);
        inseffnocounter->textsize(size12);
    insefftype->labelsize(size12);
        insefftype->textsize(size12);
    sendtochoice->labelsize(size12);
        sendtochoice->textsize(size12);

    effCopy->labelsize(size12);
    effPaste->labelsize(size12);
    bypasseff->labelsize(size12);
    effClose->labelsize(int(14 * dScale));

    inseffectui->effRtext(dScale, insefftype->value());

    partfx->redraw();} {}
  }
  Function {kitRtext(bool force = false)} {} {
    code {//
    if (force)
    {
        int fetchW, fetchH, fetchX, fetchY, fetchO;
        loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Part-kit");
        instrumentkitlist->resize(fetchX, fetchY, fetchW, fetchH);
        //kitSeen = true;
    };

    float dW = instrumentkitlist->w() / float(kitDW);
    float dH = instrumentkitlist->h() / float(kitDH);

    float dScale = dW;
    if (dScale < 0.2f)
        dScale = 0.2f;

    int size11 = int(11 * dScale);

    kitnum->labelsize(size11);
    kitmute->labelsize(size11);
    kitID->labelsize(size11);
    kitminkey->labelsize(size11);
    kitmaxkey->labelsize(size11);
    addON->labelsize(size11);
    kitadd->labelsize(size11);
    subON->labelsize(size11);
    kitsub->labelsize(size11);
    padON->labelsize(size11);
    kitpad->labelsize(size11);
    kitfxnum->labelsize(size11);
    kitMode->labelsize(size11);
        kitMode->textsize(size11);

    drumMode->labelsize(size11);
    kitClose->labelsize(int(12 * dScale));


   kitpack->resize(0, int(21.0f * dH), int(670.0f * dW), int(322.0f * dH));

   for (int i = 0; i < NUM_KIT_ITEMS; ++i)
   {
       partkititem[i]->size(int(670.0f * dW), int(20.0f * dH));
       partkititem[i]->partkititemgroup->size(int(605.0f * dW), int(20.0f * dH));
       partkititem[i]->itemRtext(dScale);
   }

    instrumentkitlist->redraw();} {}
  }
  Function {~PartUI()} {} {
    code {//
    if (adnoteui)
    {
        adnoteui->ADnoteGlobalParameters->hide();
        delete adnoteui;
    }
    if (subnoteui)
    {
        //subnoteui->hide();
        delete subnoteui;
    }
    if (padnoteui)
    {
        //padnoteui->hide();
        delete padnoteui;
    }
    if (atSeen > 0)
        saveWin(synth, aftertouchcontrol->w(), aftertouchcontrol->h(), aftertouchcontrol->x(), aftertouchcontrol->y(), true, "Part-aftertouch");
    aftertouchcontrol->hide();
    delete aftertouchcontrol;

    if (ctlSeen)
        saveWin(synth, ctlwindow->w(), ctlwindow->h(), ctlwindow->x(), ctlwindow->y(), true, "Part-controllers");
    ctlwindow->hide();
    delete ctlwindow;

    if (ctlmidiSeen)
        saveWin(synth, ctlmidi->w(), ctlmidi->h(), ctlmidi->x(), ctlmidi->y(), ctlmidi->visible(), "Part-ctlmidi");
    ctlmidi->hide();
    lastctlW = 0;
    delete ctlmidi;

    if (kitSeen)
        saveWin(synth, instrumentkitlist->w(), instrumentkitlist->h(), instrumentkitlist->x(), instrumentkitlist->y(), true, "Part-kit");
    instrumentkitlist->hide();
    delete instrumentkitlist;

    if (fxSeen)
        saveWin(synth,  partfx->w(), partfx->h(),  partfx->x(),  partfx->y(),  partfx->visible(), "Part-effects");
    partfx->hide();
    delete partfx;

    if (editSeen)
        saveWin(synth, instrumenteditwindow->w(), instrumenteditwindow->h(), instrumenteditwindow->x(),instrumenteditwindow->y(), true, "Part-edit");
    instrumenteditwindow->hide();
    lasteditW = 0;

    delete instrumenteditwindow;} {}
  }
  decl {Part *part;} {public local
  }
  decl {BankUI *bankui;} {private local
  }
  decl {ADnoteUI *adnoteui;} {public local
  }
  decl {SUBnoteUI *subnoteui;} {public local
  }
  decl {PADnoteUI *padnoteui;} {public local
  }
  decl {int npart;} {public local
  }
  decl {int lastkititem;} {public local
  }
  decl {string partname;} {public local
  }
  decl {string kitname;} {public local
  }
  decl {PartKitItem *partkititem[NUM_KIT_ITEMS];} {public local
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {int *plgroup;} {private local
  }
  decl {int engine;} {private local
  }
  decl {bool partKitOn;} {public local
  }
  decl {int lastkey;} {private local
  }
  decl {int channelATselection;} {private local
  }
  decl {int keyATselection;} {private local
  }
  decl {float midiDW;} {public local
  }
  decl {float midiDH;} {public local
  }
  decl {bool ctlmidiSeen;} {private local
  }
  decl {float atDW;} {public local
  }
  decl {float atDH;} {public local
  }
  decl {int atSeen;} {private local
  }
  decl {float ctlDW;} {public local
  }
  decl {float ctlDH;} {public local
  }
  decl {int lastctlW;} {private local
  }
  decl {bool ctlSeen;} {private local
  }
  decl {float fxDW;} {public local
  }
  decl {float fxDH;} {public local
  }
  decl {bool fxSeen;} {private local
  }
  decl {float editDW;} {public local
  }
  decl {float editDH;} {public local
  }
  decl {int lasteditW;} {private local
  }
  decl {bool editSeen;} {private local
  }
  decl {float kitDW;} {public local
  }
  decl {float kitDH;} {public local
  }
  decl {bool kitSeen;} {private local
  }
  decl {int lastfxW;} {private local
  }
  decl {int lastDynFiltW;} {private local
  }
  decl {int lastkitW;} {private local
  }
  decl {int lastmidiW;} {private local
  }
  decl {int lastatW;} {private local
  }
}
