// generated by Fast Light User Interface Designer (fluid) version 1.0405

#include "PartUI.h"
// PartUI.cc
// 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-2025 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.


#include <FL/fl_ask.H>
    #include <iostream>
    #include "Misc/Config.h"
    #include "Misc/SynthEngine.h"
#include "MasterUI.h"
#include "Misc/FormatFuncs.h"
    using func::asString;
#include "Misc/TextMsgBuffer.h"

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

void PartUI_::showparameters(int /* kititem */,int /* engine */) {
  ;
}

void PartKitItem::cb_mutedcheck_i(Fl_Check_Button2* o, void*) {
  //
            send_data(0, PART::control::kitItemMute, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);
}
void PartKitItem::cb_mutedcheck(Fl_Check_Button2* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_mutedcheck_i(o,v);
}

void PartKitItem::cb_labelbutton_i(Fl_Button* o, void*) {
  //
            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());
            }
}
void PartKitItem::cb_labelbutton(Fl_Button* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_labelbutton_i(o,v);
}

void PartKitItem::cb_minkcounter_i(Fl_Counter* o, void*) {
  //
            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);
}
void PartKitItem::cb_minkcounter(Fl_Counter* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_minkcounter_i(o,v);
}

void PartKitItem::cb_setmin_i(Fl_Button*, void*) {
  //
            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);
}
void PartKitItem::cb_setmin(Fl_Button* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_setmin_i(o,v);
}

void PartKitItem::cb_setmax_i(Fl_Button*, void*) {
  //
            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);
}
void PartKitItem::cb_setmax(Fl_Button* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_setmax_i(o,v);
}

void PartKitItem::cb_setfull_i(Fl_Button* o, void*) {
  //
            minkcounter->value(0);
            maxkcounter->value(127);

            send_data(0, PART::control::resetMinMaxKey, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);
}
void PartKitItem::cb_setfull(Fl_Button* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_setfull_i(o,v);
}

void PartKitItem::cb_maxkcounter_i(Fl_Counter* o, void*) {
  //
            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);
}
void PartKitItem::cb_maxkcounter(Fl_Counter* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_maxkcounter_i(o,v);
}

void PartKitItem::cb_adeditbutton_i(Fl_Button*, void*) {
  //
            partui->showparameters(n,PART::engine::addSynth);
            if ((Fl::event_button() == 3))
                synth->getGuiMaster()->partui->instrumentkitlist->hide();
}
void PartKitItem::cb_adeditbutton(Fl_Button* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_adeditbutton_i(o,v);
}

void PartKitItem::cb_adcheck_i(Fl_Check_Button2* o, void*) {
  //

            send_data(TOPLEVEL::action::forceUpdate, PART::control::enableAdd, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);
}
void PartKitItem::cb_adcheck(Fl_Check_Button2* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_adcheck_i(o,v);
}

void PartKitItem::cb_subeditbutton_i(Fl_Button*, void*) {
  //
            partui->showparameters(n,PART::engine::subSynth);
            if ((Fl::event_button() == 3))
                synth->getGuiMaster()->partui->instrumentkitlist->hide();
}
void PartKitItem::cb_subeditbutton(Fl_Button* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_subeditbutton_i(o,v);
}

void PartKitItem::cb_subcheck_i(Fl_Check_Button2* o, void*) {
  //

            send_data(TOPLEVEL::action::forceUpdate, PART::control::enableSub, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);
}
void PartKitItem::cb_subcheck(Fl_Check_Button2* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_subcheck_i(o,v);
}

void PartKitItem::cb_padeditbutton_i(Fl_Button*, void*) {
  //
            partui->showparameters(n,PART::engine::padSynth);
            if ((Fl::event_button() == 3))
                synth->getGuiMaster()->partui->instrumentkitlist->hide();
}
void PartKitItem::cb_padeditbutton(Fl_Button* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_padeditbutton_i(o,v);
}

void PartKitItem::cb_padcheck_i(Fl_Check_Button2* o, void*) {
  //

            send_data(TOPLEVEL::action::forceUpdate, PART::control::enablePad, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);
}
void PartKitItem::cb_padcheck(Fl_Check_Button2* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_padcheck_i(o,v);
}

void PartKitItem::cb_sendtoeffect_i(Fl_Choice* o, void*) {
  //
            send_data(0, PART::control::kitEffectNum, o->value(), TOPLEVEL::type::Integer, n, UNUSED, TOPLEVEL::insert::kitGroup);
}
void PartKitItem::cb_sendtoeffect(Fl_Choice* o, void* v) {
  ((PartKitItem*)(o->parent()->parent()->user_data()))->cb_sendtoeffect_i(o,v);
}

void PartKitItem::cb_enabledcheck_i(Fl_Check_Button2* o, void*) {
  //
          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);
}
void PartKitItem::cb_enabledcheck(Fl_Check_Button2* o, void* v) {
  ((PartKitItem*)(o->parent()->user_data()))->cb_enabledcheck_i(o,v);
}

Fl_Group* PartKitItem::make_window() {
  { partkititem = new Fl_Group(0, 0, 670, 20);
    partkititem->box(FL_NO_BOX);
    partkititem->color(FL_BACKGROUND_COLOR);
    partkititem->selection_color(FL_BACKGROUND_COLOR);
    partkititem->labeltype(FL_NO_LABEL);
    partkititem->labelfont(0);
    partkititem->labelsize(14);
    partkititem->labelcolor(FL_FOREGROUND_COLOR);
    partkititem->user_data((void*)(this));
    partkititem->align(Fl_Align(FL_ALIGN_TOP));
    partkititem->when(FL_WHEN_RELEASE);
    { Fl_Group* o = partkititemgroup = new Fl_Group(55, 4, 605, 20);
      { Fl_Check_Button2* o = mutedcheck = new Fl_Check_Button2(60, 4, 15, 15);
        mutedcheck->box(FL_NO_BOX);
        mutedcheck->down_box(FL_DOWN_BOX);
        mutedcheck->color(FL_BACKGROUND2_COLOR);
        mutedcheck->selection_color((Fl_Color)64);
        mutedcheck->labeltype(FL_NORMAL_LABEL);
        mutedcheck->labelfont(1);
        mutedcheck->labelsize(11);
        mutedcheck->labelcolor((Fl_Color)64);
        mutedcheck->callback((Fl_Callback*)cb_mutedcheck);
        mutedcheck->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
        mutedcheck->when(FL_WHEN_RELEASE);
        o->value(part->kit[n].Pmuted);
      } // Fl_Check_Button2* mutedcheck
      { Fl_Button* o = labelbutton = new Fl_Button(90, 4, 130, 14, "Bass Drum");
        labelbutton->box(FL_THIN_DOWN_BOX);
        labelbutton->down_box(FL_FLAT_BOX);
        labelbutton->color(FL_BACKGROUND2_COLOR);
        labelbutton->labelfont(1);
        labelbutton->labelsize(10);
        labelbutton->labelcolor((Fl_Color)64);
        labelbutton->callback((Fl_Callback*)cb_labelbutton);
        labelbutton->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
        o->copy_label(part->kit[n].Pname.c_str());
      } // Fl_Button* labelbutton
      { Fl_Counter* o = minkcounter = new Fl_Counter(225, 4, 70, 14);
        minkcounter->type(1);
        minkcounter->labelcolor((Fl_Color)64);
        minkcounter->minimum(0);
        minkcounter->maximum(127);
        minkcounter->step(1);
        minkcounter->textfont(1);
        minkcounter->textsize(12);
        minkcounter->textcolor((Fl_Color)64);
        minkcounter->callback((Fl_Callback*)cb_minkcounter);
        o->value(part->kit[n].Pminkey);
      } // Fl_Counter* minkcounter
      { setmin = new Fl_Button(300, 5, 15, 12, "m");
        setmin->tooltip("set the minimum key to the last pressed key");
        setmin->box(FL_THIN_UP_BOX);
        setmin->labelsize(10);
        setmin->labelcolor((Fl_Color)64);
        setmin->callback((Fl_Callback*)cb_setmin);
      } // Fl_Button* setmin
      { setmax = new Fl_Button(330, 5, 15, 12, "M");
        setmax->tooltip("set the maximum key to the last pressed key");
        setmax->box(FL_THIN_UP_BOX);
        setmax->labelsize(10);
        setmax->labelcolor((Fl_Color)64);
        setmax->callback((Fl_Callback*)cb_setmax);
      } // Fl_Button* setmax
      { setfull = new Fl_Button(315, 5, 15, 12, "R");
        setfull->tooltip("reset the minimum key to 0 and maximum key to 127");
        setfull->box(FL_THIN_UP_BOX);
        setfull->labelfont(1);
        setfull->labelsize(10);
        setfull->labelcolor((Fl_Color)64);
        setfull->callback((Fl_Callback*)cb_setfull);
      } // Fl_Button* setfull
      { Fl_Counter* o = maxkcounter = new Fl_Counter(350, 4, 70, 14);
        maxkcounter->type(1);
        maxkcounter->labelcolor((Fl_Color)64);
        maxkcounter->minimum(0);
        maxkcounter->maximum(127);
        maxkcounter->step(1);
        maxkcounter->textfont(1);
        maxkcounter->textsize(12);
        maxkcounter->textcolor((Fl_Color)64);
        maxkcounter->callback((Fl_Callback*)cb_maxkcounter);
        o->value(part->kit[n].Pmaxkey);
      } // Fl_Counter* maxkcounter
      { Fl_Button* o = adeditbutton = new Fl_Button(442, 4, 40, 15, "edit");
        adeditbutton->box(FL_GTK_THIN_UP_BOX);
        adeditbutton->color((Fl_Color)198);
        adeditbutton->labelsize(11);
        adeditbutton->labelcolor((Fl_Color)64);
        adeditbutton->callback((Fl_Callback*)cb_adeditbutton);
        if (part->kit[n].Padenabled==0) o->deactivate();
      } // Fl_Button* adeditbutton
      { Fl_Check_Button2* o = adcheck = new Fl_Check_Button2(426, 4, 15, 15);
        adcheck->box(FL_NO_BOX);
        adcheck->down_box(FL_DOWN_BOX);
        adcheck->color(FL_BACKGROUND2_COLOR);
        adcheck->selection_color((Fl_Color)64);
        adcheck->labeltype(FL_NORMAL_LABEL);
        adcheck->labelfont(1);
        adcheck->labelsize(11);
        adcheck->labelcolor((Fl_Color)64);
        adcheck->callback((Fl_Callback*)cb_adcheck);
        adcheck->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
        adcheck->when(FL_WHEN_RELEASE);
        o->value(part->kit[n].Padenabled);
      } // Fl_Check_Button2* adcheck
      { Fl_Button* o = subeditbutton = new Fl_Button(507, 4, 40, 15, "edit");
        subeditbutton->box(FL_GTK_THIN_UP_BOX);
        subeditbutton->color((Fl_Color)198);
        subeditbutton->labelsize(11);
        subeditbutton->labelcolor((Fl_Color)64);
        subeditbutton->callback((Fl_Callback*)cb_subeditbutton);
        if (part->kit[n].Psubenabled==0) o->deactivate();
      } // Fl_Button* subeditbutton
      { Fl_Check_Button2* o = subcheck = new Fl_Check_Button2(491, 4, 15, 15);
        subcheck->box(FL_NO_BOX);
        subcheck->down_box(FL_DOWN_BOX);
        subcheck->color(FL_BACKGROUND2_COLOR);
        subcheck->selection_color((Fl_Color)64);
        subcheck->labeltype(FL_NORMAL_LABEL);
        subcheck->labelfont(1);
        subcheck->labelsize(11);
        subcheck->labelcolor((Fl_Color)64);
        subcheck->callback((Fl_Callback*)cb_subcheck);
        subcheck->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
        subcheck->when(FL_WHEN_RELEASE);
        o->value(part->kit[n].Psubenabled);
      } // Fl_Check_Button2* subcheck
      { Fl_Button* o = padeditbutton = new Fl_Button(570, 4, 40, 15, "edit");
        padeditbutton->box(FL_GTK_THIN_UP_BOX);
        padeditbutton->color((Fl_Color)198);
        padeditbutton->labelsize(11);
        padeditbutton->labelcolor((Fl_Color)64);
        padeditbutton->callback((Fl_Callback*)cb_padeditbutton);
        if (part->kit[n].Ppadenabled==0) o->deactivate();
      } // Fl_Button* padeditbutton
      { Fl_Check_Button2* o = padcheck = new Fl_Check_Button2(555, 4, 15, 15);
        padcheck->box(FL_NO_BOX);
        padcheck->down_box(FL_DOWN_BOX);
        padcheck->color(FL_BACKGROUND2_COLOR);
        padcheck->selection_color((Fl_Color)64);
        padcheck->labeltype(FL_NORMAL_LABEL);
        padcheck->labelfont(1);
        padcheck->labelsize(11);
        padcheck->labelcolor((Fl_Color)64);
        padcheck->callback((Fl_Callback*)cb_padcheck);
        padcheck->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
        padcheck->when(FL_WHEN_RELEASE);
        o->value(part->kit[n].Ppadenabled);
      } // Fl_Check_Button2* padcheck
      { Fl_Choice* o = sendtoeffect = new Fl_Choice(615, 4, 45, 15);
        sendtoeffect->down_box(FL_BORDER_BOX);
        sendtoeffect->labelsize(10);
        sendtoeffect->labelcolor((Fl_Color)64);
        sendtoeffect->textfont(1);
        sendtoeffect->textsize(10);
        sendtoeffect->textcolor((Fl_Color)64);
        sendtoeffect->callback((Fl_Callback*)cb_sendtoeffect);
        sendtoeffect->align(Fl_Align(FL_ALIGN_TOP_LEFT));
        o->add("OFF"); char nrstr[10]; for (int i = 0; i < NUM_PART_EFX; i++) {sprintf(nrstr,"FX%d",i+1);o->add(nrstr);};
        o->value(part->kit[n].Psendtoparteffect+1);if (part->kit[n].Psendtoparteffect==127) o->value(0);
      } // Fl_Choice* sendtoeffect
      if (part->kit[n].Penabled == 0) o->deactivate();
      partkititemgroup->end();
    } // Fl_Group* partkititemgroup
    { Fl_Check_Button2* o = enabledcheck = new Fl_Check_Button2(30, 4, 20, 15, "01");
      enabledcheck->box(FL_NO_BOX);
      enabledcheck->down_box(FL_DOWN_BOX);
      enabledcheck->color(FL_BACKGROUND_COLOR);
      enabledcheck->selection_color((Fl_Color)64);
      enabledcheck->labeltype(FL_EMBOSSED_LABEL);
      enabledcheck->labelfont(1);
      enabledcheck->labelsize(12);
      enabledcheck->labelcolor((Fl_Color)64);
      enabledcheck->callback((Fl_Callback*)cb_enabledcheck);
      enabledcheck->align(Fl_Align(FL_ALIGN_LEFT));
      enabledcheck->when(FL_WHEN_RELEASE);
      snprintf(label,10,"%d",(n&15)+1);o->label(label);
      o->value(part->kit[n].Penabled);
      if (n==0) o->hide();
      if (o->value() == 0) labelbutton->color(gen_text_back);
    } // Fl_Check_Button2* enabledcheck
    partkititem->end();
  } // Fl_Group* partkititem
  return partkititem;
}

void PartKitItem::send_data(int action, int control, float value, int type, int kititem , int engine , int insert , int parameter , int miscmsg ) {
  //
          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);
          ;
}

PartKitItem::PartKitItem(int x,int y, int w, int h, const char *label):Fl_Group(x,y,w,h,label) {
  //
      n=0;part=NULL;
}

void PartKitItem::clearLine() {
  //
      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);
}

void PartKitItem::init(Part *part_, int n_, int npart_, PartUI_ *partui_) {
  //
      synth = & part_->getSynthEngine();
      part = part_;
      n = n_;
      npart = npart_;
      partui = partui_;
      make_window();
      end();
}

void PartKitItem::itemRtext(float dScale) {
  //
      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);
}

PartKitItem::~PartKitItem() {
  //
      partkititem->hide();
}

void PartUI::cb_instrumenteditwindow_i(ScaleTrackedWindow*, void*) {
  editClose->do_callback();
}
void PartUI::cb_instrumenteditwindow(ScaleTrackedWindow* o, void* v) {
  ((PartUI*)(o->user_data()))->cb_instrumenteditwindow_i(o,v);
}

void PartUI::cb_adsynenabledcheck_i(Fl_Check_Button2* o, void*) {
  //

              send_data(TOPLEVEL::action::forceUpdate, PART::control::enableAdd, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_adsynenabledcheck(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->parent()->parent()->user_data()))->cb_adsynenabledcheck_i(o,v);
}

void PartUI::cb_adeditbutton1_i(Fl_Button*, void*) {
  //
              showparameters(0,PART::engine::addSynth);
              //checkEngines();
              seteditname();
              if ((Fl::event_button() == 3))
              {
                  instrumenteditwindow->hide();}
}
void PartUI::cb_adeditbutton1(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->parent()->user_data()))->cb_adeditbutton1_i(o,v);
}

void PartUI::cb_subsynenabledcheck_i(Fl_Check_Button2* o, void*) {
  //

              send_data(TOPLEVEL::action::forceUpdate, PART::control::enableSub, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_subsynenabledcheck(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->parent()->parent()->user_data()))->cb_subsynenabledcheck_i(o,v);
}

void PartUI::cb_subeditbutton1_i(Fl_Button*, void*) {
  //
              showparameters(0,PART::engine::subSynth);
              //checkEngines();
              seteditname();
              if ((Fl::event_button() == 3))
              {
                  instrumenteditwindow->hide();}
}
void PartUI::cb_subeditbutton1(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->parent()->user_data()))->cb_subeditbutton1_i(o,v);
}

void PartUI::cb_padsynenabledcheck_i(Fl_Check_Button2* o, void*) {
  //

              send_data(TOPLEVEL::action::forceUpdate, PART::control::enablePad, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_padsynenabledcheck(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->parent()->parent()->user_data()))->cb_padsynenabledcheck_i(o,v);
}

void PartUI::cb_padeditbutton1_i(Fl_Button*, void*) {
  //
              showparameters(0,PART::engine::padSynth);
              //checkEngines();
              seteditname();
              if ((Fl::event_button() == 3))
              {
                  instrumenteditwindow->hide();}
}
void PartUI::cb_padeditbutton1(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->parent()->user_data()))->cb_padeditbutton1_i(o,v);
}

void PartUI::cb_kitedit_i(Fl_Button*, void*) {
  //
            Showkit();
            if ((Fl::event_button() == 3))
            {
                instrumenteditwindow->hide();}
}
void PartUI::cb_kitedit(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_kitedit_i(o,v);
}

void PartUI::cb_effects_i(Fl_Button*, void*) {
  //
            Showefx();
            if ((Fl::event_button() == 3))
            {
                instrumenteditwindow->hide();}
}
void PartUI::cb_effects(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_effects_i(o,v);
}

void PartUI::cb_editAT_i(Fl_Button*, void*) {
  //
                  ShowAT();
                  atSeen = 2;
                  if ((Fl::event_button() == 3))
                      instrumenteditwindow->hide();
}
void PartUI::cb_editAT(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_editAT_i(o,v);
}

void PartUI::cb_instrumentReset_i(Fl_Button*, void*) {
  //
           if (!fetchData(0, PART::control::enable, npart))
           {
               alert(synth, "Selected part is disabled");
               return;
           }

           bool fullClear = false;
           if (Fl::event_state(FL_CTRL))
           {
               if (choice(synth, "", "Yes", "No", "Set entire part " + std::to_string(npart + 1) + " controls to default values ?") > 1)
                   fullClear = true;
           }

           if (synth->getGuiMaster()->instrumentSingleWarning(npart, "Still clear"))
           {
               return;
           }

           if (fullClear)
               send_data(TOPLEVEL::action::forceUpdate, MAIN::control::defaultPart, npart, TOPLEVEL::type::Integer, TOPLEVEL::section::main);
           else
               send_data(TOPLEVEL::action::forceUpdate, MAIN::control::defaultInstrument, npart, TOPLEVEL::type::Integer, TOPLEVEL::section::main);
          ;
}
void PartUI::cb_instrumentReset(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_instrumentReset_i(o,v);
}

void PartUI::cb_editClose_i(Fl_Button* o, void*) {
  //
                    saveWin(synth, instrumenteditwindow->w(), instrumenteditwindow->h(), instrumenteditwindow->x(),instrumenteditwindow->y(), false, "Part-edit");
                    editSeen = false;
                    lasteditW = 0;
                    instrumenteditwindow->hide();
                    o->parent()->show();
}
void PartUI::cb_editClose(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_editClose_i(o,v);
}

void PartUI::cb_A_C_default_i(Fl_Button*, void*) {
  //
              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);
}
void PartUI::cb_A_C_default(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_A_C_default_i(o,v);
}

void PartUI::cb_copyright_i(Fl_Input* o, void*) {
  //
             send_data(TOPLEVEL::action::lowPrio, PART::control::instrumentCopyright, 0, TOPLEVEL::type::Integer, npart, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(string(o->value())));
}
void PartUI::cb_copyright(Fl_Input* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_copyright_i(o,v);
}

void PartUI::cb_commentField_i(Fl_Input* o, void*) {
  //
            send_data(TOPLEVEL::action::lowPrio, PART::control::instrumentComments, 0, TOPLEVEL::type::Integer, npart, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(string(o->value())));
}
void PartUI::cb_commentField(Fl_Input* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_commentField_i(o,v);
}

void PartUI::cb_instrumentType_i(Fl_Choice* o, void*) {
  //
                send_data(TOPLEVEL::action::lowPrio, PART::control::instrumentType, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_instrumentType(Fl_Choice* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_instrumentType_i(o,v);
}

void PartUI::cb_humanise_i(mwheel_slider_rev* o, void*) {
  //
          o->selection_color(setSlider(o->value(),0));
          send_data(0, PART::control::humanise, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_humanise(mwheel_slider_rev* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_humanise_i(o,v);
}

void PartUI::cb_velocityhumanise_i(mwheel_slider_rev* o, void*) {
  //
          o->selection_color(setSlider(o->value(),0));
          send_data(0, PART::control::humanvelocity, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_velocityhumanise(mwheel_slider_rev* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_velocityhumanise_i(o,v);
}

void PartUI::cb_instrumentkitlist_i(ScaleTrackedWindow*, void*) {
  //
      saveWin(synth, instrumentkitlist->w(), instrumentkitlist->h(), instrumentkitlist->x(), instrumentkitlist->y(), false, "Part-kit");
      instrumentkitlist->hide();
      kitSeen = false;
}
void PartUI::cb_instrumentkitlist(ScaleTrackedWindow* o, void* v) {
  ((PartUI*)(o->user_data()))->cb_instrumentkitlist_i(o,v);
}

void PartUI::cb_kitMode_i(Fl_Choice* o, void*) {
  //
          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);
}
void PartUI::cb_kitMode(Fl_Choice* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_kitMode_i(o,v);
}

void PartUI::cb_drumMode_i(Fl_Check_Button2* o, void*) {
  //
          send_data(TOPLEVEL::action::forceUpdate, PART::control::drumMode, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_drumMode(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_drumMode_i(o,v);
}

void PartUI::cb_kitClose_i(Fl_Button*, void*) {
  //
          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();
}
void PartUI::cb_kitClose(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_kitClose_i(o,v);
}

void PartUI::cb_partfx_i(ScaleTrackedWindow*, void*) {
  //
      saveWin(synth, partfx->w(), partfx->h(),  partfx->x(),  partfx->y(), false, "Part-effects");
      partfx->hide();
}
void PartUI::cb_partfx(ScaleTrackedWindow* o, void* v) {
  ((PartUI*)(o->user_data()))->cb_partfx_i(o,v);
}

void PartUI::cb_inseffnocounter_i(WidgetSpinner* o, void*) {
  //
              int effNum = o->value() - 1;
              send_data(TOPLEVEL::action::forceUpdate, PART::control::effectNumber, effNum, TOPLEVEL::type::Integer, npart, UNUSED, effNum, TOPLEVEL::insert::partEffectSelect);
}
void PartUI::cb_inseffnocounter(WidgetSpinner* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_inseffnocounter_i(o,v);
}

void PartUI::cb_insefftype_i(Fl_Choice* o, void*) {
  //
              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);
}
void PartUI::cb_insefftype(Fl_Choice* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_insefftype_i(o,v);
}

void PartUI::cb_sendtochoice_i(Fl_Choice* o, void*) {
  //
              uchar effNum = inseffectui->effNum();
              send_data(TOPLEVEL::action::forceUpdate, PART::control::effectDestination, o->value(), TOPLEVEL::type::Integer, npart, UNUSED, effNum, TOPLEVEL::insert::partEffectSelect);
}
void PartUI::cb_sendtochoice(Fl_Choice* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_sendtochoice_i(o,v);
}

void PartUI::cb_effCopy_i(Fl_Button*, void*) {
  //
          synth->getGuiMaster()->getPresetsUi()->Ucopy(npart, 16, inseffnocounter->value()-1);
          ;
}
void PartUI::cb_effCopy(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_effCopy_i(o,v);
}

void PartUI::cb_effPaste_i(Fl_Button*, void*) {
  //
          synth->getGuiMaster()->getPresetsUi()->Upaste(npart, 16, inseffnocounter->value()-1);
          ;
}
void PartUI::cb_effPaste(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_effPaste_i(o,v);
}

void PartUI::cb_bypasseff_i(Fl_Check_Button2* o, void*) {
  //
              uchar effNum = inseffectui->effNum();
              send_data(TOPLEVEL::action::forceUpdate, PART::control::effectBypass, o->value(), TOPLEVEL::type::Integer, npart, UNUSED, effNum, TOPLEVEL::insert::partEffectSelect);
}
void PartUI::cb_bypasseff(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_bypasseff_i(o,v);
}

void PartUI::cb_effClose_i(Fl_Button*, void*) {
  //
          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();
}
void PartUI::cb_effClose(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_effClose_i(o,v);
}

void PartUI::cb_modulation_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::midiModWheel, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_modulation(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_modulation_i(o,v);
}

void PartUI::cb_expression_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),127));
          send_data(0, PART::control::midiExpression,  o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_expression(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_expression_i(o,v);
}

void PartUI::cb_filterq_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::midiFilterQ, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_filterq(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_filterq_i(o,v);
}

void PartUI::cb_filtercutoff_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::midiFilterCutoff, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_filtercutoff(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_filtercutoff_i(o,v);
}

void PartUI::cb_masterbandwidth_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::midiBandwidth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_masterbandwidth(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_masterbandwidth_i(o,v);
}

void PartUI::cb_ctlmidiclose_i(Fl_Button*, void*) {
  //
                  saveWin(synth,  ctlmidi->w(),  ctlmidi->h(), ctlmidi->x(), ctlmidi->y(), false, "Part-ctlmidi");
                  ctlmidiSeen = false;
                  ctlmidi->hide();
}
void PartUI::cb_ctlmidiclose(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_ctlmidiclose_i(o,v);
}

void PartUI::cb_ctlwindow_i(ScaleTrackedWindow*, void*) {
  ctlclose->do_callback();
}
void PartUI::cb_ctlwindow(ScaleTrackedWindow* o, void* v) {
  ((PartUI*)(o->user_data()))->cb_ctlwindow_i(o,v);
}

void PartUI::cb_volrng_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),96));
          send_data(0, PART::control::volumeRange, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_volrng(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_volrng_i(o,v);
}

void PartUI::cb_vol_i(Fl_Check_Button2* o, void*) {
  //
          send_data(0, PART::control::volumeEnable, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_vol(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_vol_i(o,v);
}

void PartUI::cb_panwidth_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::panningWidth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_panwidth(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_panwidth_i(o,v);
}

void PartUI::cb_modwh_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),80));
          send_data(0, PART::control::modWheelDepth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_modwh(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_modwh_i(o,v);
}

void PartUI::cb_expmwh_i(Fl_Check_Button2* o, void*) {
  //
          send_data(0, PART::control::exponentialModWheel, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_expmwh(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_expmwh_i(o,v);
}

void PartUI::cb_bwdpth_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::bandwidthDepth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_bwdpth(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_bwdpth_i(o,v);
}

void PartUI::cb_expbw_i(Fl_Check_Button2* o, void*) {
  //
          send_data(0, 134, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_expbw(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_expbw_i(o,v);
}

void PartUI::cb_expr_i(Fl_Check_Button2* o, void*) {
  //
          send_data(0, 135, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_expr(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_expr_i(o,v);
}

void PartUI::cb_fmamp_i(Fl_Check_Button2* o, void*) {
  //
          send_data(0, PART::control::FMamplitudeEnable, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_fmamp(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_fmamp_i(o,v);
}

void PartUI::cb_sustain_i(Fl_Check_Button2* o, void*) {
  //
          send_data(0, PART::control::sustainPedalEnable, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_sustain(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_sustain_i(o,v);
}

void PartUI::cb_breath_i(Fl_Check_Button2* o, void*) {
  //
          send_data(0, 141, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_breath(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_breath_i(o,v);
}

void PartUI::cb_pwheelbrng_i(Fl_Counter* o, void*) {
  //
          send_data(0, PART::control::pitchWheelRange, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_pwheelbrng(Fl_Counter* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_pwheelbrng_i(o,v);
}

void PartUI::cb_filtq_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::filterQdepth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_filtq(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_filtq_i(o,v);
}

void PartUI::cb_fltcut_i(WidgetPDial* o, void*) {
  //
          o->selection_color(setKnob(o->value(),64));
          send_data(0, PART::control::filterCutoffDepth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_fltcut(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_fltcut_i(o,v);
}

void PartUI::cb_cfdpth_i(WidgetPDial* o, void*) {
  //
            o->selection_color(setKnob(o->value(),64));
            send_data(0, PART::control::resonanceCenterFrequencyDepth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_cfdpth(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_cfdpth_i(o,v);
}

void PartUI::cb_rbwdpth_i(WidgetPDial* o, void*) {
  //
            o->selection_color(setKnob(o->value(),64));
            send_data(0, PART::control::resonanceBandwidthDepth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_rbwdpth(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_rbwdpth_i(o,v);
}

void PartUI::cb_prtime_i(WidgetPDial* o, void*) {
  //
            o->selection_color(setKnob(o->value(),64));
            send_data(0, PART::control::portamentoTime, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_prtime(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_prtime_i(o,v);
}

void PartUI::cb_timedu_i(WidgetPDial* o, void*) {
  //
            o->selection_color(setKnob(o->value(),64));
            send_data(0, PART::control::portamentoTimeStretch, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_timedu(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_timedu_i(o,v);
}

void PartUI::cb_thresh_i(Fl_Counter* o, void*) {
  //
            send_data(0, PART::control::portamentoThreshold, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_thresh(Fl_Counter* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_thresh_i(o,v);
}

void PartUI::cb_thtype_i(Fl_Check_Button2* o, void*) {
  //
            send_data(0, PART::control::portamentoThresholdType, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_thtype(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_thtype_i(o,v);
}

void PartUI::cb_propta_i(WidgetPDial* o, void*) {
  //
            o->selection_color(setKnob(o->value(),80));
            send_data(0, PART::control::proportionalPortamentoRate, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_propta(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_propta_i(o,v);
}

void PartUI::cb_proptb_i(WidgetPDial* o, void*) {
  //
            o->selection_color(setKnob(o->value(),90));
            send_data(0, PART::control::proportionalPortamentoDepth, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_proptb(WidgetPDial* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_proptb_i(o,v);
}

void PartUI::cb_rcv_i(Fl_Check_Button2* o, void*) {
  //
            send_data(0, PART::control::receivePortamento, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_rcv(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_rcv_i(o,v);
}

void PartUI::cb_proprt_i(Fl_Check_Button2* o, void*) {
  //
            if (o->value())
            {
                propta->activate();
                proptb->activate();
            }
            else
            {
                propta->deactivate();
                proptb->deactivate();
            }
            send_data(0, PART::control::enableProportionalPortamento, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_proprt(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->parent()->user_data()))->cb_proprt_i(o,v);
}

void PartUI::cb_resetallctl_i(Fl_Button* o, void*) {
  //
          send_data(TOPLEVEL::action::forceUpdate, PART::control::resetAllControllers, o->value(), TOPLEVEL::type::Integer, npart);
}
void PartUI::cb_resetallctl(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_resetallctl_i(o,v);
}

void PartUI::cb_aftertouch_i(Fl_Button*, void*) {
  //;
                  ShowAT();
                  atSeen = 1;
                  if ((Fl::event_button() == 3))
                      ctlwindow->hide();
}
void PartUI::cb_aftertouch(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_aftertouch_i(o,v);
}

void PartUI::cb_ctlclose_i(Fl_Button*, void*) {
  //;
          saveWin(synth, ctlwindow->w(), ctlwindow->h(), ctlwindow->x(), ctlwindow->y(), false, "Part-controllers");
          ctlSeen = false;
          lastctlW = 0;
          ctlwindow->hide();
}
void PartUI::cb_ctlclose(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_ctlclose_i(o,v);
}

void PartUI::cb_aftertouchcontrol_i(ScaleTrackedWindow*, void*) {
  //
      saveWin(synth, aftertouchcontrol->w(), aftertouchcontrol->h(), aftertouchcontrol->x(), aftertouchcontrol->y(), false, "Part-aftertouch");
      aftertouchcontrol->hide();
}
void PartUI::cb_aftertouchcontrol(ScaleTrackedWindow* o, void* v) {
  ((PartUI*)(o->user_data()))->cb_aftertouchcontrol_i(o,v);
}

void PartUI::cb_channeloff_i(Fl_Button*, void*) {
  //
                  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);
}
void PartUI::cb_channeloff(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channeloff_i(o,v);
}

void PartUI::cb_channelfiltercutoff_i(Fl_Check_Button2* o, void*) {
  //
                  if (o->value())
                      channelfilterCminus->activate();
                  else
                  {
                      channelfilterCminus->value(0);
                      channelfilterCminus->deactivate();
                  }
                  setATchannel(PART::aftertouchType::filterCutoff, o->value());
}
void PartUI::cb_channelfiltercutoff(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channelfiltercutoff_i(o,v);
}

void PartUI::cb_channelfilterCminus_i(Fl_Check_Button2* o, void*) {
  //
                  setATchannel(PART::aftertouchType::filterCutoffDown, o->value());
}
void PartUI::cb_channelfilterCminus(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channelfilterCminus_i(o,v);
}

void PartUI::cb_channelfilterQ_i(Fl_Check_Button2* o, void*) {
  //
                  if (o->value())
                      channelfilterQminus->activate();
                  else
                  {
                      channelfilterQminus->value(0);
                      channelfilterQminus->deactivate();
                  }
                  setATchannel(PART::aftertouchType::filterQ, o->value());
}
void PartUI::cb_channelfilterQ(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channelfilterQ_i(o,v);
}

void PartUI::cb_channelfilterQminus_i(Fl_Check_Button2* o, void*) {
  //
                  setATchannel(PART::aftertouchType::filterQdown, o->value());
}
void PartUI::cb_channelfilterQminus(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channelfilterQminus_i(o,v);
}

void PartUI::cb_channelpitchbend_i(Fl_Check_Button2* o, void*) {
  //
                  if (o->value())
                      channelpitchBminus->activate();
                  else
                  {
                      channelpitchBminus->value(0);
                      channelpitchBminus->deactivate();
                  }
                  setATchannel(PART::aftertouchType::pitchBend, o->value());
}
void PartUI::cb_channelpitchbend(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channelpitchbend_i(o,v);
}

void PartUI::cb_channelpitchBminus_i(Fl_Check_Button2* o, void*) {
  //
                  setATchannel(PART::aftertouchType::pitchBendDown, o->value());
}
void PartUI::cb_channelpitchBminus(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channelpitchBminus_i(o,v);
}

void PartUI::cb_channelmodulation_i(Fl_Check_Button2* o, void*) {
  //
                  setATchannel(PART::aftertouchType::modulation, o->value());
}
void PartUI::cb_channelmodulation(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channelmodulation_i(o,v);
}

void PartUI::cb_channelvolume_i(Fl_Check_Button2* o, void*) {
  //
                  setATchannel(PART::aftertouchType::volume, o->value());
}
void PartUI::cb_channelvolume(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_channelvolume_i(o,v);
}

void PartUI::cb_polyoff_i(Fl_Button*, void*) {
  //
                  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);
}
void PartUI::cb_polyoff(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_polyoff_i(o,v);
}

void PartUI::cb_polyfiltercutoff_i(Fl_Check_Button2* o, void*) {
  //
                  if (o->value())
                      polyfilterCminus->activate();
                  else
                  {
                      polyfilterCminus->value(0);
                      polyfilterCminus->deactivate();
                  }
                  setATkey(PART::aftertouchType::filterCutoff, o->value());
}
void PartUI::cb_polyfiltercutoff(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_polyfiltercutoff_i(o,v);
}

void PartUI::cb_polyfilterCminus_i(Fl_Check_Button2* o, void*) {
  //
                  setATkey(PART::aftertouchType::filterCutoffDown, o->value());
}
void PartUI::cb_polyfilterCminus(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_polyfilterCminus_i(o,v);
}

void PartUI::cb_polyfilterQ_i(Fl_Check_Button2* o, void*) {
  //
                  if (o->value())
                      polyfilterQminus->activate();
                  else
                  {
                      polyfilterQminus->value(0);
                      polyfilterQminus->deactivate();
                  }
                  setATkey(PART::aftertouchType::filterQ, o->value());
}
void PartUI::cb_polyfilterQ(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_polyfilterQ_i(o,v);
}

void PartUI::cb_polyfilterQminus_i(Fl_Check_Button2* o, void*) {
  //
                  setATkey(PART::aftertouchType::filterQdown, o->value());
}
void PartUI::cb_polyfilterQminus(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_polyfilterQminus_i(o,v);
}

void PartUI::cb_polypitchbend_i(Fl_Check_Button2* o, void*) {
  //
                  if (o->value())
                      polypitchBminus->activate();
                  else
                  {
                      polypitchBminus->value(0);
                      polypitchBminus->deactivate();
                  }
                  setATkey(PART::aftertouchType::pitchBend, o->value());
}
void PartUI::cb_polypitchbend(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_polypitchbend_i(o,v);
}

void PartUI::cb_polypitchBminus_i(Fl_Check_Button2* o, void*) {
  //
                  setATkey(PART::aftertouchType::pitchBendDown, o->value());
}
void PartUI::cb_polypitchBminus(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_polypitchBminus_i(o,v);
}

void PartUI::cb_polymodulation_i(Fl_Check_Button2* o, void*) {
  //
                  setATkey(PART::aftertouchType::modulation, o->value());
}
void PartUI::cb_polymodulation(Fl_Check_Button2* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_polymodulation_i(o,v);
}

void PartUI::cb_atClose_i(Fl_Button*, void*) {
  //
          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();
}
void PartUI::cb_atClose(Fl_Button* o, void* v) {
  ((PartUI*)(o->parent()->user_data()))->cb_atClose_i(o,v);
}

ScaleTrackedWindow* PartUI::make_window() {
  { ScaleTrackedWindow* o = instrumenteditwindow = new ScaleTrackedWindow(395, 385, "Instrument Edit");
    instrumenteditwindow->box(FL_FLAT_BOX);
    instrumenteditwindow->color(FL_BACKGROUND_COLOR);
    instrumenteditwindow->selection_color(FL_BACKGROUND_COLOR);
    instrumenteditwindow->labeltype(FL_NO_LABEL);
    instrumenteditwindow->labelfont(0);
    instrumenteditwindow->labelsize(14);
    instrumenteditwindow->labelcolor(FL_FOREGROUND_COLOR);
    instrumenteditwindow->callback((Fl_Callback*)cb_instrumenteditwindow, (void*)(this));
    instrumenteditwindow->align(Fl_Align(FL_ALIGN_TOP));
    instrumenteditwindow->when(FL_WHEN_RELEASE);
    { Fl_Group* o = new Fl_Group(0, 222, 395, 162);
      o->box(FL_GTK_THIN_UP_BOX);
      { ADD = new Fl_Group(5, 246, 94, 72, "ADDsynth");
        ADD->box(FL_ENGRAVED_FRAME);
        ADD->labelfont(1);
        ADD->labelcolor((Fl_Color)64);
        { Fl_Check_Button2* o = adsynenabledcheck = new Fl_Check_Button2(12, 252, 80, 24, "Enabled");
          adsynenabledcheck->tooltip("enable/disable ADsynth");
          adsynenabledcheck->box(FL_PLASTIC_UP_BOX);
          adsynenabledcheck->down_box(FL_DOWN_BOX);
          adsynenabledcheck->color((Fl_Color)228);
          adsynenabledcheck->selection_color((Fl_Color)64);
          adsynenabledcheck->labeltype(FL_NORMAL_LABEL);
          adsynenabledcheck->labelfont(3);
          adsynenabledcheck->labelsize(11);
          adsynenabledcheck->labelcolor((Fl_Color)226);
          adsynenabledcheck->callback((Fl_Callback*)cb_adsynenabledcheck);
          adsynenabledcheck->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
          adsynenabledcheck->when(FL_WHEN_RELEASE);
          o->value(part->kit[0].Padenabled);
        } // Fl_Check_Button2* adsynenabledcheck
        { Fl_Box* o = addbox = new Fl_Box(8, 226, 84, 18);
          addbox->box(FL_FLAT_BOX);
          if (adsynenabledcheck->value() != 0 && engine != 0) o->color(add_back); else o->color(FL_BACKGROUND_COLOR);
        } // Fl_Box* addbox
        { Fl_Button* o = adeditbutton = new Fl_Button(12, 280, 80, 32, "Edit &Add");
          adeditbutton->tooltip("Right click: also close this");
          adeditbutton->box(FL_GTK_THIN_UP_BOX);
          adeditbutton->color((Fl_Color)198);
          adeditbutton->selection_color((Fl_Color)64);
          adeditbutton->labelfont(1);
          adeditbutton->labelcolor((Fl_Color)64);
          adeditbutton->callback((Fl_Callback*)cb_adeditbutton1);
          adeditbutton->align(Fl_Align(FL_ALIGN_WRAP));
          if (part->kit[0].Padenabled==0) o->deactivate();
        } // Fl_Button* adeditbutton
        ADD->end();
      } // Fl_Group* ADD
      { SUB = new Fl_Group(100, 246, 94, 72, "SUBsynth");
        SUB->box(FL_ENGRAVED_FRAME);
        SUB->labelfont(1);
        SUB->labelcolor((Fl_Color)64);
        { Fl_Check_Button2* o = subsynenabledcheck = new Fl_Check_Button2(107, 252, 80, 24, "Enabled");
          subsynenabledcheck->tooltip("enable/disable SUBsynth");
          subsynenabledcheck->box(FL_PLASTIC_UP_BOX);
          subsynenabledcheck->down_box(FL_DOWN_BOX);
          subsynenabledcheck->color((Fl_Color)228);
          subsynenabledcheck->selection_color((Fl_Color)64);
          subsynenabledcheck->labeltype(FL_NORMAL_LABEL);
          subsynenabledcheck->labelfont(3);
          subsynenabledcheck->labelsize(11);
          subsynenabledcheck->labelcolor((Fl_Color)226);
          subsynenabledcheck->callback((Fl_Callback*)cb_subsynenabledcheck);
          subsynenabledcheck->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
          subsynenabledcheck->when(FL_WHEN_RELEASE);
          o->value(part->kit[0].Psubenabled);
        } // Fl_Check_Button2* subsynenabledcheck
        { Fl_Box* o = subbox = new Fl_Box(103, 226, 84, 18);
          subbox->box(FL_FLAT_BOX);
          if (subsynenabledcheck->value() != 0 && engine != 0) o->color(sub_back); else o->color(FL_BACKGROUND_COLOR);
        } // Fl_Box* subbox
        { Fl_Button* o = subeditbutton = new Fl_Button(107, 280, 80, 32, "Edit &Sub");
          subeditbutton->tooltip("Right click: also close this");
          subeditbutton->box(FL_GTK_THIN_UP_BOX);
          subeditbutton->color((Fl_Color)198);
          subeditbutton->selection_color((Fl_Color)64);
          subeditbutton->labelfont(1);
          subeditbutton->labelcolor((Fl_Color)64);
          subeditbutton->callback((Fl_Callback*)cb_subeditbutton1);
          subeditbutton->align(Fl_Align(FL_ALIGN_WRAP));
          if (part->kit[0].Psubenabled==0) o->deactivate();
        } // Fl_Button* subeditbutton
        SUB->end();
      } // Fl_Group* SUB
      { PAD = new Fl_Group(195, 246, 94, 72, "PADsynth");
        PAD->box(FL_ENGRAVED_FRAME);
        PAD->labelfont(1);
        PAD->labelcolor((Fl_Color)64);
        { Fl_Check_Button2* o = padsynenabledcheck = new Fl_Check_Button2(202, 252, 80, 24, "Enabled");
          padsynenabledcheck->tooltip("enable/disable PADsynth");
          padsynenabledcheck->box(FL_PLASTIC_UP_BOX);
          padsynenabledcheck->down_box(FL_DOWN_BOX);
          padsynenabledcheck->color((Fl_Color)228);
          padsynenabledcheck->selection_color((Fl_Color)64);
          padsynenabledcheck->labeltype(FL_NORMAL_LABEL);
          padsynenabledcheck->labelfont(3);
          padsynenabledcheck->labelsize(11);
          padsynenabledcheck->labelcolor((Fl_Color)226);
          padsynenabledcheck->callback((Fl_Callback*)cb_padsynenabledcheck);
          padsynenabledcheck->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
          padsynenabledcheck->when(FL_WHEN_RELEASE);
          o->value(part->kit[0].Ppadenabled);
        } // Fl_Check_Button2* padsynenabledcheck
        { Fl_Box* o = padbox = new Fl_Box(198, 226, 84, 18);
          padbox->box(FL_FLAT_BOX);
          if (padsynenabledcheck->value() != 0 && engine != 0) o->color(pad_back); else o->color(FL_BACKGROUND_COLOR);
        } // Fl_Box* padbox
        { Fl_Button* o = padeditbutton = new Fl_Button(202, 280, 80, 32, "Edit &Pad");
          padeditbutton->tooltip("Right click: also close this");
          padeditbutton->box(FL_GTK_THIN_UP_BOX);
          padeditbutton->color((Fl_Color)198);
          padeditbutton->selection_color((Fl_Color)64);
          padeditbutton->labelfont(1);
          padeditbutton->labelcolor((Fl_Color)64);
          padeditbutton->callback((Fl_Callback*)cb_padeditbutton1);
          padeditbutton->align(Fl_Align(FL_ALIGN_WRAP));
          if (part->kit[0].Ppadenabled==0) o->deactivate();
        } // Fl_Button* padeditbutton
        PAD->end();
      } // Fl_Group* PAD
      { kitedit = new Fl_Button(295, 227, 94, 28, "&Kit Edit");
        kitedit->tooltip("Right click: also close this");
        kitedit->box(FL_GTK_THIN_UP_BOX);
        kitedit->color((Fl_Color)198);
        kitedit->selection_color((Fl_Color)64);
        kitedit->labelfont(1);
        kitedit->labelcolor((Fl_Color)64);
        kitedit->callback((Fl_Callback*)cb_kitedit);
        kitedit->align(Fl_Align(FL_ALIGN_WRAP));
      } // Fl_Button* kitedit
      { effects = new Fl_Button(295, 258, 94, 28, "&Effects");
        effects->tooltip("Right click: also close this");
        effects->box(FL_GTK_THIN_UP_BOX);
        effects->color((Fl_Color)198);
        effects->labelfont(1);
        effects->labelcolor((Fl_Color)64);
        effects->callback((Fl_Callback*)cb_effects);
      } // Fl_Button* effects
      { editAT = new Fl_Button(295, 290, 94, 28, "After&touch");
        editAT->box(FL_GTK_THIN_UP_BOX);
        editAT->color((Fl_Color)198);
        editAT->labelfont(1);
        editAT->labelcolor((Fl_Color)64);
        editAT->callback((Fl_Callback*)cb_editAT);
      } // Fl_Button* editAT
      { instrumentReset = new Fl_Button(283, 327, 100, 26, "&Reset");
        instrumentReset->tooltip("Revert to default instrument\n +Ctrl, clear entire part");
        instrumentReset->box(FL_PLASTIC_UP_BOX);
        instrumentReset->color((Fl_Color)89);
        instrumentReset->labelfont(1);
        instrumentReset->labelcolor((Fl_Color)64);
        instrumentReset->callback((Fl_Callback*)cb_instrumentReset);
      } // Fl_Button* instrumentReset
      { editClose = new Fl_Button(283, 357, 100, 24, "&Close");
        editClose->box(FL_THIN_UP_BOX);
        editClose->color((Fl_Color)196);
        editClose->labelfont(1);
        editClose->labelcolor((Fl_Color)64);
        editClose->callback((Fl_Callback*)cb_editClose);
      } // Fl_Button* editClose
      o->end();
    } // Fl_Group* o
    { Fl_Group* o = new Fl_Group(0, 2, 395, 216);
      o->box(FL_ENGRAVED_FRAME);
      o->labelcolor((Fl_Color)64);
      { A_C_display = new Fl_Text_Display(171, 44, 148, 4, "Author and Copyright");
        A_C_display->box(FL_NO_BOX);
        A_C_display->labelsize(12);
        A_C_display->labelcolor((Fl_Color)64);
      } // Fl_Text_Display* A_C_display
      { A_C_default = new Fl_Button(327, 25, 63, 20, "Default");
        A_C_default->tooltip("Load default author & copyright\n + Ctrl: save current text as default");
        A_C_default->labelsize(12);
        A_C_default->labelcolor((Fl_Color)64);
        A_C_default->callback((Fl_Callback*)cb_A_C_default);
      } // Fl_Button* A_C_default
      { Fl_Input* o = copyright = new Fl_Input(5, 49, 385, 55);
        copyright->type(4);
        copyright->color((Fl_Color)182);
        copyright->labelsize(12);
        copyright->labelcolor((Fl_Color)64);
        copyright->textcolor((Fl_Color)64);
        copyright->callback((Fl_Callback*)cb_copyright);
        copyright->align(Fl_Align(FL_ALIGN_TOP_RIGHT));
        o->maximum_size(MAX_INFO_TEXT_SIZE);
        o->value(part->info.Pauthor.c_str());
      } // Fl_Input* copyright
      { Fl_Input* o = commentField = new Fl_Input(5, 123, 385, 91, "Comments");
        commentField->type(4);
        commentField->color((Fl_Color)182);
        commentField->labelsize(12);
        commentField->labelcolor((Fl_Color)64);
        commentField->textcolor((Fl_Color)64);
        commentField->callback((Fl_Callback*)cb_commentField);
        commentField->align(Fl_Align(FL_ALIGN_TOP_LEFT));
        o->maximum_size(MAX_INFO_TEXT_SIZE);
        o->value(part->info.Pcomments.c_str());
      } // Fl_Input* commentField
      { Fl_Choice* o = instrumentType = new Fl_Choice(5, 25, 155, 20, "Type:");
        instrumentType->down_box(FL_BORDER_BOX);
        instrumentType->labelfont(1);
        instrumentType->labelsize(11);
        instrumentType->labelcolor((Fl_Color)64);
        instrumentType->textfont(1);
        instrumentType->textsize(11);
        instrumentType->textcolor((Fl_Color)64);
        instrumentType->callback((Fl_Callback*)cb_instrumentType);
        instrumentType->align(Fl_Align(FL_ALIGN_TOP_LEFT));
        fillInstrumentType();
        o->value(part->info.Ptype);
      } // Fl_Choice* instrumentType
      o->end();
    } // Fl_Group* o
    { humaniseBox = new Fl_Box(0, 324, 272, 58);
      humaniseBox->box(FL_ENGRAVED_FRAME);
      humaniseBox->labelfont(1);
      humaniseBox->align(Fl_Align(FL_ALIGN_RIGHT));
    } // Fl_Box* humaniseBox
    { humanise_display = new Fl_Text_Display(102, 342, 78, 7, "Humanise");
      humanise_display->box(FL_NO_BOX);
      humanise_display->labelfont(1);
      humanise_display->labelcolor((Fl_Color)64);
    } // Fl_Text_Display* humanise_display
    { mwheel_slider_rev* o = humanise = new mwheel_slider_rev(12, 342, 202, 16, "Detune");
      humanise->tooltip("Random detune of whole part in cents");
      humanise->type(5);
      humanise->box(FL_THIN_DOWN_BOX);
      humanise->color(FL_BACKGROUND_COLOR);
      humanise->selection_color(FL_BACKGROUND_COLOR);
      humanise->labeltype(FL_NORMAL_LABEL);
      humanise->labelfont(0);
      humanise->labelsize(12);
      humanise->labelcolor((Fl_Color)64);
      humanise->maximum(50);
      humanise->step(1);
      humanise->textcolor((Fl_Color)64);
      humanise->callback((Fl_Callback*)cb_humanise);
      humanise->align(Fl_Align(FL_ALIGN_RIGHT));
      humanise->when(FL_WHEN_CHANGED);
      o->setValueType(VC_PartHumaniseDetune);o->useCustomTip(true);
      o->selection_color(setSlider(o->value(),0));
    } // mwheel_slider_rev* humanise
    { mwheel_slider_rev* o = velocityhumanise = new mwheel_slider_rev(12, 362, 202, 16, "Velocity");
      velocityhumanise->tooltip("Random velocity attenuation of whole part");
      velocityhumanise->type(5);
      velocityhumanise->box(FL_THIN_DOWN_BOX);
      velocityhumanise->color(FL_BACKGROUND_COLOR);
      velocityhumanise->selection_color(FL_BACKGROUND_COLOR);
      velocityhumanise->labeltype(FL_NORMAL_LABEL);
      velocityhumanise->labelfont(0);
      velocityhumanise->labelsize(12);
      velocityhumanise->labelcolor((Fl_Color)64);
      velocityhumanise->maximum(50);
      velocityhumanise->step(1);
      velocityhumanise->textcolor((Fl_Color)64);
      velocityhumanise->callback((Fl_Callback*)cb_velocityhumanise);
      velocityhumanise->align(Fl_Align(FL_ALIGN_RIGHT));
      velocityhumanise->when(FL_WHEN_CHANGED);
      o->setValueType(VC_PartHumaniseVelocity);o->useCustomTip(true);
      o->selection_color(setSlider(o->value(),0));
    } // mwheel_slider_rev* velocityhumanise
    { originalname = new Fl_Text_Display(200, 108, 1, 15, "Derived From");
      originalname->box(FL_NO_BOX);
      originalname->labelfont(1);
      originalname->labelsize(12);
      originalname->labelcolor((Fl_Color)64);
      originalname->textsize(11);
      originalname->textcolor((Fl_Color)64);
      originalname->align(Fl_Align(FL_ALIGN_LEFT));
      originalname->hide();
    } // Fl_Text_Display* originalname
    { originaltext = new Fl_Text_Display(198, 108, 1, 15, "text");
      originaltext->box(FL_NO_BOX);
      originaltext->labelfont(1);
      originaltext->labelsize(12);
      originaltext->labelcolor((Fl_Color)225);
      originaltext->textsize(11);
      originaltext->align(Fl_Align(FL_ALIGN_RIGHT));
      originaltext->hide();
    } // Fl_Text_Display* originaltext
    instrumenteditwindow->resizable(instrumenteditwindow);
    seteditname();
    o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Edit"), npart, TOPLEVEL::windowTitle)).c_str());
    editDW = 395; editDH = 385;
    o->size_range(editDW, editDH, 0, 0, 0, 0, 1);
    instrumenteditwindow->end();
  } // ScaleTrackedWindow* instrumenteditwindow
  { ScaleTrackedWindow* o = instrumentkitlist = new ScaleTrackedWindow(670, 370, "Instrument Kit");
    instrumentkitlist->box(FL_FLAT_BOX);
    instrumentkitlist->color(FL_BACKGROUND_COLOR);
    instrumentkitlist->selection_color(FL_BACKGROUND_COLOR);
    instrumentkitlist->labeltype(FL_NO_LABEL);
    instrumentkitlist->labelfont(0);
    instrumentkitlist->labelsize(14);
    instrumentkitlist->labelcolor(FL_FOREGROUND_COLOR);
    instrumentkitlist->callback((Fl_Callback*)cb_instrumentkitlist, (void*)(this));
    instrumentkitlist->align(Fl_Align(FL_ALIGN_TOP));
    instrumentkitlist->when(FL_WHEN_RELEASE);
    { kitlist = new Fl_Group(4, 20, 662, 324);
      kitlist->box(FL_THIN_UP_FRAME);
      { kitpack = new Fl_Pack(0, 21, 670, 322);
        for (int i=0;i<NUM_KIT_ITEMS;i++){partkititem[i]=new PartKitItem(0,0,670,20,"");partkititem[i]->init(part, i, npart, this);}
        kitpack->end();
      } // Fl_Pack* kitpack
      kitlist->end();
    } // Fl_Group* kitlist
    { kitnum = new Fl_Box(10, 0, 25, 15, "No.");
      kitnum->labelfont(1);
      kitnum->labelsize(11);
      kitnum->labelcolor((Fl_Color)64);
      kitnum->align(Fl_Align(FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE));
    } // Fl_Box* kitnum
    { kitmute = new Fl_Box(56, 15, 22, 8, "Mute");
      kitmute->labelfont(3);
      kitmute->labelsize(11);
      kitmute->labelcolor((Fl_Color)226);
      kitmute->align(Fl_Align(FL_ALIGN_TOP));
    } // Fl_Box* kitmute
    { kitID = new Fl_Box(137, 0, 40, 15, "Name");
      kitID->labelfont(1);
      kitID->labelsize(11);
      kitID->labelcolor((Fl_Color)64);
      kitID->align(Fl_Align(FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE));
    } // Fl_Box* kitID
    { kitminkey = new Fl_Box(236, 0, 40, 15, "Min key");
      kitminkey->labelfont(1);
      kitminkey->labelsize(11);
      kitminkey->labelcolor((Fl_Color)64);
      kitminkey->align(Fl_Align(FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE));
    } // Fl_Box* kitminkey
    { kitmaxkey = new Fl_Box(364, 0, 40, 15, "Max key");
      kitmaxkey->labelfont(1);
      kitmaxkey->labelsize(11);
      kitmaxkey->labelcolor((Fl_Color)64);
      kitmaxkey->align(Fl_Align(FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE));
    } // Fl_Box* kitmaxkey
    { addON = new Fl_Text_Display(423, 15, 22, 8, "On");
      addON->box(FL_NO_BOX);
      addON->labelfont(3);
      addON->labelsize(11);
      addON->labelcolor((Fl_Color)226);
    } // Fl_Text_Display* addON
    { kitadd = new Fl_Box(446, 0, 34, 15, "ADD");
      kitadd->labelfont(1);
      kitadd->labelsize(11);
      kitadd->labelcolor((Fl_Color)64);
      kitadd->align(Fl_Align(FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE));
    } // Fl_Box* kitadd
    { subON = new Fl_Text_Display(489, 15, 22, 9, "On");
      subON->box(FL_NO_BOX);
      subON->labelfont(3);
      subON->labelsize(11);
      subON->labelcolor((Fl_Color)226);
    } // Fl_Text_Display* subON
    { kitsub = new Fl_Box(507, 0, 40, 15, "SUB");
      kitsub->labelfont(1);
      kitsub->labelsize(11);
      kitsub->labelcolor((Fl_Color)64);
      kitsub->align(Fl_Align(FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE));
    } // Fl_Box* kitsub
    { padON = new Fl_Text_Display(554, 15, 22, 10, "On");
      padON->box(FL_NO_BOX);
      padON->labelfont(3);
      padON->labelsize(11);
      padON->labelcolor((Fl_Color)226);
    } // Fl_Text_Display* padON
    { kitpad = new Fl_Box(572, 0, 37, 15, "PAD");
      kitpad->labelfont(1);
      kitpad->labelsize(11);
      kitpad->labelcolor((Fl_Color)64);
      kitpad->align(Fl_Align(FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE));
    } // Fl_Box* kitpad
    { kitfxnum = new Fl_Box(620, 0, 30, 15, "FX.r.");
      kitfxnum->labelfont(1);
      kitfxnum->labelsize(11);
      kitfxnum->labelcolor((Fl_Color)64);
      kitfxnum->align(Fl_Align(FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE));
    } // Fl_Box* kitfxnum
    { Fl_Choice* o = kitMode = new Fl_Choice(41, 348, 148, 19, "Mode");
      kitMode->tooltip("Single = only 1st item in defined note range sounds");
      kitMode->down_box(FL_BORDER_BOX);
      kitMode->labelsize(11);
      kitMode->labelcolor((Fl_Color)64);
      kitMode->textfont(1);
      kitMode->textsize(11);
      kitMode->textcolor((Fl_Color)64);
      kitMode->callback((Fl_Callback*)cb_kitMode);
      o->add("Off");o->add("Multi");o->add("Single");o->add("Crossfade (velocity)");o->add("Crossfade (volume)");
      if (part->PkitfadeType == 1) {o->value(3);} else if (part->PkitfadeType == 2) {o->value(4);} else {o->value(part->Pkitmode);}
      partKitOn = o->value() > 0;
      if (!partKitOn) kitlist->deactivate();
    } // Fl_Choice* kitMode
    { Fl_Check_Button2* o = drumMode = new Fl_Check_Button2(285, 350, 15, 15, "Drum mode");
      drumMode->tooltip("Disables microtonal tuning");
      drumMode->box(FL_NO_BOX);
      drumMode->down_box(FL_DOWN_BOX);
      drumMode->color(FL_BACKGROUND_COLOR);
      drumMode->selection_color((Fl_Color)64);
      drumMode->labeltype(FL_NORMAL_LABEL);
      drumMode->labelfont(0);
      drumMode->labelsize(11);
      drumMode->labelcolor((Fl_Color)64);
      drumMode->callback((Fl_Callback*)cb_drumMode);
      drumMode->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      drumMode->when(FL_WHEN_RELEASE);
      o->value(part->Pdrummode);
    } // Fl_Check_Button2* drumMode
    { kitClose = new Fl_Button(569, 348, 63, 20, "&Close");
      kitClose->tooltip("Right click: also reopen previous");
      kitClose->box(FL_THIN_UP_BOX);
      kitClose->color((Fl_Color)196);
      kitClose->labelcolor((Fl_Color)64);
      kitClose->callback((Fl_Callback*)cb_kitClose);
    } // Fl_Button* kitClose
    instrumentkitlist->resizable(instrumentkitlist);
    o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Kit List"), npart, TOPLEVEL::windowTitle)).c_str());
    kitDW = o->w(); kitDH = o->h();
    o->size_range(kitDW, kitDH, 0, 0, 0, 0, 1);
    instrumentkitlist->end();
  } // ScaleTrackedWindow* instrumentkitlist
  { ScaleTrackedWindow* o = partfx = new ScaleTrackedWindow(385, 160, "Part\'s Insert Effects");
    partfx->box(FL_FLAT_BOX);
    partfx->color(FL_BACKGROUND_COLOR);
    partfx->selection_color(FL_BACKGROUND_COLOR);
    partfx->labeltype(FL_NO_LABEL);
    partfx->labelfont(0);
    partfx->labelsize(14);
    partfx->labelcolor(FL_FOREGROUND_COLOR);
    partfx->callback((Fl_Callback*)cb_partfx, (void*)(this));
    partfx->align(Fl_Align(FL_ALIGN_TOP));
    partfx->when(FL_WHEN_RELEASE);
    { WidgetSpinner* o = inseffnocounter = new WidgetSpinner(20, 8, 35, 22);
      inseffnocounter->tooltip("Effect No.");
      inseffnocounter->box(FL_NO_BOX);
      inseffnocounter->color(FL_BACKGROUND_COLOR);
      inseffnocounter->selection_color(FL_BACKGROUND_COLOR);
      inseffnocounter->labeltype(FL_NORMAL_LABEL);
      inseffnocounter->labelfont(0);
      inseffnocounter->labelsize(12);
      inseffnocounter->labelcolor((Fl_Color)64);
      inseffnocounter->maximum(3);
      inseffnocounter->textsize(12);
      inseffnocounter->textcolor((Fl_Color)64);
      inseffnocounter->callback((Fl_Callback*)cb_inseffnocounter);
      inseffnocounter->align(Fl_Align(FL_ALIGN_LEFT));
      inseffnocounter->when(FL_WHEN_RELEASE);
      o->range(1, NUM_PART_EFX);
      o->value(1);
    } // WidgetSpinner* inseffnocounter
    { Fl_Choice* o = insefftype = new Fl_Choice(86, 8, 92, 22);
      insefftype->tooltip("Effect Type");
      insefftype->down_box(FL_BORDER_BOX);
      insefftype->labelsize(11);
      insefftype->labelcolor((Fl_Color)64);
      insefftype->textfont(1);
      insefftype->textsize(12);
      insefftype->textcolor((Fl_Color)64);
      insefftype->callback((Fl_Callback*)cb_insefftype);
      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");
      o->value(0); // initially "No Effect"
    } // Fl_Choice* insefftype
    { inseffectuigroup = new Fl_Group(3, 37, 380, 96);
      inseffectuigroup->box(FL_FLAT_BOX);
      inseffectuigroup->color((Fl_Color)48);
      { EffUI* o = inseffectui = new EffUI(5, 38, 379, 95);
        inseffectui->box(FL_NO_BOX);
        inseffectui->color(FL_BACKGROUND_COLOR);
        inseffectui->selection_color(FL_BACKGROUND_COLOR);
        inseffectui->labeltype(FL_NORMAL_LABEL);
        inseffectui->labelfont(0);
        inseffectui->labelsize(14);
        inseffectui->labelcolor(FL_FOREGROUND_COLOR);
        inseffectui->align(Fl_Align(FL_ALIGN_TOP));
        inseffectui->when(FL_WHEN_RELEASE);
        InterfaceAnchor& anchor = synth->getGuiMaster()->anchor;
                 o->init(synth, anchor.partEffectParam, anchor.partEffectEQ, npart);
        inseffectui->end();
      } // EffUI* inseffectui
      inseffectuigroup->end();
    } // Fl_Group* inseffectuigroup
    { Fl_Choice* o = sendtochoice = new Fl_Choice(225, 8, 102, 22, "To");
      sendtochoice->down_box(FL_BORDER_BOX);
      sendtochoice->labelfont(1);
      sendtochoice->labelsize(12);
      sendtochoice->labelcolor((Fl_Color)64);
      sendtochoice->textfont(1);
      sendtochoice->textsize(12);
      sendtochoice->textcolor((Fl_Color)64);
      sendtochoice->callback((Fl_Callback*)cb_sendtochoice);
      o->add("Next Effect");o->add("Part Out");o->add("Dry Out");
      o->value(0);
    } // Fl_Choice* sendtochoice
    { effCopy = new Fl_Button(346, 3, 25, 15, "C");
      effCopy->box(FL_THIN_UP_BOX);
      effCopy->color((Fl_Color)179);
      effCopy->labelfont(1);
      effCopy->labelsize(11);
      effCopy->labelcolor((Fl_Color)197);
      effCopy->callback((Fl_Callback*)cb_effCopy);
    } // Fl_Button* effCopy
    { effPaste = new Fl_Button(346, 19, 25, 15, "P");
      effPaste->box(FL_THIN_UP_BOX);
      effPaste->color((Fl_Color)179);
      effPaste->labelfont(1);
      effPaste->labelsize(11);
      effPaste->labelcolor((Fl_Color)197);
      effPaste->callback((Fl_Callback*)cb_effPaste);
    } // Fl_Button* effPaste
    { Fl_Check_Button2* o = bypasseff = new Fl_Check_Button2(20, 135, 63, 21, "Bypass");
      bypasseff->tooltip("if the effect is not used (is bypassed)");
      bypasseff->box(FL_NO_BOX);
      bypasseff->down_box(FL_DOWN_BOX);
      bypasseff->color(FL_BACKGROUND_COLOR);
      bypasseff->selection_color((Fl_Color)64);
      bypasseff->labeltype(FL_NORMAL_LABEL);
      bypasseff->labelfont(3);
      bypasseff->labelsize(12);
      bypasseff->labelcolor((Fl_Color)226);
      bypasseff->callback((Fl_Callback*)cb_bypasseff);
      bypasseff->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      bypasseff->when(FL_WHEN_RELEASE);
      o->value(false);
    } // Fl_Check_Button2* bypasseff
    { effClose = new Fl_Button(307, 136, 60, 20, "&Close");
      effClose->tooltip("Right click: also reopen previous");
      effClose->box(FL_THIN_UP_BOX);
      effClose->color((Fl_Color)196);
      effClose->labelcolor((Fl_Color)64);
      effClose->callback((Fl_Callback*)cb_effClose);
    } // Fl_Button* effClose
    partfx->resizable(partfx);
    o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Effects"), npart, TOPLEVEL::windowTitle)).c_str());
    fxDW = o->w(); fxDH = o->h();
    o->size_range(fxDW, fxDH, 0, 0, 0, 0, 1);
    partfx->end();
  } // ScaleTrackedWindow* partfx
// ctlmidi, ctlwindow, aftertouch control MUST be that order
  { ScaleTrackedWindow* o = ctlmidi = new ScaleTrackedWindow(365, 60, "MIDI Controls");
    ctlmidi->box(FL_FLAT_BOX);
    ctlmidi->color(FL_BACKGROUND_COLOR);
    ctlmidi->selection_color(FL_BACKGROUND_COLOR);
    ctlmidi->labeltype(FL_NO_LABEL);
    ctlmidi->labelfont(0);
    ctlmidi->labelsize(14);
    ctlmidi->labelcolor(FL_FOREGROUND_COLOR);
    ctlmidi->user_data((void*)(this));
    ctlmidi->align(Fl_Align(FL_ALIGN_TOP));
    ctlmidi->when(FL_WHEN_RELEASE);
    { WidgetPDial* o = modulation = new WidgetPDial(20, 10, 30, 30, "Modulation");
      modulation->tooltip("Modulation Wheel");
      modulation->box(FL_OVAL_BOX);
      modulation->color(FL_BACKGROUND_COLOR);
      modulation->selection_color(FL_INACTIVE_COLOR);
      modulation->labeltype(FL_NORMAL_LABEL);
      modulation->labelfont(0);
      modulation->labelsize(10);
      modulation->labelcolor((Fl_Color)64);
      modulation->maximum(127);
      modulation->step(1);
      modulation->callback((Fl_Callback*)cb_modulation);
      modulation->align(Fl_Align(FL_ALIGN_BOTTOM));
      modulation->when(FL_WHEN_CHANGED);
      o->value(part->ctl->modwheel.data);
      o->setValueType(VC_percent127);
      o->selection_color(setKnob(o->value(),64));
    } // WidgetPDial* modulation
    { WidgetPDial* o = expression = new WidgetPDial(80, 10, 30, 30, "Expression");
      expression->tooltip("Expression");
      expression->box(FL_OVAL_BOX);
      expression->color(FL_BACKGROUND_COLOR);
      expression->selection_color(FL_INACTIVE_COLOR);
      expression->labeltype(FL_NORMAL_LABEL);
      expression->labelfont(0);
      expression->labelsize(10);
      expression->labelcolor((Fl_Color)64);
      expression->maximum(127);
      expression->step(1);
      expression->callback((Fl_Callback*)cb_expression);
      expression->align(Fl_Align(FL_ALIGN_BOTTOM));
      expression->when(FL_WHEN_CHANGED);
      o->value(part->ctl->expression.data);
      o->setValueType(VC_percent127);
      o->selection_color(setKnob(o->value(),127));
    } // WidgetPDial* expression
    { WidgetPDial* o = filterq = new WidgetPDial(140, 10, 30, 30, "Filter Q");
      filterq->tooltip("Filter Q");
      filterq->box(FL_OVAL_BOX);
      filterq->color(FL_BACKGROUND_COLOR);
      filterq->selection_color(FL_INACTIVE_COLOR);
      filterq->labeltype(FL_NORMAL_LABEL);
      filterq->labelfont(0);
      filterq->labelsize(10);
      filterq->labelcolor((Fl_Color)64);
      filterq->maximum(127);
      filterq->step(1);
      filterq->callback((Fl_Callback*)cb_filterq);
      filterq->align(Fl_Align(FL_ALIGN_BOTTOM));
      filterq->when(FL_WHEN_CHANGED);
      o->value(part->ctl->filterq.data);
      o->setValueType(VC_percent127);
      o->selection_color(setKnob(o->value(),64));
    } // WidgetPDial* filterq
    { WidgetPDial* o = filtercutoff = new WidgetPDial(200, 10, 30, 30, "Filter Cutoff");
      filtercutoff->tooltip("Filter Cutoff");
      filtercutoff->box(FL_OVAL_BOX);
      filtercutoff->color(FL_BACKGROUND_COLOR);
      filtercutoff->selection_color(FL_INACTIVE_COLOR);
      filtercutoff->labeltype(FL_NORMAL_LABEL);
      filtercutoff->labelfont(0);
      filtercutoff->labelsize(10);
      filtercutoff->labelcolor((Fl_Color)64);
      filtercutoff->maximum(127);
      filtercutoff->step(1);
      filtercutoff->callback((Fl_Callback*)cb_filtercutoff);
      filtercutoff->align(Fl_Align(FL_ALIGN_BOTTOM));
      filtercutoff->when(FL_WHEN_CHANGED);
      o->value(part->ctl->filtercutoff.data);
      o->setValueType(VC_percent127);
      o->selection_color(setKnob(o->value(),64));
    } // WidgetPDial* filtercutoff
    { WidgetPDial* o = masterbandwidth = new WidgetPDial(260, 10, 30, 30, "Bandwidth");
      masterbandwidth->tooltip("Master Bandwidth");
      masterbandwidth->box(FL_OVAL_BOX);
      masterbandwidth->color(FL_BACKGROUND_COLOR);
      masterbandwidth->selection_color(FL_INACTIVE_COLOR);
      masterbandwidth->labeltype(FL_NORMAL_LABEL);
      masterbandwidth->labelfont(0);
      masterbandwidth->labelsize(10);
      masterbandwidth->labelcolor((Fl_Color)64);
      masterbandwidth->maximum(127);
      masterbandwidth->step(1);
      masterbandwidth->callback((Fl_Callback*)cb_masterbandwidth);
      masterbandwidth->align(Fl_Align(FL_ALIGN_BOTTOM));
      masterbandwidth->when(FL_WHEN_CHANGED);
      o->value(part->ctl->bandwidth.data);
      o->setValueType(VC_percent127);
      o->selection_color(setKnob(o->value(),64));
    } // WidgetPDial* masterbandwidth
    { ctlmidiclose = new Fl_Button(309, 35, 50, 20, "&Close");
      ctlmidiclose->box(FL_THIN_UP_BOX);
      ctlmidiclose->color((Fl_Color)196);
      ctlmidiclose->labelcolor((Fl_Color)64);
      ctlmidiclose->callback((Fl_Callback*)cb_ctlmidiclose);
    } // Fl_Button* ctlmidiclose
    ctlmidi->resizable(ctlmidi);
    o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("MIDI Controls"), npart, TOPLEVEL::windowTitle)).c_str());
    midiDW = o->w(); midiDH = o->h();
    o->size_range(midiDW, midiDH, 0, 0, 0, 0, 1);
    ctlmidi->end();
  } // ScaleTrackedWindow* ctlmidi
  { ScaleTrackedWindow* o = ctlwindow = new ScaleTrackedWindow(505, 130, "Controllers");
    ctlwindow->box(FL_FLAT_BOX);
    ctlwindow->color(FL_BACKGROUND_COLOR);
    ctlwindow->selection_color(FL_BACKGROUND_COLOR);
    ctlwindow->labeltype(FL_NO_LABEL);
    ctlwindow->labelfont(0);
    ctlwindow->labelsize(14);
    ctlwindow->labelcolor(FL_FOREGROUND_COLOR);
    ctlwindow->callback((Fl_Callback*)cb_ctlwindow, (void*)(this));
    ctlwindow->align(Fl_Align(FL_ALIGN_TOP));
    ctlwindow->when(FL_WHEN_RELEASE);
    { WidgetPDial* o = volrng = new WidgetPDial(132, 55, 30, 30, "Vol Rng");
      volrng->tooltip("Volume Range");
      volrng->box(FL_OVAL_BOX);
      volrng->color(FL_BACKGROUND_COLOR);
      volrng->selection_color(FL_INACTIVE_COLOR);
      volrng->labeltype(FL_NORMAL_LABEL);
      volrng->labelfont(0);
      volrng->labelsize(10);
      volrng->labelcolor((Fl_Color)64);
      volrng->minimum(64);
      volrng->maximum(127);
      volrng->step(1);
      volrng->callback((Fl_Callback*)cb_volrng);
      volrng->align(Fl_Align(FL_ALIGN_BOTTOM));
      volrng->when(FL_WHEN_CHANGED);
      o->value(part->ctl->volume.data);
      o->selection_color(setKnob(o->value(),96));
    } // WidgetPDial* volrng
    { Fl_Check_Button2* o = vol = new Fl_Check_Button2(175, 81, 45, 18, "Vol");
      vol->tooltip("Volume enable");
      vol->box(FL_THIN_UP_BOX);
      vol->down_box(FL_DOWN_BOX);
      vol->color(FL_BACKGROUND_COLOR);
      vol->selection_color((Fl_Color)64);
      vol->labeltype(FL_NORMAL_LABEL);
      vol->labelfont(0);
      vol->labelsize(10);
      vol->labelcolor((Fl_Color)64);
      vol->callback((Fl_Callback*)cb_vol);
      vol->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      vol->when(FL_WHEN_RELEASE);
      o->value(part->ctl->volume.receive);
    } // Fl_Check_Button2* vol
    { WidgetPDial* o = panwidth = new WidgetPDial(10, 55, 30, 30, "PanWdth");
      panwidth->tooltip("Panning Width");
      panwidth->box(FL_OVAL_BOX);
      panwidth->color(FL_BACKGROUND_COLOR);
      panwidth->selection_color(FL_INACTIVE_COLOR);
      panwidth->labeltype(FL_NORMAL_LABEL);
      panwidth->labelfont(0);
      panwidth->labelsize(10);
      panwidth->labelcolor((Fl_Color)64);
      panwidth->maximum(64);
      panwidth->step(1);
      panwidth->callback((Fl_Callback*)cb_panwidth);
      panwidth->align(Fl_Align(FL_ALIGN_BOTTOM));
      panwidth->when(FL_WHEN_CHANGED);
      o->value(part->ctl->panning.depth);
      o->selection_color(setKnob(o->value(),64));
    } // WidgetPDial* panwidth
    { WidgetPDial* o = modwh = new WidgetPDial(50, 10, 30, 30, "ModWh");
      modwh->tooltip("Modulation Wheel depth");
      modwh->box(FL_OVAL_BOX);
      modwh->color(FL_BACKGROUND_COLOR);
      modwh->selection_color(FL_INACTIVE_COLOR);
      modwh->labeltype(FL_NORMAL_LABEL);
      modwh->labelfont(0);
      modwh->labelsize(10);
      modwh->labelcolor((Fl_Color)64);
      modwh->maximum(127);
      modwh->step(1);
      modwh->callback((Fl_Callback*)cb_modwh);
      modwh->align(Fl_Align(FL_ALIGN_BOTTOM));
      modwh->when(FL_WHEN_CHANGED);
      o->value(part->ctl->modwheel.depth);
      o->selection_color(setKnob(o->value(),80));
    } // WidgetPDial* modwh
    { Fl_Check_Button2* o = expmwh = new Fl_Check_Button2(10, 15, 40, 25, "Exp MWh");
      expmwh->tooltip("Exponential modulation wheel");
      expmwh->box(FL_NO_BOX);
      expmwh->down_box(FL_DOWN_BOX);
      expmwh->color(FL_BACKGROUND_COLOR);
      expmwh->selection_color((Fl_Color)64);
      expmwh->labeltype(FL_NORMAL_LABEL);
      expmwh->labelfont(0);
      expmwh->labelsize(10);
      expmwh->labelcolor((Fl_Color)64);
      expmwh->callback((Fl_Callback*)cb_expmwh);
      expmwh->align(Fl_Align(132|FL_ALIGN_INSIDE));
      expmwh->when(FL_WHEN_RELEASE);
      o->value(part->ctl->modwheel.exponential);
    } // Fl_Check_Button2* expmwh
    { WidgetPDial* o = bwdpth = new WidgetPDial(132, 10, 30, 30, "BwDpth");
      bwdpth->tooltip("BandWidth depth");
      bwdpth->box(FL_OVAL_BOX);
      bwdpth->color(FL_BACKGROUND_COLOR);
      bwdpth->selection_color(FL_INACTIVE_COLOR);
      bwdpth->labeltype(FL_NORMAL_LABEL);
      bwdpth->labelfont(0);
      bwdpth->labelsize(10);
      bwdpth->labelcolor((Fl_Color)64);
      bwdpth->maximum(127);
      bwdpth->step(1);
      bwdpth->callback((Fl_Callback*)cb_bwdpth);
      bwdpth->align(Fl_Align(FL_ALIGN_BOTTOM));
      bwdpth->when(FL_WHEN_CHANGED);
      o->value(part->ctl->bandwidth.depth);
      o->selection_color(setKnob(o->value(),64));
    } // WidgetPDial* bwdpth
    { Fl_Check_Button2* o = expbw = new Fl_Check_Button2(92, 15, 35, 25, "Exp BW");
      expbw->tooltip("Exponential BandWidth Controller");
      expbw->box(FL_NO_BOX);
      expbw->down_box(FL_DOWN_BOX);
      expbw->color(FL_BACKGROUND_COLOR);
      expbw->selection_color((Fl_Color)64);
      expbw->labeltype(FL_NORMAL_LABEL);
      expbw->labelfont(0);
      expbw->labelsize(10);
      expbw->labelcolor((Fl_Color)64);
      expbw->callback((Fl_Callback*)cb_expbw);
      expbw->align(Fl_Align(132|FL_ALIGN_INSIDE));
      expbw->when(FL_WHEN_RELEASE);
      o->value(part->ctl->bandwidth.exponential);
    } // Fl_Check_Button2* expbw
    { Fl_Check_Button2* o = expr = new Fl_Check_Button2(175, 59, 45, 18, "Expr");
      expr->tooltip("Expression enable");
      expr->box(FL_THIN_UP_BOX);
      expr->down_box(FL_DOWN_BOX);
      expr->color(FL_BACKGROUND_COLOR);
      expr->selection_color((Fl_Color)64);
      expr->labeltype(FL_NORMAL_LABEL);
      expr->labelfont(0);
      expr->labelsize(10);
      expr->labelcolor((Fl_Color)64);
      expr->callback((Fl_Callback*)cb_expr);
      expr->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      expr->when(FL_WHEN_RELEASE);
      o->value(part->ctl->expression.receive);
    } // Fl_Check_Button2* expr
    { Fl_Check_Button2* o = fmamp = new Fl_Check_Button2(225, 59, 60, 18, "FMamp");
      fmamp->tooltip("FM amplitude enable");
      fmamp->box(FL_THIN_UP_BOX);
      fmamp->down_box(FL_DOWN_BOX);
      fmamp->color(FL_BACKGROUND_COLOR);
      fmamp->selection_color((Fl_Color)64);
      fmamp->labeltype(FL_NORMAL_LABEL);
      fmamp->labelfont(0);
      fmamp->labelsize(10);
      fmamp->labelcolor((Fl_Color)64);
      fmamp->callback((Fl_Callback*)cb_fmamp);
      fmamp->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      fmamp->when(FL_WHEN_RELEASE);
      o->value(part->ctl->fmamp.receive);
    } // Fl_Check_Button2* fmamp
    { Fl_Check_Button2* o = sustain = new Fl_Check_Button2(225, 81, 60, 18, "Sustain");
      sustain->tooltip("Sustain pedal enable");
      sustain->box(FL_THIN_UP_BOX);
      sustain->down_box(FL_DOWN_BOX);
      sustain->color(FL_BACKGROUND_COLOR);
      sustain->selection_color((Fl_Color)64);
      sustain->labeltype(FL_NORMAL_LABEL);
      sustain->labelfont(0);
      sustain->labelsize(10);
      sustain->labelcolor((Fl_Color)64);
      sustain->callback((Fl_Callback*)cb_sustain);
      sustain->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      sustain->when(FL_WHEN_RELEASE);
      o->value(part->ctl->sustain.receive);
    } // Fl_Check_Button2* sustain
    { Fl_Check_Button2* o = breath = new Fl_Check_Button2(225, 38, 60, 18, "Breath");
      breath->tooltip("Breath Control enable");
      breath->box(FL_THIN_UP_BOX);
      breath->down_box(FL_DOWN_BOX);
      breath->color(FL_BACKGROUND_COLOR);
      breath->selection_color((Fl_Color)64);
      breath->labeltype(FL_NORMAL_LABEL);
      breath->labelfont(0);
      breath->labelsize(10);
      breath->labelcolor((Fl_Color)64);
      breath->callback((Fl_Callback*)cb_breath);
      breath->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      breath->when(FL_WHEN_RELEASE);
      o->value(part->PbreathControl == MIDI::CC::breath);
    } // Fl_Check_Button2* breath
    { pwheelrnglabel = new Fl_Box(170, 1, 117, 16, "PWheel Rng (cents)");
      pwheelrnglabel->labelfont(3);
      pwheelrnglabel->labelsize(10);
      pwheelrnglabel->labelcolor((Fl_Color)226);
    } // Fl_Box* pwheelrnglabel
    { Fl_Counter* o = pwheelbrng = new Fl_Counter(168, 16, 119, 18);
      pwheelbrng->tooltip("Pitch Wheel Bend Range (cents)");
      pwheelbrng->labelcolor((Fl_Color)64);
      pwheelbrng->minimum(-6400);
      pwheelbrng->maximum(6400);
      pwheelbrng->step(1);
      pwheelbrng->textcolor((Fl_Color)64);
      pwheelbrng->callback((Fl_Callback*)cb_pwheelbrng);
      pwheelbrng->align(Fl_Align(FL_ALIGN_TOP));
      o->value(part->ctl->pitchwheel.bendrange);
      o->lstep(100);
    } // Fl_Counter* pwheelbrng
    { WidgetPDial* o = filtq = new WidgetPDial(50, 55, 30, 30, "FltQ");
      filtq->tooltip("Filter Q depth");
      filtq->box(FL_OVAL_BOX);
      filtq->color(FL_BACKGROUND_COLOR);
      filtq->selection_color(FL_INACTIVE_COLOR);
      filtq->labeltype(FL_NORMAL_LABEL);
      filtq->labelfont(0);
      filtq->labelsize(10);
      filtq->labelcolor((Fl_Color)64);
      filtq->maximum(127);
      filtq->step(1);
      filtq->callback((Fl_Callback*)cb_filtq);
      filtq->align(Fl_Align(FL_ALIGN_BOTTOM));
      filtq->when(FL_WHEN_CHANGED);
      o->value(part->ctl->filterq.depth);
      o->selection_color(setKnob(o->value(),64));
    } // WidgetPDial* filtq
    { WidgetPDial* o = fltcut = new WidgetPDial(90, 55, 30, 30, "FltCut");
      fltcut->tooltip("Filter Cutoff depth");
      fltcut->box(FL_OVAL_BOX);
      fltcut->color(FL_BACKGROUND_COLOR);
      fltcut->selection_color(FL_INACTIVE_COLOR);
      fltcut->labeltype(FL_NORMAL_LABEL);
      fltcut->labelfont(0);
      fltcut->labelsize(10);
      fltcut->labelcolor((Fl_Color)64);
      fltcut->maximum(127);
      fltcut->step(1);
      fltcut->callback((Fl_Callback*)cb_fltcut);
      fltcut->align(Fl_Align(FL_ALIGN_BOTTOM));
      fltcut->when(FL_WHEN_CHANGED);
      o->value(part->ctl->filtercutoff.depth);
      o->selection_color(setKnob(o->value(),64));
    } // WidgetPDial* fltcut
    { ctlresonance = new Fl_Group(290, 15, 45, 85, "Resonance");
      ctlresonance->box(FL_GTK_THIN_UP_BOX);
      ctlresonance->labelfont(1);
      ctlresonance->labelsize(10);
      ctlresonance->labelcolor((Fl_Color)64);
      ctlresonance->align(Fl_Align(FL_ALIGN_TOP_LEFT));
      { WidgetPDial* o = cfdpth = new WidgetPDial(300, 20, 25, 25, "CFdpth");
        cfdpth->tooltip("Center Frequency controller Depth");
        cfdpth->box(FL_OVAL_BOX);
        cfdpth->color(FL_BACKGROUND_COLOR);
        cfdpth->selection_color(FL_INACTIVE_COLOR);
        cfdpth->labeltype(FL_NORMAL_LABEL);
        cfdpth->labelfont(0);
        cfdpth->labelsize(10);
        cfdpth->labelcolor((Fl_Color)64);
        cfdpth->maximum(127);
        cfdpth->step(1);
        cfdpth->callback((Fl_Callback*)cb_cfdpth);
        cfdpth->align(Fl_Align(FL_ALIGN_BOTTOM));
        cfdpth->when(FL_WHEN_CHANGED);
        o->value(part->ctl->resonancecenter.depth);
        o->selection_color(setKnob(o->value(),64));
      } // WidgetPDial* cfdpth
      { WidgetPDial* o = rbwdpth = new WidgetPDial(300, 60, 25, 25, "BWdpth");
        rbwdpth->tooltip("BandWidth controller depth");
        rbwdpth->box(FL_OVAL_BOX);
        rbwdpth->color(FL_BACKGROUND_COLOR);
        rbwdpth->selection_color(FL_INACTIVE_COLOR);
        rbwdpth->labeltype(FL_NORMAL_LABEL);
        rbwdpth->labelfont(0);
        rbwdpth->labelsize(10);
        rbwdpth->labelcolor((Fl_Color)64);
        rbwdpth->maximum(127);
        rbwdpth->step(1);
        rbwdpth->callback((Fl_Callback*)cb_rbwdpth);
        rbwdpth->align(Fl_Align(FL_ALIGN_BOTTOM));
        rbwdpth->when(FL_WHEN_CHANGED);
        o->value(part->ctl->resonancebandwidth.depth);
        o->selection_color(setKnob(o->value(),64));
      } // WidgetPDial* rbwdpth
      ctlresonance->end();
    } // Fl_Group* ctlresonance
    { threshlabel = new Fl_Box(400, 36, 48, 14, "Thresh");
      threshlabel->labelfont(3);
      threshlabel->labelsize(10);
      threshlabel->labelcolor((Fl_Color)226);
    } // Fl_Box* threshlabel
    { ctlportamento = new Fl_Group(340, 15, 160, 85, "Portamento");
      ctlportamento->box(FL_ENGRAVED_FRAME);
      ctlportamento->labelfont(1);
      ctlportamento->labelsize(10);
      ctlportamento->labelcolor((Fl_Color)64);
      { ctlx100 = new Fl_Box(400, 47, 55, 15, "x100 cnt.");
        ctlx100->labelfont(3);
        ctlx100->labelsize(10);
        ctlx100->labelcolor((Fl_Color)226);
        ctlx100->align(Fl_Align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE));
      } // Fl_Box* ctlx100
      { WidgetPDial* o = prtime = new WidgetPDial(345, 60, 25, 25, "time");
        prtime->tooltip("Portamento time");
        prtime->box(FL_OVAL_BOX);
        prtime->color(FL_BACKGROUND_COLOR);
        prtime->selection_color(FL_INACTIVE_COLOR);
        prtime->labeltype(FL_NORMAL_LABEL);
        prtime->labelfont(0);
        prtime->labelsize(10);
        prtime->labelcolor((Fl_Color)64);
        prtime->maximum(127);
        prtime->step(1);
        prtime->callback((Fl_Callback*)cb_prtime);
        prtime->align(Fl_Align(FL_ALIGN_BOTTOM));
        prtime->when(FL_WHEN_CHANGED);
        o->value(part->ctl->portamento.time);
        o->selection_color(setKnob(o->value(),64));
      } // WidgetPDial* prtime
      { WidgetPDial* o = timedu = new WidgetPDial(375, 60, 25, 25, "t.dn/up");
        timedu->tooltip("Portamento time stretch (up/down)");
        timedu->box(FL_OVAL_BOX);
        timedu->color(FL_BACKGROUND_COLOR);
        timedu->selection_color(FL_INACTIVE_COLOR);
        timedu->labeltype(FL_NORMAL_LABEL);
        timedu->labelfont(0);
        timedu->labelsize(10);
        timedu->labelcolor((Fl_Color)64);
        timedu->maximum(127);
        timedu->step(1);
        timedu->callback((Fl_Callback*)cb_timedu);
        timedu->align(Fl_Align(FL_ALIGN_BOTTOM));
        timedu->when(FL_WHEN_CHANGED);
        o->value(part->ctl->portamento.updowntimestretch);
        o->selection_color(setKnob(o->value(),64));
      } // WidgetPDial* timedu
      { Fl_Counter* o = thresh = new Fl_Counter(388, 20, 72, 16);
        thresh->tooltip("Minimum or max. difference of the notes in order to do the portamento (x 100 "
"cents)");
        thresh->type(1);
        thresh->labelcolor((Fl_Color)64);
        thresh->minimum(0);
        thresh->maximum(127);
        thresh->step(1);
        thresh->callback((Fl_Callback*)cb_thresh);
        o->value(part->ctl->portamento.pitchthresh);
      } // Fl_Counter* thresh
      { Fl_Check_Button2* o = thtype = new Fl_Check_Button2(425, 68, 15, 15, "th.type");
        thtype->tooltip("Threshold type (min/max)");
        thtype->box(FL_NO_BOX);
        thtype->down_box(FL_DOWN_BOX);
        thtype->color(FL_BACKGROUND_COLOR);
        thtype->selection_color((Fl_Color)64);
        thtype->labeltype(FL_NORMAL_LABEL);
        thtype->labelfont(0);
        thtype->labelsize(10);
        thtype->labelcolor((Fl_Color)64);
        thtype->callback((Fl_Callback*)cb_thtype);
        thtype->align(Fl_Align(FL_ALIGN_BOTTOM));
        thtype->when(FL_WHEN_RELEASE);
        o->value(part->ctl->portamento.pitchthreshtype);
      } // Fl_Check_Button2* thtype
      { WidgetPDial* o = propta = new WidgetPDial(463, 20, 25, 25, "Prp.Rate");
        propta->tooltip("Distance required to double change from nonpropotinal portamento time");
        propta->box(FL_OVAL_BOX);
        propta->color(FL_BACKGROUND_COLOR);
        propta->selection_color(FL_INACTIVE_COLOR);
        propta->labeltype(FL_NORMAL_LABEL);
        propta->labelfont(0);
        propta->labelsize(10);
        propta->labelcolor((Fl_Color)64);
        propta->maximum(127);
        propta->step(1);
        propta->callback((Fl_Callback*)cb_propta);
        propta->align(Fl_Align(FL_ALIGN_BOTTOM));
        propta->when(FL_WHEN_CHANGED);
        o->value(part->ctl->portamento.propRate);
        o->selection_color(setKnob(o->value(),80));
      } // WidgetPDial* propta
      { WidgetPDial* o = proptb = new WidgetPDial(463, 60, 25, 25, "Prp.Dpth");
        proptb->tooltip("The difference from nonproportinal portamento");
        proptb->box(FL_OVAL_BOX);
        proptb->color(FL_BACKGROUND_COLOR);
        proptb->selection_color(FL_INACTIVE_COLOR);
        proptb->labeltype(FL_NORMAL_LABEL);
        proptb->labelfont(0);
        proptb->labelsize(10);
        proptb->labelcolor((Fl_Color)64);
        proptb->maximum(127);
        proptb->step(1);
        proptb->callback((Fl_Callback*)cb_proptb);
        proptb->align(Fl_Align(FL_ALIGN_BOTTOM));
        proptb->when(FL_WHEN_CHANGED);
        o->value(part->ctl->portamento.propDepth);
        o->selection_color(setKnob(o->value(),90));
      } // WidgetPDial* proptb
      { Fl_Check_Button2* o = rcv = new Fl_Check_Button2(345, 20, 40, 18, "Rcv");
        rcv->tooltip("Receive Portamento Controllers");
        rcv->box(FL_THIN_UP_BOX);
        rcv->down_box(FL_DOWN_BOX);
        rcv->color(FL_BACKGROUND_COLOR);
        rcv->selection_color((Fl_Color)64);
        rcv->labeltype(FL_NORMAL_LABEL);
        rcv->labelfont(0);
        rcv->labelsize(10);
        rcv->labelcolor((Fl_Color)64);
        rcv->callback((Fl_Callback*)cb_rcv);
        rcv->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
        rcv->when(FL_WHEN_RELEASE);
        o->value(part->ctl->portamento.receive);
      } // Fl_Check_Button2* rcv
      { Fl_Check_Button2* o = proprt = new Fl_Check_Button2(345, 40, 50, 18, "Proprt.");
        proprt->tooltip("Enable Proportional Portamento (over fixed Portamento)");
        proprt->box(FL_THIN_UP_BOX);
        proprt->down_box(FL_DOWN_BOX);
        proprt->color(FL_BACKGROUND_COLOR);
        proprt->selection_color((Fl_Color)64);
        proprt->labeltype(FL_NORMAL_LABEL);
        proprt->labelfont(0);
        proprt->labelsize(9);
        proprt->labelcolor((Fl_Color)64);
        proprt->callback((Fl_Callback*)cb_proprt);
        proprt->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
        proprt->when(FL_WHEN_RELEASE);
        o->value(part->ctl->portamento.proportional);
        if (o->value()){propta->activate();proptb->activate();}
        else {propta->deactivate();proptb->deactivate();}
      } // Fl_Check_Button2* proprt
      ctlportamento->end();
    } // Fl_Group* ctlportamento
    { resetallctl = new Fl_Button(5, 105, 210, 20, "&Reset all controllers");
      resetallctl->box(FL_PLASTIC_UP_BOX);
      resetallctl->color((Fl_Color)228);
      resetallctl->labelcolor((Fl_Color)64);
      resetallctl->callback((Fl_Callback*)cb_resetallctl);
    } // Fl_Button* resetallctl
    { aftertouch = new Fl_Button(245, 105, 130, 20, "&Aftertouch");
      aftertouch->box(FL_GTK_THIN_UP_BOX);
      aftertouch->color((Fl_Color)198);
      aftertouch->labelcolor((Fl_Color)64);
      aftertouch->callback((Fl_Callback*)cb_aftertouch);
    } // Fl_Button* aftertouch
    { ctlclose = new Fl_Button(405, 105, 95, 20, "&Close");
      ctlclose->box(FL_THIN_UP_BOX);
      ctlclose->color((Fl_Color)196);
      ctlclose->labelcolor((Fl_Color)64);
      ctlclose->callback((Fl_Callback*)cb_ctlclose);
    } // Fl_Button* ctlclose
    ctlwindow->resizable(ctlwindow);
    o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Controllers"), npart, TOPLEVEL::windowTitle)).c_str());
    ctlDW = o->w(); ctlDH = o->h();
    o->size_range(ctlDW, ctlDH, 0, 0, 0, 0, 1);
    ctlwindow->end();
  } // ScaleTrackedWindow* ctlwindow
  { ScaleTrackedWindow* o = aftertouchcontrol = new ScaleTrackedWindow(485, 180, "Aftertouch");
    aftertouchcontrol->box(FL_FLAT_BOX);
    aftertouchcontrol->color(FL_BACKGROUND_COLOR);
    aftertouchcontrol->selection_color(FL_BACKGROUND_COLOR);
    aftertouchcontrol->labeltype(FL_NO_LABEL);
    aftertouchcontrol->labelfont(0);
    aftertouchcontrol->labelsize(14);
    aftertouchcontrol->labelcolor(FL_FOREGROUND_COLOR);
    aftertouchcontrol->callback((Fl_Callback*)cb_aftertouchcontrol, (void*)(this));
    aftertouchcontrol->align(Fl_Align(FL_ALIGN_TOP));
    aftertouchcontrol->when(FL_WHEN_RELEASE);
    { Fl_Box* o = new Fl_Box(9, 5, 228, 171);
      o->box(FL_ENGRAVED_FRAME);
    } // Fl_Box* o
    { Fl_Box* o = new Fl_Box(241, 5, 234, 143);
      o->box(FL_ENGRAVED_FRAME);
    } // Fl_Box* o
    { ATchan = new Fl_Box(95, 13, 35, 17, "Channel");
      ATchan->labelfont(1);
      ATchan->labelcolor((Fl_Color)64);
    } // Fl_Box* ATchan
    { channeloff = new Fl_Button(55, 40, 48, 20, "Off");
      channeloff->box(FL_PLASTIC_UP_BOX);
      channeloff->color((Fl_Color)228);
      channeloff->labelcolor((Fl_Color)64);
      channeloff->callback((Fl_Callback*)cb_channeloff);
    } // Fl_Button* channeloff
    { channelfiltercutoff = new Fl_Check_Button2(25, 65, 70, 15, "Filter Cutoff");
      channelfiltercutoff->tooltip("Between current MIDI setting and max.");
      channelfiltercutoff->box(FL_NO_BOX);
      channelfiltercutoff->down_box(FL_DOWN_BOX);
      channelfiltercutoff->color(FL_BACKGROUND_COLOR);
      channelfiltercutoff->selection_color((Fl_Color)64);
      channelfiltercutoff->labeltype(FL_NORMAL_LABEL);
      channelfiltercutoff->labelfont(0);
      channelfiltercutoff->labelsize(14);
      channelfiltercutoff->labelcolor((Fl_Color)64);
      channelfiltercutoff->callback((Fl_Callback*)cb_channelfiltercutoff);
      channelfiltercutoff->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      channelfiltercutoff->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* channelfiltercutoff
    { channelfilterCminus = new Fl_Check_Button2(150, 65, 70, 15, "Down");
      channelfilterCminus->tooltip("Between current MIDI setting and zero");
      channelfilterCminus->box(FL_NO_BOX);
      channelfilterCminus->down_box(FL_DOWN_BOX);
      channelfilterCminus->color(FL_BACKGROUND_COLOR);
      channelfilterCminus->selection_color((Fl_Color)64);
      channelfilterCminus->labeltype(FL_NORMAL_LABEL);
      channelfilterCminus->labelfont(0);
      channelfilterCminus->labelsize(14);
      channelfilterCminus->labelcolor((Fl_Color)64);
      channelfilterCminus->callback((Fl_Callback*)cb_channelfilterCminus);
      channelfilterCminus->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      channelfilterCminus->when(FL_WHEN_RELEASE);
      channelfilterCminus->deactivate();
    } // Fl_Check_Button2* channelfilterCminus
    { channelfilterQ = new Fl_Check_Button2(25, 85, 70, 15, "Filter Q");
      channelfilterQ->tooltip("Between current MIDI setting and max.");
      channelfilterQ->box(FL_NO_BOX);
      channelfilterQ->down_box(FL_DOWN_BOX);
      channelfilterQ->color(FL_BACKGROUND_COLOR);
      channelfilterQ->selection_color((Fl_Color)64);
      channelfilterQ->labeltype(FL_NORMAL_LABEL);
      channelfilterQ->labelfont(0);
      channelfilterQ->labelsize(14);
      channelfilterQ->labelcolor((Fl_Color)64);
      channelfilterQ->callback((Fl_Callback*)cb_channelfilterQ);
      channelfilterQ->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      channelfilterQ->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* channelfilterQ
    { channelfilterQminus = new Fl_Check_Button2(150, 85, 70, 15, "Down");
      channelfilterQminus->tooltip("Between current MIDI setting and zero");
      channelfilterQminus->box(FL_NO_BOX);
      channelfilterQminus->down_box(FL_DOWN_BOX);
      channelfilterQminus->color(FL_BACKGROUND_COLOR);
      channelfilterQminus->selection_color((Fl_Color)64);
      channelfilterQminus->labeltype(FL_NORMAL_LABEL);
      channelfilterQminus->labelfont(0);
      channelfilterQminus->labelsize(14);
      channelfilterQminus->labelcolor((Fl_Color)64);
      channelfilterQminus->callback((Fl_Callback*)cb_channelfilterQminus);
      channelfilterQminus->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      channelfilterQminus->when(FL_WHEN_RELEASE);
      channelfilterQminus->deactivate();
    } // Fl_Check_Button2* channelfilterQminus
    { channelpitchbend = new Fl_Check_Button2(25, 105, 70, 15, "Pitch Bend");
      channelpitchbend->tooltip("Between current pitch wheel position and max.");
      channelpitchbend->box(FL_NO_BOX);
      channelpitchbend->down_box(FL_DOWN_BOX);
      channelpitchbend->color(FL_BACKGROUND_COLOR);
      channelpitchbend->selection_color((Fl_Color)64);
      channelpitchbend->labeltype(FL_NORMAL_LABEL);
      channelpitchbend->labelfont(0);
      channelpitchbend->labelsize(14);
      channelpitchbend->labelcolor((Fl_Color)64);
      channelpitchbend->callback((Fl_Callback*)cb_channelpitchbend);
      channelpitchbend->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      channelpitchbend->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* channelpitchbend
    { channelpitchBminus = new Fl_Check_Button2(150, 105, 70, 15, "Down");
      channelpitchBminus->tooltip("Between current pitch wheel position and min.");
      channelpitchBminus->box(FL_NO_BOX);
      channelpitchBminus->down_box(FL_DOWN_BOX);
      channelpitchBminus->color(FL_BACKGROUND_COLOR);
      channelpitchBminus->selection_color((Fl_Color)64);
      channelpitchBminus->labeltype(FL_NORMAL_LABEL);
      channelpitchBminus->labelfont(0);
      channelpitchBminus->labelsize(14);
      channelpitchBminus->labelcolor((Fl_Color)64);
      channelpitchBminus->callback((Fl_Callback*)cb_channelpitchBminus);
      channelpitchBminus->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      channelpitchBminus->when(FL_WHEN_RELEASE);
      channelpitchBminus->deactivate();
    } // Fl_Check_Button2* channelpitchBminus
    { channelmodulation = new Fl_Check_Button2(25, 125, 70, 15, "Modulation");
      channelmodulation->tooltip("Between zero and Add/Pad frequency LFO depth");
      channelmodulation->box(FL_NO_BOX);
      channelmodulation->down_box(FL_DOWN_BOX);
      channelmodulation->color(FL_BACKGROUND_COLOR);
      channelmodulation->selection_color((Fl_Color)64);
      channelmodulation->labeltype(FL_NORMAL_LABEL);
      channelmodulation->labelfont(0);
      channelmodulation->labelsize(14);
      channelmodulation->labelcolor((Fl_Color)64);
      channelmodulation->callback((Fl_Callback*)cb_channelmodulation);
      channelmodulation->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      channelmodulation->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* channelmodulation
    { channelvolume = new Fl_Check_Button2(25, 145, 70, 15, "Volume");
      channelvolume->tooltip("Between current part volume and max.");
      channelvolume->box(FL_NO_BOX);
      channelvolume->down_box(FL_DOWN_BOX);
      channelvolume->color(FL_BACKGROUND_COLOR);
      channelvolume->selection_color((Fl_Color)64);
      channelvolume->labeltype(FL_NORMAL_LABEL);
      channelvolume->labelfont(0);
      channelvolume->labelsize(14);
      channelvolume->labelcolor((Fl_Color)64);
      channelvolume->callback((Fl_Callback*)cb_channelvolume);
      channelvolume->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      channelvolume->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* channelvolume
    { ATkey = new Fl_Box(328, 13, 35, 17, "Key");
      ATkey->labelfont(1);
      ATkey->labelcolor((Fl_Color)64);
    } // Fl_Box* ATkey
    { polyoff = new Fl_Button(300, 40, 48, 20, "Off");
      polyoff->box(FL_PLASTIC_UP_BOX);
      polyoff->color((Fl_Color)228);
      polyoff->labelcolor((Fl_Color)64);
      polyoff->callback((Fl_Callback*)cb_polyoff);
    } // Fl_Button* polyoff
    { polyfiltercutoff = new Fl_Check_Button2(270, 65, 70, 15, "Filter Cutoff");
      polyfiltercutoff->tooltip("Between current MIDI setting and max.");
      polyfiltercutoff->box(FL_NO_BOX);
      polyfiltercutoff->down_box(FL_DOWN_BOX);
      polyfiltercutoff->color(FL_BACKGROUND_COLOR);
      polyfiltercutoff->selection_color((Fl_Color)64);
      polyfiltercutoff->labeltype(FL_NORMAL_LABEL);
      polyfiltercutoff->labelfont(0);
      polyfiltercutoff->labelsize(14);
      polyfiltercutoff->labelcolor((Fl_Color)64);
      polyfiltercutoff->callback((Fl_Callback*)cb_polyfiltercutoff);
      polyfiltercutoff->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      polyfiltercutoff->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* polyfiltercutoff
    { polyfilterCminus = new Fl_Check_Button2(395, 65, 70, 15, "Down");
      polyfilterCminus->tooltip("Between current MIDI setting and zero");
      polyfilterCminus->box(FL_NO_BOX);
      polyfilterCminus->down_box(FL_DOWN_BOX);
      polyfilterCminus->color(FL_BACKGROUND_COLOR);
      polyfilterCminus->selection_color((Fl_Color)64);
      polyfilterCminus->labeltype(FL_NORMAL_LABEL);
      polyfilterCminus->labelfont(0);
      polyfilterCminus->labelsize(14);
      polyfilterCminus->labelcolor((Fl_Color)64);
      polyfilterCminus->callback((Fl_Callback*)cb_polyfilterCminus);
      polyfilterCminus->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      polyfilterCminus->when(FL_WHEN_RELEASE);
      polyfilterCminus->deactivate();
    } // Fl_Check_Button2* polyfilterCminus
    { polyfilterQ = new Fl_Check_Button2(270, 85, 70, 15, "Filter Q");
      polyfilterQ->tooltip("Between current MIDI setting and max.");
      polyfilterQ->box(FL_NO_BOX);
      polyfilterQ->down_box(FL_DOWN_BOX);
      polyfilterQ->color(FL_BACKGROUND_COLOR);
      polyfilterQ->selection_color((Fl_Color)64);
      polyfilterQ->labeltype(FL_NORMAL_LABEL);
      polyfilterQ->labelfont(0);
      polyfilterQ->labelsize(14);
      polyfilterQ->labelcolor((Fl_Color)64);
      polyfilterQ->callback((Fl_Callback*)cb_polyfilterQ);
      polyfilterQ->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      polyfilterQ->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* polyfilterQ
    { polyfilterQminus = new Fl_Check_Button2(395, 85, 70, 15, "Down");
      polyfilterQminus->tooltip("Between current MIDI setting and zero");
      polyfilterQminus->box(FL_NO_BOX);
      polyfilterQminus->down_box(FL_DOWN_BOX);
      polyfilterQminus->color(FL_BACKGROUND_COLOR);
      polyfilterQminus->selection_color((Fl_Color)64);
      polyfilterQminus->labeltype(FL_NORMAL_LABEL);
      polyfilterQminus->labelfont(0);
      polyfilterQminus->labelsize(14);
      polyfilterQminus->labelcolor((Fl_Color)64);
      polyfilterQminus->callback((Fl_Callback*)cb_polyfilterQminus);
      polyfilterQminus->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      polyfilterQminus->when(FL_WHEN_RELEASE);
      polyfilterQminus->deactivate();
    } // Fl_Check_Button2* polyfilterQminus
    { polypitchbend = new Fl_Check_Button2(270, 105, 70, 15, "Pitch Bend");
      polypitchbend->tooltip("Between current pitch wheel position and max.");
      polypitchbend->box(FL_NO_BOX);
      polypitchbend->down_box(FL_DOWN_BOX);
      polypitchbend->color(FL_BACKGROUND_COLOR);
      polypitchbend->selection_color((Fl_Color)64);
      polypitchbend->labeltype(FL_NORMAL_LABEL);
      polypitchbend->labelfont(0);
      polypitchbend->labelsize(14);
      polypitchbend->labelcolor((Fl_Color)64);
      polypitchbend->callback((Fl_Callback*)cb_polypitchbend);
      polypitchbend->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      polypitchbend->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* polypitchbend
    { polypitchBminus = new Fl_Check_Button2(395, 105, 70, 15, "Down");
      polypitchBminus->tooltip("Between current pitch wheel position and min.");
      polypitchBminus->box(FL_NO_BOX);
      polypitchBminus->down_box(FL_DOWN_BOX);
      polypitchBminus->color(FL_BACKGROUND_COLOR);
      polypitchBminus->selection_color((Fl_Color)64);
      polypitchBminus->labeltype(FL_NORMAL_LABEL);
      polypitchBminus->labelfont(0);
      polypitchBminus->labelsize(14);
      polypitchBminus->labelcolor((Fl_Color)64);
      polypitchBminus->callback((Fl_Callback*)cb_polypitchBminus);
      polypitchBminus->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      polypitchBminus->when(FL_WHEN_RELEASE);
      polypitchBminus->deactivate();
    } // Fl_Check_Button2* polypitchBminus
    { polymodulation = new Fl_Check_Button2(270, 125, 70, 15, "Modulation");
      polymodulation->tooltip("Between zero and Add/Pad frequency LFO depth");
      polymodulation->box(FL_NO_BOX);
      polymodulation->down_box(FL_DOWN_BOX);
      polymodulation->color(FL_BACKGROUND_COLOR);
      polymodulation->selection_color((Fl_Color)64);
      polymodulation->labeltype(FL_NORMAL_LABEL);
      polymodulation->labelfont(0);
      polymodulation->labelsize(14);
      polymodulation->labelcolor((Fl_Color)64);
      polymodulation->callback((Fl_Callback*)cb_polymodulation);
      polymodulation->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
      polymodulation->when(FL_WHEN_RELEASE);
    } // Fl_Check_Button2* polymodulation
    { atClose = new Fl_Button(420, 154, 50, 20, "&Close");
      atClose->box(FL_THIN_UP_BOX);
      atClose->color((Fl_Color)196);
      atClose->labelcolor((Fl_Color)64);
      atClose->callback((Fl_Callback*)cb_atClose);
    } // Fl_Button* atClose
    aftertouchcontrol->resizable(aftertouchcontrol);
    o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Aftertouch"), npart, TOPLEVEL::windowTitle)).c_str());
    atDW = o->w(); atDH = o->h();
    o->size_range(atDW, atDH, 0, 0, 0, 0, 1);
    aftertouchcontrol->end();
  } // ScaleTrackedWindow* aftertouchcontrol
  return aftertouchcontrol;
}

void PartUI::send_data(int action, int control, float value, int type, int npart, int kititem , int engine , int insert , int parameter , int miscmsg ) {
  //
          type |= TOPLEVEL::type::Write;
          collect_writeData(synth, value, action, type, control, npart, kititem, engine, insert, parameter, UNUSED, miscmsg);
}

float PartUI::fetchData(float value, int control, int part, int kititem , int engine , int insert , int parameter , int offset , int miscmsg , int request ) {
  //
          return collect_readData(synth, value, control, part, kititem, engine, insert, parameter, offset, miscmsg, request);
}

void PartUI::returns_update(CommandBlock *getData) {
  //
      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:
              switch (part->PkitfadeType)
              {
              case 1:
                  kitMode->value(3);
                  break;
              case 2:
                  kitMode->value(4);
                  break;
              default:
                  kitMode->value(valInt);
                  break;
              }
              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();
      ;
}

void PartUI::paste(CommandBlock *getData) {
  //
          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;
}

PartUI::PartUI(int x,int y, int w, int h, const char *label):Fl_Group(x,y,w,h,label) {
  //
      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;
}

void PartUI::rebuild(int npart_) {
  //
          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();
}

void PartUI::fillInstrumentType() {
  //

          int i = 0;
          string entry = type_list[i];
          while (entry != "@end")
          {
              instrumentType->add(entry.c_str());
              ++ i;
              entry = type_list[i];
          }
}

void PartUI::editrefresh() {
  //
          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));
}

void PartUI::effectsrefresh() {
  //
          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;
}

void PartUI::kitrefresh() {
  //
          instrumentkitlist->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Kit List"), npart, TOPLEVEL::windowTitle)).c_str());
          drumMode->value(part->Pdrummode);
              switch (part->PkitfadeType)
              {
              case 1:
                  kitMode->value(3);
                  break;
              case 2:
                  kitMode->value(4);
                  break;
              default:
                  kitMode->value(part->Pkitmode);
                  break;
              }
          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);
          }
}

void PartUI::controllersrefresh() {
  //
      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));
}

void PartUI::ctlmidirefresh() {
  //
          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));
}

void PartUI::ATrefresh() {
  //
      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();
}

void PartUI::fetchChannel() {
  //
              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);
}

void PartUI::fetchKey() {
  //
              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);
}

void PartUI::setATchannel(int type, int state) {
  //
          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);
}

void PartUI::setATkey(int type, int state) {
  //
          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);
}

void PartUI::init(Part *part_,int npart_,BankUI *bankui_) {
  //
      synth = & part_->getSynthEngine();
      bankui = bankui_;
      part = part_;
      npart = npart_;
      plgroup = &synth->getGuiMaster()->panelgroup;
      make_window();
      end();
}

void PartUI::checkEngines(string instrumentName ) {
  //
      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);
}

void PartUI::showparameters(int kititem, int engine) {
  //
      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();
}

void PartUI::setinstrumentlabel(string text ) {
  //
      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());
}

void PartUI::refreshEffUI() {
  //
          insefftype->value(inseffectui->effType());
          inseffnocounter->value(inseffectui->effNum() + 1);
          inseffectui->refresh(npart);
          bypasseff->value(inseffectui->getPartFxBypass());
          sendtochoice->value(inseffectui->getPartFxRouting());
}

void PartUI::seteditname() {
  //
      instrumenteditwindow->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Edit"), npart, TOPLEVEL::windowTitle)).c_str());
}

void PartUI::Showedit() {
  //
      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;
}

void PartUI::Showctl() {
  //
      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;
}

void PartUI::ShowAT() {
  //
      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();
}

void PartUI::Showctlmidi() {
  //
      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;
}

void PartUI::Showefx() {
  //
      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;
}

void PartUI::Showkit() {
  //
      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;
}

void PartUI::wincheck() {
  //
      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();
}

void PartUI::theme() {
  //
          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();
          ;
}

void PartUI::editRtext() {
  //
      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();
}

void PartUI::ctlRtext() {
  //
      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();
}

void PartUI::ATRtext() {
  //
      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();
}

void PartUI::ctlmidiRtext() {
  //
      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();
}

void PartUI::fxRtext() {
  //
      /*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();
}

void PartUI::kitRtext(bool force ) {
  //
      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();
}

PartUI::~PartUI() {
  //
      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;
}
