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

comment {ADNoteUI.cc} {in_source not_in_header
}

comment {Original ZynAddSubFX author Nasca Octavian Paul
Copyright (C) 2002-2005 Nasca Octavian Paul
Copyright 2009-2011, Alan Calvert
Copyright 2014-2024, Will Godfrey, Kristian Amlie

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

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

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

This file is derivative of ZynAddSubFX original code.

} {selected in_source in_header
}

decl {\#include <FL/Fl_Box.H>
    \#include <FL/Fl_Group.H>
    \#include "Params/ADnoteParameters.h"
    \#include "Misc/SynthEngine.h"
    \#include "DSP/FFTwrapper.h"
    \#include "UI/MiscGui.h"
    \#include "UI/WidgetPDial.h"
    \#include "UI/WidgetMWSlider.h"
    \#include "UI/WidgetCheckButton.h"
    \#include "UI/WidgetSpinner.h"
    \#include "FilterUI.h"
    \#include "PresetsUI.h"} {public global
}

decl {\#include <string>
    \#include "ResonanceUI.h"
    \#include "EnvelopeUI.h"
    \#include "LFOUI.h"
    \#include "OscilGenUI.h"} {public global
}

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

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

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

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

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

class ADvoiceUI {: {public Fl_Group}
} {
  Function {make_window()} {} {
    Fl_Window ADnoteVoiceParameters {
      label Voice
      xywh {486 185 805 615} type Double box NO_BOX hide resizable
      class Fl_Group
    } {
      Fl_Box {} {
        xywh {10 69 275 66} box PLASTIC_UP_BOX color 223 labelcolor 64
      }
      Fl_Check_Button voiceonbutton {
        label On
        callback {//
            send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::enableVoice, o->value(), TOPLEVEL::type::Integer);
            ;}
        xywh {12 41 50 20} down_box DOWN_BOX color 7 selection_color 64 labelfont 3 labelcolor 226
        code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableVoice, npart, kititem, PART::engine::addVoice1 + nvoice));}
        class Fl_Check_Button2
      }
      Fl_Group voiceparametersgroup {
        xywh {0 0 805 615} box THIN_UP_FRAME color 48
        code0 {if (voiceonbutton->value() == 0) o->deactivate();}
      } {
        Fl_Group voicemodegroup {
          xywh {0 0 805 615}
        } {
          Fl_Group voiceFMparametersgroup {
            label MODULATOR
            xywh {575 5 230 565} box THIN_UP_FRAME color 48 labelfont 1 labelsize 12 labelcolor 64 align 17
          } {
            Fl_Group modfrequency {
              label {Mod FREQUENCY}
              xywh {580 204 220 161} box THIN_UP_FRAME labelfont 1 labelsize 11 labelcolor 64 align 17
            } {
              Fl_Group voiceFMfreqenvgroup {
                label {Yoshimi : AddSynth Modulator - Frequency Envelope}
                xywh {585 290 210 70} box FLAT_BOX color 51 align 144
                code0 {o->init(pars->VoicePar[nvoice].FMFreqEnvelope, npart, kititem, nvoice + PART::engine::addMod1, 1);}
                code1 {if(collect_readData(synth,0,ADDVOICE::control::enableModulatorFrequencyEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice) == 0) o->deactivate();}
                class EnvelopeUI
              } {}
              Fl_Check_Button ModFreqEn {
                label On
                callback {//
                    if (o->value() == 0)
                        voiceFMfreqenvgroup->deactivate();
                    else
                        voiceFMfreqenvgroup->activate();
                    o->redraw();
                    send_data(0, ADDVOICE::control::enableModulatorFrequencyEnvelope, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip {Enable Frequency Envelope} xywh {590 295 38 14} down_box DOWN_BOX color 7 selection_color 64 labelfont 3 labelsize 10 labelcolor 226
                code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableModulatorFrequencyEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice));}
                class Fl_Check_Button2
              }
              Fl_Counter ModCoarseDetune {
                label {Coarse Det.}
                callback {//
                    send_data(0, ADDVOICE::control::modulatorCoarseDetune, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip {Coarse Detune} xywh {723 270 73 13} selection_color 64 labelsize 10 labelcolor 64 align 1 minimum -64 maximum 63 step 1 textfont 1 textsize 11 textcolor 64
                code0 {int k = int(collect_readData(synth,0,ADDVOICE::control::modulatorCoarseDetune, npart, kititem, PART::engine::addVoice1 + nvoice)) % 1024;}
                code1 {if (k >= 512) k-= 1024;}
                code2 {o->value(k);}
                code3 {o->lstep(10);}
              }
              Fl_Text_Display modoctavetext {
                label Octave
                xywh {669 270 50 11} box NO_BOX labelfont 3 labelsize 10 labelcolor 226
              }
              Fl_Counter ModOctave {
                callback {//
                    send_data(0, ADDVOICE::control::modulatorOctave, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip Octave xywh {665 270 54 13} type Simple selection_color 49 labelfont 3 labelsize 10 align 1 minimum -8 maximum 7 step 1 textfont 1 textsize 11 textcolor 64
                code0 {int k = int(collect_readData(synth,0,ADDVOICE::control::modulatorOctave, npart, kititem, PART::engine::addVoice1 + nvoice));}
                code1 {if (k >= 8) k -= 16;}
                code2 {o->value(k);}
              }
              Fl_Slider ModDetune {
                callback {//
                    o->selection_color(setSlider(o->value(),0));
                    send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::modulatorDetuneFrequency, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip {Fine Detune (cents)} xywh {623 239 168 13} type {Horz Knob} box THIN_DOWN_BOX labelcolor 64 minimum -8192 maximum 8191 step 1
                code0 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorDetuneFrequency, npart, kititem, PART::engine::addVoice1 + nvoice));}
                code1 {o->selection_color(setSlider(o->value(),0));}
                class mwheel_slider_rev
              }
              Fl_Choice ModDetuneType {
                label {Detune Type}
                callback {//
                    send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::modulatorDetuneType, o->value(), TOPLEVEL::type::Integer);
                    ;}
                xywh {585 270 75 13} down_box BORDER_BOX selection_color 49 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 10 textcolor 64
                code0 {o->add("Default");o->add("L35cents");o->add("L10cents");o->add("E100cents");o->add("E1200cents");}
                code1 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorDetuneType, npart, kititem, PART::engine::addVoice1 + nvoice));}
              } {}
              Fl_Value_Output fmdetunevalueoutput {
                label Detune
                callback {//
                    o->value(getDetune((ModDetuneType->value() < 1) ? (collect_readData(synth, 0, ADDSYNTH::detuneType, npart, kititem, PART::engine::addSynth)) : (ModDetuneType->value()), 0, ModDetune->value()+8192));
    ;}
                xywh {587 239 36 13} box THIN_DOWN_BOX labelsize 10 labelcolor 64 align 5 minimum -5000 maximum 5000 textfont 1 textsize 10 textcolor 64
                code0 {o->step(0.01, 1);}
                code1 {o->value(getDetune((ModDetuneType->value() < 1) ? (collect_readData(synth, 0, ADDSYNTH::detuneType, npart, kititem, PART::engine::addSynth)) : (ModDetuneType->value()), 0, ModDetune->value()+8192));}
              }
              Fl_Check_Button Mod440 {
                label 440Hz
                callback {//
                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::modulatorFrequencyAs440Hz, o->value(), TOPLEVEL::type::Integer);
                ;}
                tooltip {Set the modulator base frequency to 440Hz} xywh {726 220 55 15} down_box DOWN_BOX selection_color 64 labelfont 1 labelsize 11 labelcolor 64
                code0 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorFrequencyAs440Hz, npart, kititem, PART::engine::addVoice1 + nvoice));}
                class Fl_Check_Button2
              }
              Fl_Check_Button detuneFromBaseOsc {
                label {Follow voice}
                callback {//
                    send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::modulatorDetuneFromBaseOsc, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip {Apply all detuning in the voice oscillator to the modulator as well.} xywh {630 220 95 15} down_box DOWN_BOX selection_color 64 labelsize 11 labelcolor 64
                code0 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorDetuneFromBaseOsc, npart, kititem, PART::engine::addVoice1 + nvoice));}
                code1 {if (Mod440->value() != 0) o->deactivate();}
                class Fl_Check_Button2
              }
            }
            Fl_Group Modampgrp {
              label {Mod AMPLITUDE}
              xywh {580 55 220 149} box THIN_UP_FRAME labelfont 1 labelsize 11 labelcolor 64 align 17
            } {
              Fl_Value_Slider ModVolume {
                label Vol
                callback {//
                    o->selection_color(setSlider(o->value(),90));
                    send_data(0, ADDVOICE::control::modulatorAmplitude, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip Volume xywh {585 70 160 15} type {Horz Knob} box THIN_DOWN_BOX labelsize 11 align 8 maximum 127 step 1
                code0 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorAmplitude, npart, kititem, PART::engine::addVoice1 + nvoice));}
                code1 {o->selection_color(setSlider(o->value(),90));}
                class mwheel_val_slider_rev
              }
              Fl_Value_Slider ModVsense {
                label {V.Sns}
                callback {//
                    o->selection_color(setSlider(o->value(),64));
                    send_data(0, ADDVOICE::control::modulatorVelocitySense, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip {Velocity Sensing Function - rightmost/max to disable)} xywh {585 90 160 15} type {Horz Knob} box THIN_DOWN_BOX labelsize 11 align 8 maximum 127 step 1
                code0 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorVelocitySense, npart, kititem, PART::engine::addVoice1 + nvoice));}
                code1 {o->selection_color(setSlider(o->value(),64));}
                class mwheel_val_slider_rev
              }
              Fl_Group voiceFMampenvgroup {
                label {Yoshimi : AddSynth Modulator - Amplitude Envelope}
                xywh {585 129 210 70} box FLAT_BOX color 51 align 144
                code0 {o->init(pars->VoicePar[nvoice].FMAmpEnvelope, npart, kititem, nvoice + PART::engine::addMod1, 0);}
                code1 {if (collect_readData(synth,0,ADDVOICE::control::enableModulatorAmplitudeEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice) == 0)  o->deactivate();}
                class EnvelopeUI
              } {}
              Fl_Check_Button ModAmpEn {
                label On
                callback {//
                    if (o->value() == 0)
                        voiceFMampenvgroup->deactivate();
                    else
                        voiceFMampenvgroup->activate();
                    o->redraw();
                    send_data(0, ADDVOICE::control::enableModulatorAmplitudeEnvelope, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip {Enable Amplitude Envelope} xywh {590 134 38 14} down_box DOWN_BOX color 7 selection_color 64 labelfont 3 labelsize 10 labelcolor 226
                code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableModulatorAmplitudeEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice));}
                class Fl_Check_Button2
              }
              Fl_Value_Slider ModFdamp {
                label {F.Damp}
                callback {//
                    o->selection_color(setSlider(o->value(),0));
                    send_data(0, ADDVOICE::control::modulatorHFdamping, o->value(), TOPLEVEL::type::Integer);
                    ;}
                tooltip {Modulator Damp at Higher frequency} xywh {585 110 160 15} type {Horz Knob} box THIN_DOWN_BOX labelsize 11 align 8 minimum -64 maximum 63 step 1
                code0 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorHFdamping, npart, kititem, PART::engine::addVoice1 + nvoice));}
                code1 {o->selection_color(setSlider(o->value(),0));}
                class mwheel_val_slider_rev
              }
            }
            Fl_Group modOscDisplay {
              xywh {580 365 220 200} labelcolor 64
            } {
              Fl_Group modoscil {
                label {                       }
                xywh {580 365 220 200} box THIN_UP_FRAME labelfont 1 labelsize 11 labelcolor 64 align 17
              } {
                Fl_Text_Display ModLocalOsc {
                  label {Local Oscillator}
                  xywh {598 385 95 2} box NO_BOX labelfont 1 labelsize 12 labelcolor 64
                }
                Fl_Choice ExtModOsc {
                  label Use
                  callback {//
                    send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::modulatorOscillatorSource, o->value() - 1, TOPLEVEL::type::Integer);
                    ;}
                  tooltip {Use an earlier oscillator for this modulator. Only the base oscillator is used, not other voice parameters.} xywh {607 402 75 14} down_box BORDER_BOX selection_color 49 labelsize 10 labelcolor 64 align 1 textfont 1 textsize 10 textcolor 64
                  code0 {o->add("Internal");}
                  code1 {char tmp[50]; for (int i = 0; i < nvoice; ++i) {sprintf(tmp, "Mod.%2d", i + 1); o->add(tmp);};}
                  code3 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorOscillatorSource, npart, kititem, PART::engine::addVoice1 + nvoice) + 1);}
                } {}
                Fl_Button changeFMoscilbutton {
                  label Waveform
                  callback {//
                    if (oscedit)
                        delete oscedit;
                    lastWaveW = 0;
                    int nv = nvoice;
                    int extMod = ExtModOsc->value() - 1;
                    if (extMod >= 0)
                        nv = extMod;
                    oscedit = new OscilEditor(pars->VoicePar[nv].POscilFM, modOscDisplay, NULL, NULL, synth, npart, kititem, nvoice + PART::engine::addMod1);
                    if ((Fl::event_button() == 3))
                        synth->getGuiMaster()->partui->adnoteui->ADnoteVoice->hide();
                    ;}
                  xywh {712 370 72 18} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 10 labelcolor 64
                  code0 {if (ExtModOsc->value() > 0) o->labelcolor(alt_warn_tex);}
                }
                Fl_Slider ModPhase {
                  label Phase
                  callback {//
                    o->selection_color(setSlider(o->value(),0));
                    send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::modulatorOscillatorPhase, o->value(), TOPLEVEL::type::Integer);
                    ;}
                  tooltip {Phase offset} xywh {708 402 80 14} type {Horz Knob} box THIN_DOWN_BOX labelsize 10 labelcolor 64 align 1 minimum -64 maximum 63 step 1
                  code0 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorOscillatorPhase, npart, kititem, PART::engine::addVoice1 + nvoice));}
                  code1 {o->setValueType(VC_PhaseOffset); o->useCustomTip(true);}
                  code2 {o->selection_color(setSlider(o->value(),0));}
                  class mwheel_slider_rev
                }
                Fl_Group fmoscil {
                  xywh {580 425 220 140} box THIN_DOWN_BOX color 57 labelcolor 179
                  code0 {oscFM = new Oscilloscope(o->x(),o->y(),o->w(),o->h(), 125,"");}
                  code1 {update_fmoscil();}
                } {}
              }
              Fl_Box modvoicelabel {
                label Voice
                callback {//
                    update_modvoicelabel();
                    ;}
                xywh {600 470 190 65} labelfont 1 labelsize 40 labelcolor 7
                code0 {update_modvoicelabel();}
              }
            }
            Fl_Choice ExtMod {
              label Source
              callback {//
                  send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::externalModulator, o->value() - 1, TOPLEVEL::type::Integer);
                  ;}
              tooltip {Use an earlier voice as modulator. All parameters from the imported voice remain in effect, except for volume, panning, base frequency and pitch bend scaling factor. The voice is also converted to mono. Parameters in the current voice will then tweak the modulator further.} xywh {692 32 104 17} down_box BORDER_BOX selection_color 49 labelsize 11 labelcolor 64 align 9 textfont 1 textcolor 64
              code0 {o->add("Local");}
              code1 {char tmp[50]; for (int i = 0; i < nvoice; ++i) {sprintf(tmp, "Voice %2d", i + 1); o->add(tmp);};}
              code2 {o->value(collect_readData(synth,0,ADDVOICE::control::externalModulator, npart, kititem, PART::engine::addVoice1 + nvoice) + 1);}
              code3 {if (lrint(o->value())) {modoscil->deactivate();}}
            } {}
          }
          Fl_Text_Display modtypetext {
            label {Type:}
            xywh {572 32 50 8} box NO_BOX selection_color 49 labelfont 3 labelsize 11 labelcolor 226
          }
          Fl_Choice ModType {
            callback {//
                if (o->value() == 0)
                    voiceFMparametersgroup->deactivate();
                else
                    voiceFMparametersgroup->activate();
                o->redraw();
                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::modulatorType, o->value(), TOPLEVEL::type::Integer);
                ;}
            xywh {580 32 90 17} box NO_BOX down_box BORDER_BOX selection_color 49 labelfont 3 labelsize 11 align 5 textfont 1 textsize 11 textcolor 64
            code0 {o->add("Off");o->add("Morph");o->add("Ring");o->add("PM");o->add("FM");o->add("PWM");}
            code1 {o->value(collect_readData(synth,0,ADDVOICE::control::modulatorType, npart, kititem, PART::engine::addVoice1 + nvoice));}
            code2 {if (o->value() == 0) voiceFMparametersgroup->deactivate();}
          } {}
          Fl_Group freqencygrp {
            label FREQUENCY
            xywh {5 280 570 120} box THIN_UP_FRAME labelfont 1 labelsize 12 labelcolor 64 align 17
          } {
            Fl_Group voicefreqenvgroup {
              label {Yoshimi : AddSynth Voice - Frequency Envelope}
              xywh {9 325 205 70} box FLAT_BOX color 51 align 144
              code0 {o->init(pars->VoicePar[nvoice].FreqEnvelope, npart, kititem, nvoice + PART::engine::addVoice1, 1);}
              code1 {if (collect_readData(synth,0,ADDVOICE::control::enableFrequencyEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice)==0) o->deactivate();}
              class EnvelopeUI
            } {}
            Fl_Check_Button FreqEn {
              label On
              callback {//
                  if (o->value() == 0)
                      voicefreqenvgroup->deactivate();
                  else
                      voicefreqenvgroup->activate();
                  o->redraw();
                  send_data(0, ADDVOICE::control::enableFrequencyEnvelope, o->value(), TOPLEVEL::type::Integer);
                  ;}
              tooltip {Enable Frequency Envelope} xywh {14 330 38 14} down_box DOWN_BOX selection_color 64 labelfont 3 labelsize 10 labelcolor 226
              code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableFrequencyEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice));}
              class Fl_Check_Button2
            }
            Fl_Group voicefreqlfogroup {
              label {Frequency LFO     }
              xywh {215 325 275 70} box FLAT_BOX color 47 align 144
              code0 {o->init(synth, npart, kititem, PART::engine::addVoice1 + nvoice, TOPLEVEL::insertType::frequency);}
              code1 {if (collect_readData(synth,0,ADDVOICE::control::enableFrequencyLFO, npart, kititem, PART::engine::addVoice1 + nvoice)==0) o->deactivate();}
              class LFOUI
            } {}
            Fl_Check_Button FreqLfoEn {
              label On
              callback {//
            bool enab = _SYS_::F2B(o->value());
            if (enab)
            {
                voicefreqlfogroup->activate();
                synth->getGuiMaster()->partui->adnoteui->voicelistitem[nvoice]->voicelistvibratto->activate();
            }
            else
            {
                voicefreqlfogroup->deactivate();
                synth->getGuiMaster()->partui->adnoteui->voicelistitem[nvoice]->voicelistvibratto->deactivate();
            }
            o->redraw();

            send_data(0, ADDVOICE::control::enableFrequencyLFO, o->value(), TOPLEVEL::type::Integer);
            ;}
              tooltip {Enable Frequency LFO} xywh {220 330 38 14} down_box DOWN_BOX selection_color 64 labelfont 3 labelsize 10 labelcolor 226
              code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableFrequencyLFO, npart, kititem, PART::engine::addVoice1 + nvoice));}
              class Fl_Check_Button2
            }
            Fl_Text_Display voiceoctavetext {
              label Octave
              xywh {507 306 50 11} box NO_BOX labelfont 3 labelsize 10 labelcolor 226
            }
            Fl_Counter Octave {
              callback {//
                  send_data(0, ADDVOICE::control::octave, o->value(), TOPLEVEL::type::Integer);
                  ;}
              tooltip Octave xywh {504 306 58 13} type Simple selection_color 49 labelfont 3 labelsize 10 align 1 minimum -8 maximum 7 step 1 value 4 textfont 1 textsize 11 textcolor 64
              code0 {int k = int(collect_readData(synth,0,ADDVOICE::control::octave, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {if (k >= 8) k -= 16;}
              code2 {o->value(k);}
            }
            Fl_Counter CoarseDetune {
              label {Coarse Det.}
              callback {//
                  send_data(0, ADDVOICE::control::coarseDetune, o->value(), TOPLEVEL::type::Integer);
                  ;}
              tooltip {Coarse Detune} xywh {493 375 78 13} selection_color 64 labelsize 10 labelcolor 64 align 1 minimum -64 maximum 63 step 1 textfont 1 textsize 11 textcolor 64
              code0 {int k = collect_readData(synth,0,ADDVOICE::control::coarseDetune, npart, kititem, PART::engine::addVoice1 + nvoice);}
              code1 {o->value(k);}
              code2 {o->lstep(10);}
            }
            Fl_Choice FreqDetunetype {
              label {Detune Type}
              callback {//
                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::detuneType, o->value(), TOPLEVEL::type::Integer);
                ;}
              xywh {495 340 75 13} down_box BORDER_BOX selection_color 64 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 10 textcolor 64
              code0 {o->add("Default");o->add("L35cents");o->add("L10cents");o->add("E100cents");o->add("E1200cents");}
              code1 {o->value(collect_readData(synth, 0, ADDVOICE::control::detuneType, npart, kititem, PART::engine::addVoice1 + nvoice));}
            } {}
            Fl_Slider Detune {
              callback {//
                int detune = lrint(o->value());
                o->selection_color(setSlider(o->value(),0));
                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::detuneFrequency, detune, TOPLEVEL::type::Integer);
                ;}
              tooltip {Fine Detune (cents)} xywh {62 306 428 14} type {Horz Knob} box THIN_DOWN_BOX minimum -8192 maximum 8191 step 1
              code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::detuneFrequency, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {o->selection_color(setSlider(o->value(),0));}
              class mwheel_slider_rev
            }
            Fl_Value_Output detunevalueoutput {
              label Detune
              callback {//
                o->value(getDetune((FreqDetunetype->value()<1)?(collect_readData(synth, 0, ADDSYNTH::detuneType, npart, kititem, PART::engine::addSynth)) : (FreqDetunetype->value()),0,Detune->value()+8192)*collect_readData(synth, 0, ADDSYNTH::control::bandwidthMultiplier, npart, kititem, PART::engine::addSynth));
                ;}
              xywh {9 306 53 14} box THIN_DOWN_BOX labelsize 10 labelcolor 64 align 5 minimum -5000 maximum 5000 step 0.01 textfont 1 textsize 10 textcolor 64
              code0 {o->step(0.01, 1);}
              code1 {o->value(getDetune((FreqDetunetype->value()<1)?(collect_readData(synth, 0, ADDSYNTH::detuneType, npart, kititem, PART::engine::addSynth)) : (FreqDetunetype->value()),0,Detune->value()+8192)*collect_readData(synth, 0, ADDSYNTH::control::bandwidthMultiplier, npart, kititem, PART::engine::addSynth));}
            }
            Fl_Dial bend {
              label Bend
              callback {//
                o->selection_color(setKnob(o->value(),88));
                send_data(0, ADDVOICE::control::pitchBendAdjustment, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip {Pitch bend scaling for this voice} xywh {70 284 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 8 maximum 127 step 1
              code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::pitchBendAdjustment, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {o->setValueType(VC_PitchBend);}
              code2 {o->selection_color(setKnob(o->value(),88));}
              class WidgetPDial
            }
            Fl_Check_Button Freq440 {
              label 440Hz
              callback {//
                  int x = lrint(o->value());
                  if (x == 0 && Mod440->value() == 0)
                      fixedfreqetdial->deactivate();
                  else
                      fixedfreqetdial->activate();
                  send_data(0, ADDVOICE::control::baseFrequencyAs440Hz, o->value(), TOPLEVEL::type::Integer);
                  ;}
              tooltip {Set the voice base frequency to 440Hz} xywh {400 286 55 15} down_box DOWN_BOX selection_color 64 labelfont 1 labelsize 11 labelcolor 64
              code0 {o->value(collect_readData(synth,0,ADDVOICE::control::baseFrequencyAs440Hz, npart, kititem, PART::engine::addVoice1 + nvoice));}
              class Fl_Check_Button2
            }
            Fl_Dial fixedfreqetdial {
              label {Eq.T.}
              callback {//
                o->selection_color(setKnob(o->value(),0));
                send_data(0, ADDVOICE::control::equalTemperVariation, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip {How the frequency varies according to the keyboard (leftmost for fixed frequency)} xywh {460 284 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 8 maximum 127 step 1
              code0 {o->value(collect_readData(synth,0,ADDVOICE::control::equalTemperVariation, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {if (Freq440->value() ==0) o->deactivate();}
              code2 {o->setValueType(VC_FixedFreqET);}
              code3 {o->selection_color(setKnob(o->value(),0));}
              class WidgetPDial
            }
            Fl_Dial offset {
              label Offset
              callback {//
                o->selection_color(setKnob(o->value(),64));
                send_data(0, ADDVOICE::control::pitchBendOffset, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip {Offset of the frequency in Hz.} xywh {130 284 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 8 maximum 127 step 1
              code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::pitchBendOffset, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {o->setValueType(VC_FreqOffsetHz);}
              code2 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
          }
          Fl_Group oscDisplay {
            xywh {5 462 570 145}
          } {
            Fl_Group oscGroup {
              xywh {5 462 570 145} labelfont 1 labelsize 13 align 17
              code0 {if (collect_readData(synth, 0, ADDVOICE::control::externalOscillator, npart, kititem, PART::engine::addVoice1 + nvoice) >= 0) o->deactivate();}
            } {
              Fl_Group oscParamBox {
                label {Local
Oscillator}
                xywh {5 478 80 128} box THIN_UP_FRAME labelfont 1 labelsize 12 labelcolor 64 align 17
              } {
                Fl_Choice UseOsc {
                  label Use
                  callback {//
                    send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::voiceOscillatorSource, o->value() - 1, TOPLEVEL::type::Integer);
                ;}
                  tooltip {Use an earlier oscillator for this voice. Only the base oscillator is used, not other voice parameters.} xywh {9 526 72 18} down_box BORDER_BOX selection_color 49 labelsize 10 labelcolor 64 align 1 textfont 1 textsize 10 textcolor 64
                  code0 {o->add("Internal");}
                  code1 {char tmp[50]; for (int i = 0; i < nvoice; ++i) {sprintf(tmp, "Osc. %2d", i + 1); o->add(tmp);};}
                  code3 {o->value(collect_readData(synth, 0, ADDVOICE::control::voiceOscillatorSource, npart, kititem, PART::engine::addVoice1 + nvoice) + 1);}
                } {}
                Fl_Button changevoiceoscilbutton {
                  label Waveform
                  callback {//
                    if (oscedit)
                        delete oscedit;
                    lastWaveW = 0;
                    int nv = nvoice;
                    if (UseOsc->value() > 0)
                        nv = UseOsc->value() - 1;
                    oscedit = new OscilEditor(pars->VoicePar[nv].POscil, oscDisplay, NULL, NULL, synth, npart, kititem, nvoice + PART::engine::addVoice1);
                    if ((Fl::event_button() == 3))
                        synth->getGuiMaster()->partui->adnoteui->ADnoteVoice->hide();
                    ;}
                  xywh {9 548 72 22} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 11 labelcolor 64
                  code0 {if (UseOsc->value() > 0) o->labelcolor(alt_warn_tex);}
                }
                Fl_Slider VoiceOscPhase {
                  label Phase
                  callback {//
                o->selection_color(setSlider(o->value(),0));
                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::voiceOscillatorPhase, o->value(), TOPLEVEL::type::Integer);
                ;}
                  tooltip {Phase offset} xywh {9 586 72 16} type {Horz Knob} box THIN_DOWN_BOX labelsize 10 labelcolor 64 align 1 minimum -64 maximum 63 step 1
                  code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::voiceOscillatorPhase, npart, kititem, PART::engine::addVoice1 + nvoice));}
                  code1 {o->setValueType(VC_PhaseOffset); o->useCustomTip(true);}
                  code2 {o->selection_color(setSlider(o->value(),0));}
                  class mwheel_slider_rev
                }
              }
              Fl_Group voiceoscil {
                xywh {88 462 485 145} box THIN_DOWN_BOX color 57 labelcolor 49
                code0 {osc = new Oscilloscope(o->x(),o->y(),o->w(),o->h(), 130, "");}
                code1 {update_voiceoscil();}
              } {}
            }
            Fl_Box osclabel {
              label Osc
              callback {//
        update_osclabels();
        ;}
              xywh {135 502 400 65} labelfont 1 labelsize 50 labelcolor 7
            }
          }
          Fl_Box {} {
            xywh {205 35 85 33} box THIN_UP_FRAME
          }
          Fl_Check_Button ResonanceEn {
            label Resonance
            callback {//
                bool enab = _SYS_::F2B(o->value());

                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::enableResonance, enab, TOPLEVEL::type::Integer);
                ;}
            tooltip {Resonance On/Off} xywh {238 49 17 19} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 1
            code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::enableResonance, npart, kititem, PART::engine::addVoice1 + nvoice));}
            class Fl_Check_Button2
          }
          Fl_Group unisongroup {
            xywh {88 402 484 56} box PLASTIC_UP_BOX color 223 deactivate
            code0 {int tmp = collect_readData(synth, 0, ADDVOICE::control::unisonSize, npart, kititem, PART::engine::addVoice1 + nvoice); if (tmp > 1) o->activate();}
          } {
            Fl_Spinner unisonsize {
              label Size
              callback {//
                send_data(0, ADDVOICE::control::unisonSize, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip {Number of unison sub-voices} xywh {98 434 40 16} box THIN_UP_BOX color 29 labelsize 10 align 1 minimum 2 maximum 50 value 2 textsize 11 textcolor 64
              code0 {int tmp = collect_readData(synth, 0, ADDVOICE::control::unisonSize, npart, kititem, PART::engine::addVoice1 + nvoice);}
              code1 {if (tmp < 2) tmp = 2;}
              code2 {o->value(tmp);}
              class WidgetSpinner
            }
            Fl_Dial UnisonStereo {
              label Stereo
              callback {//
                o->selection_color(setKnob(o->value(),64));
                send_data(0, ADDVOICE::control::unisonStereoSpread, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip {Stereo Spread} xywh {356 422 28 28} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::unisonStereoSpread, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Dial UnisonVib {
              label {Vib.}
              callback {//
                o->selection_color(setKnob(o->value(),64));
                send_data(0, ADDVOICE::control::unisonVibratoDepth, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip Vibratto xywh {396 422 28 28} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::unisonVibratoDepth, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Choice UnisonInvert {
              label Invert
              callback {//
                send_data(0, ADDVOICE::control::unisonPhaseInvert, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip {Phase Invert} xywh {484 426 78 18} down_box BORDER_BOX selection_color 64 labelsize 10 labelcolor 64 align 1 textfont 1 textsize 11 textcolor 64
              code0 {o->add("None");o->add("Random");o->add("50%");o->add("33%");o->add("25%");o->add("20%");}
              code1 {o->value(collect_readData(synth, 0, ADDVOICE::control::unisonPhaseInvert, npart, kititem, PART::engine::addVoice1 + nvoice));}
            } {}
            Fl_Slider UnisonFreqSpread {
              label {Frequency Spread}
              callback {//
                  o->selection_color(setSlider(o->value(),60));
                  unisonspreadoutput->do_callback();
                  send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::unisonFrequencySpread, o->value(), TOPLEVEL::type::Integer);
                  ;}
              tooltip {Frequency Spread of the Unison} xywh {181 434 120 16} type {Horz Knob} box THIN_DOWN_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1 value 64
              code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::unisonFrequencySpread, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {o->selection_color(setSlider(o->value(),60));}
              class mwheel_slider_rev
            }
            Fl_Value_Output unisonspreadoutput {
              label {(cents)}
              callback {//
                o->value(collect_readData(synth, 0, ADDVOICE::control::unisonSpreadCents, npart, kititem, PART::engine::addVoice1 + nvoice));
                ;}
              xywh {145 434 38 16} box THIN_DOWN_BOX labelsize 10 labelcolor 64 align 5 maximum 1000 textsize 10 textcolor 64
              code0 {o->step(0.1, 1);}
              code1 {o->value(collect_readData(synth, 0, ADDVOICE::control::unisonSpreadCents, npart, kititem, PART::engine::addVoice1 + nvoice));}
            }
            Fl_Dial UnisonVspeed {
              label {V.speed}
              callback {//
                o->selection_color(setKnob(o->value(),64));
                send_data(0, ADDVOICE::control::unisonVibratoSpeed, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip {Vibratto Average Speed} xywh {436 422 28 28} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::unisonVibratoSpeed, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {o->selection_color(setKnob(o->value(),64));}
              class WidgetPDial
            }
            Fl_Dial UnisonPhRnd {
              label {Ph.rnd}
              callback {//
                o->selection_color(setKnob(o->value(),127));
                send_data(0, ADDVOICE::control::unisonPhaseRandomise, o->value(), TOPLEVEL::type::Integer);
                ;}
              tooltip {Phase randomness} xywh {316 422 28 28} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
              code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::unisonPhaseRandomise, npart, kititem, PART::engine::addVoice1 + nvoice));}
              code1 {o->selection_color(setKnob(o->value(),127));}
              class WidgetPDial
            }
            Fl_Box unisName {
              label UNISON
              xywh {186 402 73 25} labelfont 1 labelsize 12 labelcolor 64
            }
          }
          Fl_Check_Button UnisonEn {
            label On
            callback {//
                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::enableUnison, o->value(), TOPLEVEL::type::Integer);
                ;}
            xywh {94 408 38 14} down_box DOWN_BOX selection_color 64 labelfont 3 labelsize 10 labelcolor 226
            code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::enableUnison, npart, kititem, PART::engine::addVoice1 + nvoice) > 1);}
            class Fl_Check_Button2
          }
        }
        Fl_Group amplitudegroup {
          xywh {5 68 285 212} box UP_FRAME labelfont 1 labelsize 12 labelcolor 64 align 17
        } {
          Fl_Dial voicevolume {
            label Volume
            callback {//
                int vol = lrint(o->value());
                o->selection_color(setKnob(vol,100));

                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::volume, vol, TOPLEVEL::type::Integer);
                ;}
            tooltip Volume xywh {30 86 33 33} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 127 step 1
            code0 {o->setValueType(VC_ADDVoiceVolume);}
            code1 {o->value(collect_readData(synth,0,ADDVOICE::control::volume, npart, kititem, PART::engine::addVoice1 + nvoice));}
            code2 {o->selection_color(setKnob(o->value(),100));}
            class WidgetPDial
          }
          Fl_Dial voicevsns {
            label {Vel Sens}
            callback {//
                o->selection_color(setKnob(o->value(),127));

                send_data(0, ADDVOICE::control::velocitySense, o->value(), TOPLEVEL::type::Integer);
                ;}
            tooltip {Velocity Sensing Function - rightmost/max disables)} xywh {86 87 33 33} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 127 step 1
            code0 {o->value(collect_readData(synth,0,ADDVOICE::control::velocitySense, npart, kititem, PART::engine::addVoice1 + nvoice));}
            code1 {o->setValueType(VC_AmpVelocitySense);}
            code2 {o->selection_color(setKnob(o->value(),127));}
            class WidgetPDial
          }
          Fl_Dial voicepan {
            label Pan
            callback {//
                int pan = lrint(o->value());
                o->selection_color(setKnob(pan,64));

                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::panning, pan, TOPLEVEL::type::Integer);
                ;}
            tooltip {Voice panning} xywh {160 86 33 33} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 6 maximum 127 step 1
            code0 {o->setValueType(VC_PanningStd);}
            code1 {o->value(collect_readData(synth,0,ADDVOICE::control::panning, npart, kititem, PART::engine::addVoice1 + nvoice));}
            code2 {o->selection_color(setKnob(o->value(),64));}
            class WidgetPDial
          }
          Fl_Dial voicewidth {
            label Width
            callback {//
                o->selection_color(setKnob(o->value(),63));

                send_data(0, ADDVOICE::control::randomWidth, o->value(), TOPLEVEL::type::Integer);
                ;}
            tooltip {Voice random width} xywh {235 86 33 33} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 63 step 1 value 63
            code0 {o->setValueType(VC_PanningRandom);}
            code1 {o->value(collect_readData(synth,0,ADDVOICE::control::randomWidth, npart, kititem, PART::engine::addVoice1 + nvoice));}
            code2 {o->selection_color(setKnob(o->value(),63));}
            class WidgetPDial
          }
          Fl_Check_Button voicerandompan {
            label Rand
            callback {//
                int tmp = o->value();
                if (tmp == 0)
                    voicewidth->deactivate();
                else
                    voicewidth->activate();

                send_data(0, ADDVOICE::control::enableRandomPan, tmp, TOPLEVEL::type::Integer);
                ;}
            tooltip {Enable random panning} xywh {205 94 15 15} down_box DOWN_BOX color 48 selection_color 64 labelsize 11 labelcolor 64 align 1
            code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableRandomPan, npart, kititem, PART::engine::addVoice1 + nvoice));}
            code1 {if (o->value() == 0) voicewidth->deactivate(); else voicewidth->activate();}
            class Fl_Check_Button2
          }
          Fl_Group voiceampenvgroup {
            label {Yoshimi : AddSynth Voice - Amplitude Envelope}
            xywh {10 135 275 70} box FLAT_BOX color 51 align 144
            code0 {o->init(pars->VoicePar[nvoice].AmpEnvelope, npart, kititem, nvoice + PART::engine::addVoice1, 0);}
            code1 {if (collect_readData(synth,0,ADDVOICE::control::enableAmplitudeEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice) == 0) o->deactivate();}
            class EnvelopeUI
          } {}
          Fl_Check_Button AmpEnvEn {
            label On
            callback {//
                if (o->value() == 0)
                    voiceampenvgroup->deactivate();
                else
                    voiceampenvgroup->activate();
                o->redraw();

                send_data(0, ADDVOICE::control::enableAmplitudeEnvelope, o->value(), TOPLEVEL::type::Integer);
                ;}
            tooltip {Enable Amplitude Envelope} xywh {14 139 38 14} down_box DOWN_BOX color 7 selection_color 64 labelfont 3 labelsize 10 labelcolor 226
            code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableAmplitudeEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice));}
            class Fl_Check_Button2
          }
          Fl_Group voiceamplfogroup {
            label {Amplitude LFO     }
            xywh {10 205 275 70} box FLAT_BOX color 47 align 144
            code0 {o->init(synth, npart, kititem, PART::engine::addVoice1 + nvoice, TOPLEVEL::insertType::amplitude);}
            code1 {if (collect_readData(synth,0,ADDVOICE::control::enableAmplitudeLFO, npart, kititem, PART::engine::addVoice1 + nvoice) == 0) o->deactivate();}
            class LFOUI
          } {}
          Fl_Check_Button AmpLfoEn {
            label On
            callback {//
                if (o->value() == 0)
                    voiceamplfogroup->deactivate();
                else
                    voiceamplfogroup->activate();
                o->redraw();

                send_data(0, ADDVOICE::control::enableAmplitudeLFO, o->value(), TOPLEVEL::type::Integer);
                ;}
            tooltip {Enable Amplitude LFO} xywh {14 210 38 14} down_box DOWN_BOX color 7 selection_color 64 labelfont 3 labelsize 10 labelcolor 226
            code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableAmplitudeLFO, npart, kititem, PART::engine::addVoice1 + nvoice));}
            class Fl_Check_Button2
          }
          Fl_Check_Button VolumeMinus {
            label Minus
            callback {//

        send_data(0, ADDVOICE::control::invertPhase, o->value(), TOPLEVEL::type::Integer);
        ;}
            tooltip {Reverse phase relative to other voices} xywh {12 75 50 10} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64
            code0 {o->value(collect_readData(synth,0,ADDVOICE::control::invertPhase, npart, kititem, PART::engine::addVoice1 + nvoice));}
            class Fl_Check_Button2
          }
          Fl_Box {} {
            xywh {140 88 4 40} box THIN_DOWN_FRAME
          }
          Fl_Box ampVoiceLabel {
            label AMPLITUDE
            xywh {128 72 35 17} labelfont 1 labelsize 10 labelcolor 64
          }
        }
        Fl_Group voicefiltergroup {
          label {FILTER      }
          xywh {290 35 285 245} box UP_FRAME labelfont 1 labelsize 12 labelcolor 64 align 17
          code0 {if (collect_readData(synth, 0, ADDVOICE::control::enableFilter, npart, kititem, PART::engine::addVoice1 + nvoice) == 0) o->deactivate();}
        } {
          Fl_Group voicefilter {
            label {ADsynth Voice - Filter}
            xywh {295 60 275 75} box FLAT_BOX color 50 align 144
            code0 {o->init(pars->VoicePar[nvoice].VoiceFilter,&pars->VoicePar[nvoice].PFilterVelocityScale, &pars->VoicePar[nvoice].PFilterVelocityScaleFunction, npart, kititem, PART::engine::addVoice1 + nvoice);}
            class FilterUI
          } {}
          Fl_Group voicefilterenvgroup {
            label {Yoshimi : AddSynth Voice - Filter Envelope}
            xywh {295 135 275 70} box FLAT_BOX color 51 align 144
            code0 {o->init(pars->VoicePar[nvoice].FilterEnvelope, npart, kititem, nvoice + PART::engine::addVoice1, 2);}
            code1 {if (collect_readData(synth, 0, ADDVOICE::control::enableFilterEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice)==0) o->deactivate();}
            class EnvelopeUI
          } {}
          Fl_Check_Button FilterEnvEn {
            label On
            callback {//
                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::enableFilterEnvelope, o->value(), TOPLEVEL::type::Integer);
                ;}
            tooltip {Enable Filter Envelope} xywh {300 140 38 14} down_box DOWN_BOX color 7 selection_color 64 labelfont 3 labelsize 10 labelcolor 226
            code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::enableFilterEnvelope, npart, kititem, PART::engine::addVoice1 + nvoice));}
            class Fl_Check_Button2
          }
          Fl_Group voicefilterlfogroup {
            label {Filter LFO     }
            xywh {295 205 275 70} box FLAT_BOX color 47 align 144
            code0 {o->init(synth, npart, kititem, PART::engine::addVoice1 + nvoice, TOPLEVEL::insertType::filter);}
            code1 {if (collect_readData(synth, 0, ADDVOICE::control::enableFilterLFO, npart, kititem, PART::engine::addVoice1 + nvoice)==0) o->deactivate();}
            class LFOUI
          } {}
          Fl_Check_Button FilterLfoEn {
            label On
            callback {//
                send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::enableFilterLFO, o->value(), TOPLEVEL::type::Integer);
                ;}
            tooltip {Enable Filter LFO} xywh {300 210 38 14} down_box DOWN_BOX color 7 selection_color 64 labelfont 3 labelsize 10 labelcolor 226
            code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::enableFilterLFO, npart, kititem, PART::engine::addVoice1 + nvoice));}
            class Fl_Check_Button2
          }
        }
        Fl_Box {} {
          xywh {5 35 64 33} box THIN_UP_FRAME
        }
        Fl_Group {} {
          xywh {69 35 136 33} box THIN_UP_FRAME
        } {
          Fl_Value_Slider Delay {
            label Delay
            callback {//
                o->selection_color(setSlider(o->value(),0));

                send_data(0, ADDVOICE::control::delay, o->value(), TOPLEVEL::type::Integer);
                ;}
            tooltip {Time before the voice activates} xywh {76 50 124 12} type {Horz Knob} box THIN_DOWN_BOX labelsize 11 labelcolor 64 align 1 maximum 127 step 1 textcolor 64
            code0 {o->value(collect_readData(synth,0,ADDVOICE::control::delay, npart, kititem, PART::engine::addVoice1 + nvoice));}
            code1 {o->setValueType(VC_ADDVoiceDelay);o->useCustomTip(true);}
            code2 {o->selection_color(setSlider(o->value(),0));}
            class mwheel_slider_rev
          }
        }
        Fl_Check_Button bypassfiltercheckbutton {
          label {Bypass Global}
          callback {//

        send_data(0, ADDVOICE::control::bypassGlobalFilter, o->value(), TOPLEVEL::type::Integer);
        ;}
          xywh {450 41 14 14} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 8
          code0 {o->value(collect_readData(synth,0,ADDVOICE::control::bypassGlobalFilter, npart, kititem, PART::engine::addVoice1 + nvoice));}
          class Fl_Check_Button2
        }
        Fl_Check_Button FilterEn {
          label On
          callback {//
              bypassfiltercheckbutton->redraw();

              send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::enableFilter, o->value(), TOPLEVEL::type::Integer);
              ;}
          tooltip {Enable Filter} xywh {294 41 38 14} down_box DOWN_BOX selection_color 64 labelfont 3 labelsize 10 labelcolor 226
          code0 {o->value(collect_readData(synth,0,ADDVOICE::control::enableFilter, npart, kititem, PART::engine::addVoice1 + nvoice));}
          class Fl_Check_Button2
        }
        Fl_Group extvoicegroup {
          label Voice
          xywh {5 400 80 76} box THIN_UP_FRAME labelfont 1 labelsize 12 labelcolor 49 align 17
        } {
          Fl_Choice ExtOsc {
            label Source
            callback {//
                  if (nvoice == 0)
                      o->deactivate();
                  if (o->value() != 0)
                  {
                      oscGroup->deactivate();
                      SoundType->deactivate();
                  }
                  else
                  {
                      oscGroup->activate();
                      SoundType->activate();
                  }
                  send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::soundType, 0, TOPLEVEL::type::Integer);
                  send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::externalOscillator, o->value() - 1, TOPLEVEL::type::Integer);
                  ;}
            tooltip {Use an earlier voice as input to this voice. All parameters from the imported voice remain in effect, except for volume, panning, base frequency and pitch bend scaling factor. The voice is also converted to mono. Parameters in the current voice will then tweak the signal further.} xywh {8 430 74 18} down_box BORDER_BOX selection_color 49 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 10 textcolor 64
            code0 {o->add("Local");}
            code1 {char tmp[50]; for (int i = 0; i < nvoice; ++i) {sprintf(tmp, "Voice %2d", i + 1); o->add(tmp);};}
            code2 {o->value(collect_readData(synth,0,ADDVOICE::control::externalOscillator, npart, kititem, PART::engine::addVoice1 + nvoice) + 1);}
            code3 {if (nvoice == 0) o->deactivate();}
          } {}
          Fl_Choice SoundType {
            callback {//
              int x = int(o->value());
              send_data(TOPLEVEL::action::forceUpdate, ADDVOICE::control::soundType, x, TOPLEVEL::type::Integer);
              ;}
            tooltip {Oscillator Type (sound/noise)} xywh {8 454 74 18} down_box BORDER_BOX selection_color 49 labelsize 10 labelcolor 64 when 6 textfont 1 textsize 10 textcolor 64
            code0 {o->add("Sound");o->add("Whit Ns");o->add("Pink Ns");o->add("Spot Ns");}
            code1 {o->value(collect_readData(synth,0,ADDVOICE::control::soundType,npart,kititem,PART::engine::addVoice1 + nvoice));}
            code2 {if (o->value()!=0) voicemodegroup->deactivate();}
            code3 {if (ExtOsc->value() > 0) o->deactivate();}
          } {}
        }
        Fl_Box noiselabel {
          label Noise
          callback {//
                update_osclabels();
                ;}
          xywh {130 500 400 65} labelfont 1 labelsize 50 labelcolor 7
          code0 {update_osclabels();}
        }
      }
      Fl_Group Vname {
        label VOICE
        xywh {476 10 63 16} labelfont 1 labelcolor 64 align 0
      } {}
    }
  }
  Function {ADvoiceUI(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} {
    code {//
        nvoice = 0;
        pars = NULL;
        oscedit = NULL;
        lastWaveW = 0;
        ;} {}
  }
  Function {send_data(int action, int control, float value, int type)} {} {
    code {//
    type |= TOPLEVEL::type::Write;
    collect_writeData(synth, value, action, type, control, npart, kititem, nvoice + PART::engine::addVoice1);
    ;} {}
  }
  Function {returns_update(CommandBlock *getData)} {} {
    code {//
    float value = getData->data.value;
    unsigned char control = getData->data.control;
    unsigned char voice = getData->data.engine;
    //std::cout << "voice " << int(voice) << "   nvoice " << int(nvoice) << std::endl;
    if (voice >= PART::engine::addMod1)
        voice -= PART::engine::addMod1;
    else if (voice >= PART::engine::addVoice1)
        voice -= PART::engine::addVoice1;
    int tmp;
    bool val_bool = _SYS_::F2B(value);
    if (control != ADDVOICE::control::enableVoice &&  voice != nvoice)
        return;

    switch(control)
    {
        case ADDVOICE::control::volume:
            voicevolume->value(value);
            voicevolume->selection_color(setKnob(value,100));
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voicevolume->value(value);
                synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voicevolume->selection_color(setSlider(value,100));
            break;

        case ADDVOICE::control::velocitySense:
            voicevsns->value(value);
            voicevsns->selection_color(setKnob(value,127));
            break;

        case ADDVOICE::control::panning:
            voicepan->value(value);
            voicepan->selection_color(setKnob(value,64));
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voicepanning->value(value);
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voicepanning->selection_color(setKnob(value,64));
            break;

        case ADDVOICE::control::enableRandomPan:
            voicerandompan->value(val_bool);
            if (val_bool)
                voicewidth->activate();
            else
                voicewidth->deactivate();
            break;

        case ADDVOICE::control::randomWidth:
            voicewidth->value(value);
            voicewidth->selection_color(setKnob(value,63));
            break;

        case ADDVOICE::control::invertPhase:
            VolumeMinus->value(val_bool);
            break;

        case ADDVOICE::control::enableAmplitudeEnvelope:
            AmpEnvEn->value(val_bool);
            if (val_bool == 0)
                    voiceampenvgroup->deactivate();
                else
                    voiceampenvgroup->activate();
            break;

        case ADDVOICE::control::enableAmplitudeLFO:
            AmpLfoEn->value(val_bool);
            if (val_bool == 0)
                    voiceamplfogroup->deactivate();
                else
                    voiceamplfogroup->activate();
            break;

        case ADDVOICE::control::modulatorType:
            ModType->value((int)value);
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->update_modlabel();
            if (value == 0)
                    voiceFMparametersgroup->deactivate();
                else
                    voiceFMparametersgroup->activate();
            break;

        case ADDVOICE::control::externalModulator:
            tmp = (int) value;
            ExtMod->value(tmp + 1);
            if (tmp >= 0)
            {
                modoscil->deactivate();
            }
            else
            {
                modoscil->activate();
            }
            voiceFMparametersgroup->redraw();
            update_fmoscil();
            oscFM->redraw();
            modoscil->redraw();
            modvoicelabel->do_callback();
            break;

        case ADDVOICE::control::detuneFrequency:
            if (voice == nvoice)
            {
                Detune->value(value);
                Detune->selection_color(setSlider(value,0));
                detunevalueoutput->do_callback();
            }
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voicedetune->value(value);
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voicedetune->selection_color(setSlider(value,0));
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->detunevalueoutput->do_callback();
            break;

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

        case ADDVOICE::control::baseFrequencyAs440Hz:
            Freq440->value(val_bool);
            if (value == 0 && Mod440->value() == 0)
                fixedfreqetdial->deactivate();
            else
                fixedfreqetdial->activate();
            break;

        case ADDVOICE::control::octave:
            Octave->value((int) value);
            break;

        case ADDVOICE::control::detuneType:
            FreqDetunetype->value((int) value);
            detunevalueoutput->do_callback();
            break;

        case ADDVOICE::control::coarseDetune:
            CoarseDetune->value((int) value);
            break;

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

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

        case ADDVOICE::control::enableFrequencyEnvelope:
            FreqEn->value(val_bool);
            if (val_bool == 0)
                voicefreqenvgroup->deactivate();
            else
                voicefreqenvgroup->activate();
            break;

        case ADDVOICE::control::enableFrequencyLFO:
            FreqLfoEn->value(val_bool);
             if (val_bool == 0)
                 voicefreqlfogroup->deactivate();
             else
                 voicefreqlfogroup->activate();
            break;

        case ADDVOICE::control::unisonFrequencySpread:
            UnisonFreqSpread->value(value);
            UnisonFreqSpread->selection_color(setSlider(value,60));
            unisonspreadoutput->do_callback();
            break;

        case ADDVOICE::control::unisonPhaseRandomise:
            UnisonPhRnd->value(value);
            UnisonPhRnd->selection_color(setKnob(value,127));
            break;

        case ADDVOICE::control::unisonStereoSpread:
            UnisonStereo->value(value);
            UnisonStereo->selection_color(setKnob(value,64));
            break;

        case ADDVOICE::control::unisonVibratoDepth:
            UnisonVib->value(value);
            UnisonVib->selection_color(setKnob(value,64));
            break;

        case ADDVOICE::control::unisonVibratoSpeed:
            UnisonVspeed->value(value);
            UnisonVspeed->selection_color(setKnob(value,64));
            break;

        case ADDVOICE::control::unisonSize:
            {
                tmp = int(value);
                unisonsize->value(tmp);
                unisongroup->redraw();
                UnisonEn->redraw();
            }
            break;

        case ADDVOICE::control::unisonPhaseInvert:
            UnisonInvert->value(value);
            break;

        case ADDVOICE::control::enableUnison:
            UnisonEn->value(val_bool);
            if (val_bool == 0)
            {
                unisonsize->value(2);
                unisongroup->deactivate();
            }
            else
            {
                unisongroup->activate();
                unisongroup->redraw();
                UnisonEn->redraw();
            }
            break;

        case ADDVOICE::control::enableFilter:
            FilterEn->value(val_bool);
            if (val_bool)
                  voicefiltergroup->activate();
              else
                  voicefiltergroup->deactivate();
              bypassfiltercheckbutton->redraw(); // yes it's needed!
            break;

        case ADDVOICE::control::bypassGlobalFilter:
            bypassfiltercheckbutton->value(val_bool);
            break;
        case ADDVOICE::control::enableFilterEnvelope:
            FilterEnvEn->value(val_bool);
            if (val_bool)
                voicefilterenvgroup->activate();
            else
                voicefilterenvgroup->deactivate();
            FilterEnvEn->redraw(); // yes it's needed!
            break;

        case ADDVOICE::control::enableFilterLFO:
            FilterLfoEn->value(val_bool);
            if (val_bool)
                voicefilterlfogroup->activate();
            else
                voicefilterlfogroup->deactivate();
            FilterLfoEn->redraw(); // yes it's needed!
            break;

        case ADDVOICE::control::modulatorAmplitude:
            ModVolume->value(value);
            ModVolume->selection_color(setSlider(ModVolume->value(),90));
            break;

        case ADDVOICE::control::modulatorVelocitySense:
            ModVsense->value(value);
            ModVsense->selection_color(setSlider(ModVsense->value(),64));
            break;

        case ADDVOICE::control::modulatorHFdamping:
            ModFdamp->value(value);
            ModFdamp->selection_color(setSlider(ModFdamp->value(),0));
            break;

        case ADDVOICE::control::enableModulatorAmplitudeEnvelope:
            ModAmpEn->value(val_bool);
            if (val_bool)
                voiceFMampenvgroup->activate();
            else
                voiceFMampenvgroup->deactivate();
            break;

        case ADDVOICE::control::modulatorDetuneFrequency:
            ModDetune->value(value);
            ModDetune->selection_color(setSlider(value,0));
            fmdetunevalueoutput->do_callback();
            break;

        case ADDVOICE::control::modulatorDetuneFromBaseOsc:
            detuneFromBaseOsc->value(value);
            break;


        case ADDVOICE::control::modulatorFrequencyAs440Hz:
            tmp = (val_bool);
            Mod440->value(tmp);
            if (tmp == 0 && lrint(Freq440->value() == 0))
                fixedfreqetdial->deactivate();
            else
                fixedfreqetdial->activate();
            if (tmp != 0)
                detuneFromBaseOsc->deactivate();
            else
                detuneFromBaseOsc->activate();
            break;
        case ADDVOICE::control::modulatorOctave:
            ModOctave->value((int) value);
            break;

        case ADDVOICE::control::modulatorDetuneType:
            ModDetuneType->value((int) value);
            fmdetunevalueoutput->do_callback();
            break;

        case ADDVOICE::control::modulatorCoarseDetune:
            ModCoarseDetune->value((int) value);
            break;

        case ADDVOICE::control::enableModulatorFrequencyEnvelope:
            ModFreqEn->value(val_bool);
            if (val_bool == 0)
                voiceFMfreqenvgroup->deactivate();
            else
                voiceFMfreqenvgroup->activate();
            break;

        case ADDVOICE::control::modulatorOscillatorPhase:
            ModPhase->value(value);
            oscFM->phase = 64 - lrint(value);
            ModPhase->selection_color(setSlider(ModPhase->value(),0));
            update_fmoscil();
            oscFM->redraw();
            modoscil->redraw();
            modvoicelabel->do_callback();
            break;

        case ADDVOICE::control::modulatorOscillatorSource:
            tmp = int(value);
            ExtModOsc->value(tmp + 1);
            if (tmp < 0)
            {
                tmp = voice;
                changeFMoscilbutton->labelcolor(gen_text);
            }
            else
                changeFMoscilbutton->labelcolor(alt_warn_tex);
            update_fmoscil();
            voiceFMparametersgroup->redraw();
            oscFM->redraw();
            modoscil->redraw();
            modvoicelabel->do_callback();
            break;

        case ADDVOICE::control::delay:
            Delay->value(value);
            Delay->selection_color(setSlider(Delay->value(),0));
            break;

        case ADDVOICE::control::enableVoice:
            tmp = (val_bool);
            voiceonbutton->value(tmp);
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voiceenabled->value(tmp);
            synth->getGuiMaster()->partui->adnoteui->setVoiceTabs(voice, false);
            synth->getGuiMaster()->partui->adnoteui->setTabColour(voice);
            if (tmp)
            {
                nvoice = voice;
                voiceparametersgroup->activate();
                synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voicelistitemgroup->activate();
            }
            else
            {
                voiceparametersgroup->deactivate();
                synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voicelistitemgroup->deactivate();
            }
            voiceonbutton->redraw();
            synth->getGuiMaster()->partui->adnoteui->voiceTabBar->redraw();
            break;

        case ADDVOICE::control::enableResonance:
            tmp = (val_bool);
            if (voice == nvoice)
                ResonanceEn->value(tmp);
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[voice]->voiceresonanceenabled->value(tmp);
            break;

        case ADDVOICE::control::voiceOscillatorPhase:
            tmp = (int)value;
            VoiceOscPhase->value(tmp);
            osc->phase = 64 - tmp;
            VoiceOscPhase->selection_color(setSlider(VoiceOscPhase->value(),0));
            update_voiceoscil();
            voiceoscil->redraw();
            osclabel->redraw();
            break;

        case ADDVOICE::control::voiceOscillatorSource:
            tmp = int(value);
            UseOsc->value(tmp + 1);
            if (tmp < 0)
            {
                tmp = voice;
                changevoiceoscilbutton->labelcolor(gen_text);
            }
            else
                changevoiceoscilbutton->labelcolor(alt_warn_tex);
            changevoiceoscilbutton->redraw();
            update_voiceoscil();
            voiceoscil->redraw();
            update_osclabels();
            break;

        case ADDVOICE::control::soundType:
            tmp = lrint(value);
            SoundType->value(tmp);
            if (tmp)
                voicemodegroup->deactivate();
            else
                voicemodegroup->activate();
            update_voiceoscil();
            update_osclabels();
            synth->getGuiMaster()->partui->adnoteui->voicelistitem[nvoice]->refreshlist(nvoice);
            break;

        case ADDVOICE::control::externalOscillator:
            tmp = int(value);
            ExtOsc->value(tmp + 1);
            update_voiceoscil();
            update_osclabels();
            voiceoscil->redraw();
            break;
    }
    ;} {}
  }
  Function {paste()} {} {
    code {//
        if (oscedit->osceditUI->visible())
        {
            oscedit->refresh();
        }
        ;} {}
  }
  Function {update_osclabels()} {} {
    code {//
        int soundType = SoundType->value();
        char useOsc = UseOsc->value();
        char extOsc = ExtOsc->value();
    if (extOsc > 0)
    {
        char str[15];
        snprintf(str, sizeof(str), "Voice %d", extOsc);
        osclabel->copy_label(str);
        osclabel->labelcolor(ext_voice);
        osclabel->show();
        noiselabel->hide();
    }
    else if (soundType == 0 && useOsc > 0)
    {
        char str[15];
        snprintf(str, sizeof(str), "Osc. %d", useOsc);
        osclabel->copy_label(str);
        osclabel->labelcolor(ext_osc);
        osclabel->show();
        noiselabel->hide();
    }
    else if (soundType == 1)
    {
        noiselabel->copy_label("White Noise");
        noiselabel->labelcolor(7);
        noiselabel->show();
        osclabel->hide();
    }
    else if (soundType == 2)
    {
        noiselabel->copy_label("Pink Noise");
        noiselabel->labelcolor(5);
        noiselabel->show();
        osclabel->hide();
    }
    else if (soundType == 3)
    {
        noiselabel->copy_label("Spot Noise");
        noiselabel->labelcolor(6);
        noiselabel->show();
        osclabel->hide();
    }
    else
    {
        noiselabel->hide();
        osclabel->hide();
    }
     ;} {}
  }
  Function {update_modvoicelabel()} {} {
    code {//
        int fmVoice = collect_readData(synth,0,ADDVOICE::control::externalModulator, npart, kititem, PART::engine::addVoice1 + nvoice);
        int fmExtOsc = collect_readData(synth,0,ADDVOICE::control::modulatorOscillatorSource, npart, kititem, PART::engine::addVoice1 + nvoice);
        if (fmVoice >= 0)
        {
            char str[15];
            snprintf(str, sizeof(str), "Voice %d",char(fmVoice) + 1);
            modvoicelabel->copy_label(str);
            modvoicelabel->labelcolor(ext_voice);
            modvoicelabel->show();
        }
        else if (fmExtOsc >= 0)
        {
            char str[15];
            snprintf(str, sizeof(str), "Mod. %d", char(fmExtOsc) + 1);
            modvoicelabel->copy_label(str);
            modvoicelabel->labelcolor(ext_osc);
            modvoicelabel->show();
        }
        else
        {
            modvoicelabel->hide();
        }
    ;} {}
  }
  Function {update_voiceoscil()} {} {
    code {// updating
        int nvs = nvoice;
        int nvp = nvoice;

        voiceOscUpdate(synth, npart, kititem, nvoice, nvs, nvp);

        // we still need 'pars->' here :(
        oscil->changeParams(pars->VoicePar[nvs].POscil);

        osc->init(oscil,0,64-collect_readData(synth,0,ADDVOICE::control::voiceOscillatorPhase, npart, kititem, PART::engine::addVoice1 + nvoice),synth);

        if (collect_readData(synth,0,ADDVOICE::control::externalOscillator, npart, kititem, PART::engine::addVoice1 + nvoice) >= 0
            || collect_readData(synth,0,ADDVOICE::control::soundType, npart, kititem, PART::engine::addVoice1 + nvoice) > 0)

            voiceoscil->deactivate();
        else
            voiceoscil->activate();

        ;} {}
  }
  Function {update_fmoscil()} {} {
    code {//
        int nv=nvoice;
        int fmVoice = collect_readData(synth,0,ADDVOICE::control::externalModulator, npart, kititem, PART::engine::addVoice1 + nvoice);
        int fmExtOsc = collect_readData(synth,0,ADDVOICE::control::modulatorOscillatorSource, npart, kititem, PART::engine::addVoice1 + nvoice);
        if (fmVoice >= 0)
        {
            nv = fmVoice;
            while (collect_readData(synth,0,ADDVOICE::control::externalOscillator, npart, kititem, PART::engine::addVoice1 + nv) >= 0)
            {
                nv = collect_readData(synth,0,ADDVOICE::control::externalOscillator, npart, kititem, PART::engine::addVoice1 + nv);
            }
            oscilFM->changeParams(pars->VoicePar[nv].POscil);
            oscFM->init(oscilFM,0,pars->VoicePar[nv].Poscilphase, synth);
        }
        else
        {
            if (fmExtOsc >= 0)
            {
                nv = fmExtOsc;
            }
            oscilFM->changeParams(pars->VoicePar[nv].POscilFM);
            oscFM->init(oscilFM,0,pars->VoicePar[nvoice].PFMoscilphase, synth);
	}
	;} {}
  }
  Function {voiceRtext(float dScale)} {} {
    code {//
    if (oscedit)
    {
        if (oscedit->osceditUI->visible() && lastWaveW != oscedit->osceditUI->w())
        {
            lastWaveW = oscedit->osceditUI->w();
            oscedit->waveRtext();
        }
    }
    voiceampenvgroup->wincheck();
    voicefilterenvgroup->wincheck();
    voicefreqenvgroup->wincheck();

    voiceFMampenvgroup->wincheck();
    voiceFMfreqenvgroup->wincheck();

    if (!ADnoteVoiceParameters->visible())
        return;

    if (dScale == lastdScale)
        return;

    voiceamplfogroup->lfoRtext(dScale);
    voiceampenvgroup->envRtext(dScale);

    voicefilterlfogroup->lfoRtext(dScale);
    voicefilterenvgroup->envRtext(dScale);

    voicefreqlfogroup->lfoRtext(dScale);
    voicefreqenvgroup->envRtext(dScale);

    voicefilter->filterRtext(dScale);

    lastdScale = dScale;

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

    voiceonbutton->labelsize(size14);
    Vname->labelsize(size14);

    ResonanceEn->labelsize(size11);
    ampVoiceLabel->labelsize(size);
    voicevolume->labelsize(size);
    voicevsns->labelsize(size);
    voicepan->labelsize(size);
    voicewidth->labelsize(size);
    voicerandompan->labelsize(size11);
    AmpEnvEn->labelsize(size);
    AmpLfoEn->labelsize(size);
    VolumeMinus->labelsize(size);

    voicefiltergroup->labelsize(size12);
    FilterEnvEn->labelsize(size);
    FilterLfoEn->labelsize(size);

    Delay->labelsize(size11);
    bypassfiltercheckbutton->labelsize(size12);
    FilterEn->labelsize(size);

    freqencygrp->labelsize(size12);
    FreqEn->labelsize(size);
    FreqLfoEn->labelsize(size);
    voiceoctavetext->labelsize(size);
        Octave->textsize(size11);
    CoarseDetune->labelsize(size);
       CoarseDetune->textsize(size11);
    detunevalueoutput->labelsize(size);
        detunevalueoutput->textsize(size);
    FreqDetunetype->labelsize(size);
        FreqDetunetype->textsize(size11);
    bend->labelsize(size);
    Freq440->labelsize(size11);
    fixedfreqetdial->labelsize(size);
    offset->labelsize(size);

    unisonsize->labelsize(size);
        unisonsize->textsize(size11);
    UnisonStereo->labelsize(size);
    UnisonVib->labelsize(size);
    UnisonFreqSpread->labelsize(size);
    unisonspreadoutput->labelsize(size);
        unisonspreadoutput->textsize(size11);
    UnisonVspeed->labelsize(size);
    UnisonPhRnd->labelsize(size);
    UnisonInvert->labelsize(size);
        UnisonInvert->textsize(size11);
    UnisonEn->labelsize(size);
    unisName->labelsize(size12);

    extvoicegroup->labelsize(size12);
    ExtOsc->labelsize(size);
        ExtOsc->textsize(size);
    SoundType->labelsize(size);
        SoundType->textsize(size);

    oscParamBox->labelsize(size12);
    UseOsc->labelsize(size);
        UseOsc->textsize(size);
    changevoiceoscilbutton->labelsize(size);
    VoiceOscPhase->labelsize(size);

    noiselabel->labelsize(int(50 * dScale));
    osclabel->labelsize(int(50 * dScale));

    voiceFMparametersgroup->labelsize(size12);
    voiceFMampenvgroup->envRtext(dScale);
    voiceFMfreqenvgroup->envRtext(dScale);

    ExtMod->labelsize(size11);
        ExtMod->textsize(size14);

    Modampgrp->labelsize(size11);
    ModVolume->labelsize(size11);
        ModVolume->textsize(size);
    ModVsense->labelsize(size11);
        ModVsense->textsize(size);
    ModFdamp->labelsize(size11);
        ModFdamp->textsize(size);
    ModAmpEn->labelsize(size);

    modfrequency->labelsize(size11);
    ModCoarseDetune->labelsize(size);
        ModCoarseDetune->textsize(size);
    modoctavetext->labelsize(size);
        ModOctave->textsize(size);
    fmdetunevalueoutput->labelsize(size);
        fmdetunevalueoutput->textsize(size);
    detuneFromBaseOsc->labelsize(size11);
    Mod440->labelsize(size11);
    ModDetuneType->labelsize(size);
        ModDetuneType->textsize(size11);

    ModFreqEn->labelsize(size);

    modtypetext->labelsize(size11);
        ModType->textsize(size14);

    ModLocalOsc->labelsize(size12);
    changeFMoscilbutton->labelsize(size);
    ModPhase->labelsize(size);
    ExtModOsc->labelsize(size);
        ExtModOsc->textsize(size);

    modvoicelabel->labelsize(int(40 * dScale));

    ADnoteVoiceParameters->redraw();} {}
  }
  Function {voicetheme()} {} {
    code {//
        if (oscedit)
        {
            if (oscedit->osceditUI->visible())
            {
                oscedit->waveRtext();
            }
        }

        voiceampenvgroup->theme();
        voicefreqenvgroup->theme();
        voicefilterenvgroup->theme();
        voicefilter->theme();

        voiceFMampenvgroup->theme();
        voiceFMfreqenvgroup->theme();
        ;} {}
  }
  Function {init(ADnoteParameters *parameters,int npart_, int kititem_, int nvoice_)} {} {
    code {//
        synth = & parameters->getSynthEngine();
        pars = parameters;
        npart = npart_;
        kititem = kititem_;
        nvoice = nvoice_;
        lastdScale = 0;
        fft = new fft::Calc(synth->oscilsize);
        oscil = new OscilGen(*fft, NULL, synth, parameters->VoicePar[nvoice].POscil);
        oscilFM = new OscilGen(*fft, NULL, synth, parameters->VoicePar[nvoice].POscilFM);
        make_window();
        end();
        if (nvoice == 0)
        {
            UseOsc->deactivate();
            ExtMod->deactivate();
            ExtModOsc->deactivate();
        }
        ADnoteVoiceParameters->show();
        ;} {}
  }
  Function {~ADvoiceUI()} {} {
    code {//
        ADnoteVoiceParameters->hide();
        hide();
        if (oscedit)
            delete oscedit;
        delete oscil;
        delete oscilFM;
        delete fft;
        ;} {}
  }
  decl {int nvoice;} {public local
  }
  decl {int npart;} {private local
  }
  decl {int kititem;} {private local
  }
  decl {ADnoteParameters *pars;} {private local
  }
  decl {OscilEditor *oscedit;} {public local
  }
  decl {fft::Calc *fft;} {private local
  }
  decl {OscilGen *oscil;} {public local
  }
  decl {OscilGen *oscilFM;} {public local
  }
  decl {Oscilloscope *osc;} {private local
  }
  decl {Oscilloscope *oscFM;} {private local
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {float lastdScale;} {private local
  }
  decl {int lastWaveW;} {private local
  }
}

class ADvoicelistitem {: {public Fl_Group}
} {
  Function {make_window()} {} {
    Fl_Window ADnoteVoiceListItem {
      xywh {705 176 635 30} type Double box GTK_THIN_UP_BOX labelcolor 64 hide
      class Fl_Group
    } {
      Fl_Group enabledpatch {
        label 1
        xywh {4 4 34 18} box UP_BOX labelfont 2 labelcolor 226 align 20
        code0 {char tmp[12]; snprintf(tmp, 12, "%d", nvoice + 1); o->label(strdup(tmp));}
      } {}
      Fl_Check_Button voiceenabled {
        callback {//
            bool enab = _SYS_::F2B(o->value());
            collect_writeData(synth, enab, TOPLEVEL::action::forceUpdate, (TOPLEVEL::type::Integer | TOPLEVEL::type::Write), ADDVOICE::control::enableVoice, npart, kititem, PART::engine::addVoice1 + nvoice);
            ;}
        xywh {18 7 15 15} down_box DOWN_BOX selection_color 64 labeltype EMBOSSED_LABEL labelcolor 64
        code1 {o->value(collect_readData(synth,0,ADDVOICE::control::enableVoice, npart, kititem, PART::engine::addVoice1 + nvoice));}
        class Fl_Check_Button2
      }
      Fl_Group voicelistitemgroup {
        xywh {38 1 593 25} box FLAT_BOX labelcolor 64
        code0 {if (voiceenabled->value() == 0) o->deactivate();}
      } {
        Fl_Value_Slider voicevolume {
          callback {//
            int vol = lrint(o->value());
            o->selection_color(setSlider(vol,100));

            collect_writeData(synth, vol, TOPLEVEL::action::forceUpdate, (TOPLEVEL::type::Write | TOPLEVEL::type::Integer), ADDVOICE::control::volume, npart, kititem, PART::engine::addVoice1 + nvoice);
            ;}
          tooltip Volume xywh {155 4 122 20} type {Horz Knob} box THIN_DOWN_BOX labelsize 8 labelcolor 64 maximum 127 step 1 textcolor 64
          code0 {o->value(collect_readData(synth,0,ADDVOICE::control::volume, npart, kititem, PART::engine::addVoice1 + nvoice));}
          code1 {o->selection_color(setSlider(o->value(),100));}
          code2 {o->setValueType(VC_ADDVoiceVolume);o->useCustomTip(true);}
          class mwheel_slider_rev
        }
        Fl_Check_Button voiceresonanceenabled {
          callback {//
    bool enab = _SYS_::F2B(o->value());
    synth->getGuiMaster()->partui->adnoteui->advoice->ResonanceEn->value(enab);

    collect_writeData(synth, enab, 0, (TOPLEVEL::type::Write | TOPLEVEL::type::Integer), ADDVOICE::control::enableResonance, npart, kititem, PART::engine::addVoice1 + nvoice);
    ;}
          tooltip {Resonance On/Off} xywh {305 5 15 17} down_box DOWN_BOX selection_color 64 labeltype EMBOSSED_LABEL labelfont 1 labelsize 11 labelcolor 64 align 4
          code0 {o->value(collect_readData(synth,0, ADDVOICE::control::enableResonance, npart, kititem, PART::engine::addVoice1 + nvoice));}
          class Fl_Check_Button2
        }
        Fl_Value_Slider voicelistvibratto {
          callback {//
            int lfodepth = lrint(o->value());
            o->selection_color(setSlider(lfodepth,40));

            collect_writeData(synth, lfodepth, TOPLEVEL::action::forceUpdate, (TOPLEVEL::type::Write | TOPLEVEL::type::Integer), 1, npart, kititem, PART::engine::addVoice1 + nvoice, 0, 1);
            ;}
          tooltip {Frequency LFO amount} xywh {535 4 95 20} type {Horz Knob} box THIN_DOWN_BOX labelsize 8 labelcolor 64 align 5 maximum 127 step 1 textcolor 64 deactivate
          code0 {o->value(collect_readData(synth, 0, LFOINSERT::control::depth, npart, kititem, PART::engine::addVoice1 + nvoice, 0, 1));}
          code1 {o->setValueType(VC_LFOdepthFreq);o->useCustomTip(true);}
          code2 {o->selection_color(setSlider(o->value(),40));}
          class mwheel_slider_rev
        }
        Fl_Dial voicepanning {
          callback {//
            int panning = lrint(o->value());
            o->selection_color(setKnob(panning,64));

            collect_writeData(synth, panning, TOPLEVEL::action::forceUpdate, (TOPLEVEL::type::Write | TOPLEVEL::type::Integer), ADDVOICE::control::panning, npart, kititem, PART::engine::addVoice1 + nvoice);
            ;}
          tooltip {Voice panning} xywh {282 4 20 20} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 4 maximum 127 step 1
          code0 {o->setValueType(VC_PanningStd);}
          code1 {o->value(collect_readData(synth, 0,ADDVOICE::control::panning, npart, kititem, PART::engine::addVoice1 + nvoice));}
          code2 {o->selection_color(setSlider(o->value(),64));}
          class WidgetPDial
        }
        Fl_Group voiceoscil {
          callback {//
    update_voiceoscil();
    ;}
          xywh {88 4 30 20} box THIN_DOWN_FRAME color 32 labelcolor 49
          code0 {osc = new Oscilloscope(o->x(), o->y(), o->w(), o->h(), 20, "");}
          code1 {update_voiceoscil();}
        } {}
        Fl_Box noiselabel {
          label N
          callback {//
    int tmp = collect_readData(synth,0,ADDVOICE::control::soundType,npart,kititem,PART::engine::addVoice1 + nvoice);
    update_noiselabel();
    if (tmp == 0)
    {
        voiceresonanceenabled->activate();
        detunevalueoutput->activate();
        voicedetune->activate();
        return;
    }
    voiceresonanceenabled->deactivate();
    detunevalueoutput->deactivate();
    voicedetune->deactivate();
    ;}
          xywh {93 5 20 20} labelfont 1 labelsize 13 labelcolor 7
        }
        Fl_Group modoscil {
          callback {//
	update_modoscil();
	;}
          xywh {122 4 30 20} box THIN_DOWN_FRAME color 32 labelcolor 49
          code0 {modosc = new Oscilloscope(o->x(), o->y(), o->w(), o->h(), 20, "");}
          code1 {update_modoscil();}
        } {}
        Fl_Box modlabel {
          label N
          callback {//
                update_modlabel();
                ;}
          xywh {127 5 20 20} labelfont 1 labelsize 13 labelcolor 7
        }
        Fl_Slider voicedetune {
          callback {//
            int detune = lrint(o->value());
            o->selection_color(setSlider(detune,0));
            collect_writeData(synth, detune, TOPLEVEL::action::forceUpdate, TOPLEVEL::type::Write, ADDVOICE::control::detuneFrequency, npart, kititem, PART::engine::addVoice1 + nvoice);
            ;}
          tooltip {Fine Detune (cents)} xywh {365 4 164 20} type {Horz Knob} box THIN_DOWN_BOX labelcolor 64 minimum -8192 maximum 8191 step 1
          code0 {o->value(collect_readData(synth, 0, ADDVOICE::control::detuneFrequency, npart, kititem, PART::engine::addVoice1 + nvoice));}
          code1 {o->selection_color(setSlider(o->value(),0));}
          class mwheel_slider_rev
        }
        Fl_Value_Output detunevalueoutput {
          callback {//
              int detType = collect_readData(synth, 0, ADDVOICE::control::detuneType, npart, kititem, PART::engine::addVoice1 + nvoice);
	o->value(getDetune((detType == 0) ? (collect_readData(synth, 0, ADDSYNTH::detuneType, npart, kititem, PART::engine::addSynth)) : (detType), 0, collect_readData(synth, 0, ADDVOICE::control::detuneFrequency, npart, kititem, PART::engine::addVoice1 + nvoice) + 8192) * collect_readData(synth, 0, ADDSYNTH::control::bandwidthMultiplier, npart, kititem, PART::engine::addSynth));
	;}
          xywh {326 4 40 20} box THIN_DOWN_BOX labelsize 10 labelcolor 64 align 0 when 3 minimum -5000 maximum 5000 textsize 11 textcolor 64
          code0 {o->step(0.01, 1);}
        }
        Fl_Button itemedit {
          label Edit
          callback {//
              synth->getGuiMaster()->partui->adnoteui->setVoiceTabs(nvoice);
              synth->getGuiMaster()->partui->adnoteui->set_voice(true);
              if ((Fl::event_button() == 3))
                  synth->getGuiMaster()->partui->adnoteui->ADnoteVoiceList->hide();
              ;}
          tooltip {Right click: also close this} xywh {42 4 40 20} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 12 labelcolor 64
        }
      }
    }
  }
  Function {ADvoicelistitem(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} {
    code {//
    nvoice = 0;
    pars = NULL;
    ;} {}
  }
  Function {init(ADnoteParameters *parameters, int npart_, int kititem_, int nvoice_)} {} {
    code {//
    synth = & parameters->getSynthEngine();
    pars = parameters;
    npart = npart_;
    kititem = kititem_;
    nvoice = nvoice_;
    fft = new fft::Calc(synth->oscilsize);
    oscil = new OscilGen(*fft, NULL, synth, parameters->VoicePar[nvoice].POscil);
    oscilFM = new OscilGen(*fft, NULL, synth, parameters->VoicePar[nvoice].POscilFM);
    make_window();
    if (collect_readData(synth,0,ADDVOICE::control::enableFrequencyLFO, npart, kititem, PART::engine::addVoice1 + nvoice) > 0)
        voicelistvibratto->activate();
    else
        voicelistvibratto->deactivate();
    ADnoteVoiceListItem->show();
    end();
    ;} {}
  }
  Function {refreshlist(int nvoice)} {} {
    code {//
        // a lot missing from here :(
        voiceenabled->value(collect_readData(synth,0,ADDVOICE::control::enableVoice, npart, kititem, PART::engine::addVoice1 + nvoice));
        voiceresonanceenabled->value(collect_readData(synth,0,ADDVOICE::control::enableResonance, npart, kititem, PART::engine::addVoice1 + nvoice));
        voicevolume->value(collect_readData(synth,0,ADDVOICE::control::volume, npart, kititem, PART::engine::addVoice1 + nvoice));
            voicevolume->selection_color(setSlider(voicevolume->value(),100));
        voicedetune->value(collect_readData(synth,0,ADDVOICE::control::detuneFrequency, npart, kititem, PART::engine::addVoice1 + nvoice));
        voicedetune->selection_color(setSlider(voicedetune->value(),0));

        voicepanning->value(collect_readData(synth,0,ADDVOICE::control::panning, npart, kititem, PART::engine::addVoice1 + nvoice));
            voicepanning->selection_color(setKnob(voicepanning->value(),64));
        if (collect_readData(synth,0,ADDVOICE::control::enableFrequencyLFO, npart, kititem, PART::engine::addVoice1 + nvoice)==0)
            voicelistvibratto->deactivate();
        else
            voicelistvibratto->activate();
        // this line dips into the LFO code. needs to be handled differently.
        voicelistvibratto->value(pars->VoicePar[nvoice].FreqLfo->Pintensity);
            voicelistvibratto->selection_color(setKnob(voicelistvibratto->value(),40));

        synth->getGuiMaster()->partui->adnoteui->advoice->update_voiceoscil();

        if (voiceenabled->value() == 0)
        {
            voicelistitemgroup->deactivate();
        }
        else
        {
            voicelistitemgroup->activate();
        }
        detunevalueoutput->do_callback();
        voiceoscil->do_callback();
        noiselabel->do_callback();
        modoscil->do_callback();
        modlabel->do_callback();
        ADnoteVoiceListItem->redraw();
        ;} {}
  }
  Function {update_voiceoscil()} {} {
    code {// this is identical to code in // updating
        int nvs = nvoice;
        int nvp = nvoice;

        voiceOscUpdate(synth, npart, kititem, nvoice, nvs, nvp);

        // we still need 'pars->' here :(
        oscil->changeParams(pars->VoicePar[nvs].POscil);

        osc->init(oscil,0,64-collect_readData(synth,0,ADDVOICE::control::voiceOscillatorPhase, npart, kititem, PART::engine::addVoice1 + nvoice),synth);

        if (collect_readData(synth,0,ADDVOICE::control::externalOscillator, npart, kititem, PART::engine::addVoice1 + nvoice) >= 0
            || collect_readData(synth,0,ADDVOICE::control::soundType, npart, kititem, PART::engine::addVoice1 + nvoice) > 0)

            voiceoscil->deactivate();
        else
            voiceoscil->activate();

        ;} {}
  }
  Function {update_noiselabel()} {} {
    code {//
        int extVoice = collect_readData(synth, 0, ADDVOICE::control::externalOscillator, npart, kititem, PART::engine::addVoice1 + nvoice);
        int extOsc = collect_readData(synth, 0, ADDVOICE::control::voiceOscillatorSource, npart, kititem, PART::engine::addVoice1 + nvoice);
        int type = collect_readData(synth, 0, ADDVOICE::control::soundType, npart, kititem, PART::engine::addVoice1 + nvoice);

        bool showNoise = true;
        if (extVoice >= 0)
        {
            char str[15];
            snprintf(str, sizeof(str), "V%d", extVoice + 1);
            noiselabel->copy_label(str);
            noiselabel->labelcolor(ext_voice);
        }
        else if (extOsc >= 0)
        {
            char str[15];
            snprintf(str, sizeof(str), "O%d", extOsc + 1);
            noiselabel->copy_label(str);
            noiselabel->labelcolor(ext_osc);
        }
        else
        {
            noiselabel->copy_label("N");
            switch (type)
            {
                case 1:
                    noiselabel->labelcolor(7);
                    break;
                case 2:
                    noiselabel->labelcolor(5);
                    break;
                case 3:
                    noiselabel->labelcolor(6);
                    break;
                default:
                    showNoise = false;
            }
        }
        if (showNoise)
            noiselabel->show();
        else
            noiselabel->hide();
        ;} {}
  }
  Function {update_modoscil()} {} {
    code {// this is identical to code in // updating
        int nvs = nvoice;
        int nvp = nvoice;

        voiceOscUpdate(synth, npart, kititem, nvoice, nvs, nvp);

        // we still need 'pars->' here :(
        oscilFM->changeParams(pars->VoicePar[nvs].POscil);

        modosc->init(oscilFM,0,64-collect_readData(synth,0,ADDVOICE::control::modulatorOscillatorPhase, npart, kititem, PART::engine::addVoice1 + nvoice),synth);

        if (collect_readData(synth,0,ADDVOICE::control::modulatorType, npart, kititem, PART::engine::addVoice1 + nvoice) == NONE
            || collect_readData(synth,0,ADDVOICE::control::externalModulator, npart, kititem, PART::engine::addVoice1 + nvoice) >= 0)

            modoscil->deactivate();
        else
            modoscil->activate();

        ;} {}
  }
  Function {update_modlabel()} {} {
    code {//
        if (collect_readData(synth,0,ADDVOICE::control::modulatorType, npart, kititem, PART::engine::addVoice1 + nvoice) == NONE)
        {
            modlabel->copy_label("OFF");
            modlabel->labelcolor(41);
            modlabel->deactivate();
            modlabel->show();
        }
        else
        {
            modlabel->activate();
            int voice = collect_readData(synth,0,ADDVOICE::control::externalModulator, npart, kititem, PART::engine::addVoice1 + nvoice);
            int osc = collect_readData(synth,0,ADDVOICE::control::modulatorOscillatorSource, npart, kititem, PART::engine::addVoice1 + nvoice);

            if (voice >= 0)
            {
                char str[15];
                snprintf(str, sizeof(str), "V%d", voice + 1);
                modlabel->copy_label(str);
                modlabel->labelcolor(ext_voice);
                modlabel->show();
            }
            else if (osc >= 0)
            {
                char str[15];
                snprintf(str, sizeof(str), "M%d", osc + 1);
                modlabel->copy_label(str);
                modlabel->labelcolor(ext_osc);
                modlabel->show();
            }
            else
            {
                modlabel->hide();
            }
        }
        ;} {}
  }
  Function {itemRtext(float dScale)} {} {
    code {//

        int size11 = int(11 * dScale);
        int size12 = int(12 * dScale);
        int size14 = int(14 * dScale);

        voiceresonanceenabled->labelsize(size11);
        voiceoscil->labelsize(size14);
        noiselabel->labelsize(size14);
        modoscil->labelsize(size14);
        modlabel->labelsize(size14);
        detunevalueoutput->textsize(size11);
        itemedit->labelsize(size12);
        voiceenabled->labelsize(size12);
        enabledpatch->size(34 * dScale, 18 * dScale);
        enabledpatch->labelsize(size14);
        ;} {}
  }
  Function {~ADvoicelistitem()} {} {
    code {//
        ADnoteVoiceListItem->hide();
        delete oscil;
        delete oscilFM;
        delete fft;
        ;} {}
  }
  decl {ADnoteParameters *pars;} {private local
  }
  decl {int nvoice;} {public local
  }
  decl {fft::Calc *fft;} {private local
  }
  decl {OscilGen *oscil;} {private local
  }
  decl {OscilGen *oscilFM;} {private local
  }
  decl {Oscilloscope *osc;} {private local
  }
  decl {Oscilloscope *modosc;} {private local
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {int npart;} {private local
  }
  decl {int kititem;} {private local
  }
}

class ADnoteUI {: {public PresetsUI_}
} {
  Function {make_window()} {private
  } {
    comment {globalrandompan MUST be after globalwidth} {in_source in_header
    }
    Fl_Window ADnoteGlobalParameters {
      label {ADsynth Global Parameters of the Instrument}
      callback {//
        saveWin(synth,  ADnoteGlobalParameters->w(),  ADnoteGlobalParameters->h(), ADnoteGlobalParameters->x(), ADnoteGlobalParameters->y(), false, "AddSynth");
        globalSeen = false;
        resui->resonancewindow->hide();
        o->hide();
        ;}
      xywh {447 196 580 405} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("AddSynth Global"), npart, TOPLEVEL::windowTitle, kititem)).c_str());}
      code1 {addDW = 580; addDH = 405;}
      code2 {o->size_range(addDW, addDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Group globalfreq {
        label FREQUENCY
        xywh {5 255 570 115} box THIN_UP_BOX labelfont 1 labelsize 12 labelcolor 64 align 17
      } {
        Fl_Group freqenv {
          label {Yoshimi : AddSynth Global - Frequency Envelope}
          xywh {10 295 205 70} box FLAT_BOX color 51 labelsize 12 align 144
          code0 {o->init(pars->GlobalPar.FreqEnvelope, npart, kititem, PART::engine::addSynth, 1);}
          class EnvelopeUI
        } {}
        Fl_Text_Display octavetext {
          label Octave
          xywh {493 275 50 8} box NO_BOX labelfont 3 labelsize 10 labelcolor 226
        }
        Fl_Counter octave {
          callback {//
            send_data(0, ADDSYNTH::control::octave, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip Octave xywh {495 275 47 13} type Simple selection_color 49 labelfont 3 labelsize 10 align 1 minimum -8 maximum 7 step 1 textfont 1 textsize 11 textcolor 64
          code0 {int k = collect_readData(synth,0,ADDSYNTH::control::octave, npart, kititem, PART::engine::addSynth) / 1024; if (k >= 8) k -= 16;}
          code2 {o->value(k);}
        }
        Fl_Counter coarsedet {
          label {Coarse det.}
          callback {//
            send_data(0, ADDSYNTH::control::coarseDetune, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Coarse Detune} xywh {495 346 77 13} selection_color 64 labelsize 10 labelcolor 64 align 5 minimum -64 maximum 63 step 1 textfont 1 textsize 11 textcolor 64
          code0 {int k = collect_readData(synth, 0, ADDSYNTH::control::coarseDetune, npart, kititem, PART::engine::addSynth);}
          code1 {o->value(k);}
          code2 {o->lstep(10);}
        }
        Fl_Group freqlfo {
          label {Frequency LFO}
          xywh {215 295 275 70} box FLAT_BOX color 47 labelsize 12 align 144
          code0 {o->init(synth, npart, kititem, PART::engine::addSynth, TOPLEVEL::insertType::frequency);}
          class LFOUI
        } {}
        Fl_Slider freq {
          callback {//
            o->selection_color(setSlider(o->value(),0));
            detunevalueoutput->do_callback();
            send_data(0, ADDSYNTH::control::detuneFrequency, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Fine Detune (cents)} xywh {57 275 433 13} type {Horz Knob} box THIN_DOWN_BOX labelcolor 64 minimum -8192 maximum 8191 step 1
          code0 {o->value(collect_readData(synth, 0, ADDSYNTH::detuneFrequency, npart, kititem, PART::engine::addSynth));}
          code1 {o->selection_color(setSlider(o->value(),0));}
          class mwheel_slider_rev
        }
        Fl_Choice detunetype {
          label {Detune Type}
          callback {//
            send_data(0, ADDSYNTH::control::detuneType, o->value() + 1, TOPLEVEL::type::Integer);
            ;}
          xywh {494 313 78 14} down_box BORDER_BOX selection_color 64 labelsize 10 labelcolor 64 align 5 textfont 1 textsize 11 textcolor 64
          code0 {o->add("L35 cents");o->add("L10cents");o->add("E100cents");o->add("E1200cents");}
          code1 {o->value(collect_readData(synth, 0, ADDSYNTH::detuneType, npart, kititem, PART::engine::addSynth)-1);}
        } {}
        Fl_Value_Output detunevalueoutput {
          label Detune
          callback {//
    o->value(getDetune(detunetype->value()+1,0, freq->value()+8192));
    ;}
          xywh {12 275 45 13} labelsize 10 labelcolor 64 align 5 minimum -5000 maximum 5000 textfont 1 textsize 10 textcolor 64
          code0 {o->step(0.01, 1);}
          code1 {o->value(getDetune(detunetype->value()+1, 0, freq->value()+8192));}
        }
        Fl_Dial relBwidth {
          label relBW
          callback {//
            o->selection_color(setKnob(o->value(),64));
            send_data(0, ADDSYNTH::control::relativeBandwidth, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Bandwidth - modify the relative fine detune of the voices} xywh {545 270 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::relativeBandwidth, npart, kititem, PART::engine::addSynth));}
          code1 {o->selection_color(setKnob(o->value(),64));}
          class WidgetPDial
        }
      }
      Fl_Box {} {
        xywh {10 7 275 68} box PLASTIC_UP_BOX color 223
      }
      Fl_Group amplitudegrp {
        xywh {5 5 285 250} box THIN_UP_FRAME labelfont 1 labelsize 12 labelcolor 64 align 17
      } {
        Fl_Dial globalvolume {
          label Volume
          callback {//
            o->selection_color(setKnob(o->value(),90));
            send_data(0, ADDSYNTH::control::volume, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip Volume xywh {30 23 35 35} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->setValueType(VC_InstrumentVolume);}
          code1 {o->value(collect_readData(synth,0,ADDSYNTH::control::volume, npart, kititem, PART::engine::addSynth));}
          code2 {o->selection_color(setKnob(o->value(),90));}
          class WidgetPDial
        }
        Fl_Dial vsns {
          label {Vel Sens}
          callback {//
            o->selection_color(setKnob(o->value(),64));
            send_data(0, ADDSYNTH::control::velocitySense, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Velocity Sensing Function - rightmost/max to disable} xywh {85 23 35 35} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::velocitySense, npart, kititem, PART::engine::addSynth));}
          code1 {o->selection_color(setKnob(o->value(),64));}
          code2 {o->setValueType(VC_AmpVelocitySense);}
          class WidgetPDial
        }
        Fl_Dial globalpan {
          label Pan
          callback {//
            o->selection_color(setKnob(o->value(),64));
            send_data(0, ADDSYNTH::control::panning, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Global panning} xywh {155 23 35 35} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 127 step 1
          code0 {o->setValueType(VC_PanningStd);}
          code1 {o->value(collect_readData(synth,0,ADDSYNTH::control::panning, npart, kititem, PART::engine::addSynth));}
          code2 {o->selection_color(setKnob(o->value(),64));}
          class WidgetPDial
        }
        Fl_Dial globalwidth {
          label Width
          callback {//
            o->selection_color(setKnob(o->value(),63));
            send_data(0, ADDSYNTH::control::randomWidth, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Global random width} xywh {235 23 35 35} box ROUND_UP_BOX labelsize 10 labelcolor 64 maximum 63 step 1 value 63
          code0 {o->setValueType(VC_PanningRandom);}
          code1 {o->value(collect_readData(synth,0,ADDSYNTH::control::randomWidth, npart, kititem, PART::engine::addSynth));}
          code2 {o->selection_color(setKnob(o->value(),63));}
          class WidgetPDial
        }
        Fl_Check_Button globalrandompan {
          label Rand
          callback {//
            int tmp = o->value();
            if (tmp == 0)
                globalwidth->deactivate();
            else
                globalwidth->activate();
            send_data(0, ADDSYNTH::control::enableRandomPan, tmp, TOPLEVEL::type::Integer);
            ;}
          tooltip {Enable random panning} xywh {205 32 15 15} down_box DOWN_BOX color 48 selection_color 64 labelsize 11 labelcolor 64 align 1
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::enableRandomPan, npart, kititem, PART::engine::addSynth));}
          code1 {if (o->value() == 0) globalwidth->deactivate(); else globalwidth->activate();}
          class Fl_Check_Button2
        }
        Fl_Dial depop {
          label {D.Pop}
          callback {//
            o->selection_color(setKnob(o->value(),20));
            send_data(0, ADDSYNTH::control::dePop, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Pop Suppression} xywh {130 227 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::dePop, npart, kititem, PART::engine::addSynth));}
          code1 {o->selection_color(setKnob(o->value(),20));}
          class WidgetPDial
        }
        Fl_Dial pstr {
          label {P.Str.}
          callback {//
            o->selection_color(setKnob(o->value(),0));
            send_data(0, ADDSYNTH::control::punchStrength, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Punch Strength} xywh {170 227 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::punchStrength, npart, kititem, PART::engine::addSynth));}
          code1 {o->selection_color(setKnob(o->value(),0));}
          class WidgetPDial
        }
        Fl_Dial pt {
          label {P.t.}
          callback {//
            o->selection_color(setKnob(o->value(),60));
            send_data(0, ADDSYNTH::control::punchDuration, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Punch Time (duration)} xywh {200 227 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::punchDuration, npart, kititem, PART::engine::addSynth));}
          code1 {o->selection_color(setKnob(o->value(),60));}
          class WidgetPDial
        }
        Fl_Dial pstc {
          label {P.Stc.}
          callback {//
            o->selection_color(setKnob(o->value(),64));
            send_data(0, ADDSYNTH::control::punchStretch, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Punch Stretch} xywh {230 227 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::punchStretch, npart, kititem, PART::engine::addSynth));}
          code1 {o->selection_color(setKnob(o->value(),64));}
          class WidgetPDial
        }
        Fl_Dial pvel {
          label {P.Vel.}
          callback {//
            o->selection_color(setKnob(o->value(),72));
            send_data(0, ADDSYNTH::control::punchVelocity, o->value(), TOPLEVEL::type::Integer);
            ;}
          tooltip {Punch Velocity Sensing} xywh {260 227 25 25} box ROUND_UP_BOX labelsize 10 labelcolor 64 align 1 maximum 127 step 1
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::punchVelocity, npart, kititem, PART::engine::addSynth));}
          code1 {o->selection_color(setKnob(o->value(),72));}
          class WidgetPDial
        }
        Fl_Group ampenv {
          label {Yoshimi : AddSynth Global - Amplitude Envelope}
          xywh {10 75 275 70} box FLAT_BOX color 51 labelsize 12 align 144
          code0 {o->init(pars->GlobalPar.AmpEnvelope, npart, kititem, PART::engine::addSynth, 0);}
          class EnvelopeUI
        } {}
        Fl_Group amplfo {
          label {Amplitude LFO}
          xywh {10 145 275 70} box FLAT_BOX color 47 labelsize 12 align 144
          code0 {o->init(synth, npart, kititem, PART::engine::addSynth, TOPLEVEL::insertType::amplitude);}
          class LFOUI
        } {}
        Fl_Check_Button rndgrp {
          label {Rnd Grp}
          callback {//
            send_data(0, ADDSYNTH::control::randomGroup, o->value(), TOPLEVEL::type::Integer);
        ;}
          tooltip {Disable individual Harmonic Amplitude randomisation for voices that use the same oscillator} xywh {8 234 63 18} down_box DOWN_BOX selection_color 64 labelsize 11 labelcolor 64
          code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::randomGroup, npart, kititem, PART::engine::addSynth));}
          class Fl_Check_Button2
        }
        Fl_Box {} {
          xywh {135 24 4 44} box THIN_DOWN_FRAME
        }
        Fl_Box amplitudelabel {
          label AMPLITUDE
          xywh {128 12 35 8} labelfont 1 labelsize 12 labelcolor 64
        }
      }
      Fl_Group filtergrp {
        label FILTER
        xywh {290 5 285 250} box THIN_UP_BOX labelfont 1 labelsize 12 labelcolor 64 align 17
      } {
        Fl_Group filterenv {
          label {Yoshimi : AddSynth Global - Filter Envelope}
          xywh {295 110 275 70} box FLAT_BOX color 51 labelsize 12 align 144
          code0 {o->init(pars->GlobalPar.FilterEnvelope, npart, kititem, PART::engine::addSynth, 2);}
          class EnvelopeUI
        } {}
        Fl_Group filterlfo {
          label {Filter LFO}
          xywh {295 180 275 70} box FLAT_BOX color 47 labelsize 12 align 144
          code0 {o->init(synth, npart, kititem, PART::engine::addSynth, TOPLEVEL::insertType::filter);}
          class LFOUI
        } {}
        Fl_Group filterui {
          label {Yoshimi : AddSynth Global - Filter}
          xywh {295 35 275 75} box FLAT_BOX color 50 labelsize 12 align 144
          code0 {o->init(pars->GlobalPar.GlobalFilter, &pars->GlobalPar.PFilterVelocityScale, &pars->GlobalPar.PFilterVelocityScaleFunction, npart, kititem, PART::engine::addSynth);}
          class FilterUI
        } {}
      }
      Fl_Check_Button stereo {
        label { Stereo}
        callback {//
            send_data(0, ADDSYNTH::control::stereo, o->value(), TOPLEVEL::type::Integer);
            ;}
        xywh {8 220 61 15} down_box DOWN_BOX selection_color 64 labelfont 3 labelsize 11 labelcolor 226
        code0 {o->value(collect_readData(synth,0,ADDSYNTH::control::stereo, npart, kititem, PART::engine::addSynth));}
        class Fl_Check_Button2
      }
      Fl_Button showvoicelist {
        label {Show Voice List}
        callback {//
            for (int i = 0; i < NUM_VOICES; ++i)
                voicelistitem[i]->refreshlist(i);
            int fetchW, fetchH, fetchX, fetchY, fetchO;
            loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "AddSynth-list");

            if (fetchW < listDW || fetchH < listDH)
            {
                fetchW = listDW;
                fetchH = listDH;
            }
            checkSane(fetchX, fetchY,fetchW, fetchH, listDW, listDH);
            ADnoteVoiceList->resize(fetchX, fetchY,fetchW, fetchH);
            lastlistW = 0;
            ADnoteVoiceList->show();
            listSeen = true;


            if (Fl::event_button() == 3)
                ADnoteGlobalParameters->hide();
            ;}
        tooltip {Right click: also close this} xywh {191 375 121 25} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 12 labelcolor 64
      }
      Fl_Button showvoicepars {
        label {Show Voice Parameters}
        callback {//
            set_voice(false);
            if ((Fl::event_button() == 3))
                ADnoteGlobalParameters->hide();
            ;}
        tooltip {Right click: also close this} xywh {5 375 180 25} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 12 labelcolor 64
      }
      Fl_Button globalclose {
        label {&Close}
        callback {//
            saveWin(synth,  ADnoteGlobalParameters->w(),  ADnoteGlobalParameters->h(), ADnoteGlobalParameters->x(), ADnoteGlobalParameters->y(), false, "AddSynth");
            globalSeen = false;
            resui->resonancewindow->hide();
            ADnoteGlobalParameters->hide();
            if (Fl::event_button() == 3)
            {
                if (synth->getGuiMaster()->partui->partKitOn)
                    synth->getGuiMaster()->partui->instrumentkitlist->show();
                else
                    synth->getGuiMaster()->partui->instrumenteditwindow->show();
            }
            ;}
        tooltip {Right click: also reopen previous} xywh {517 375 54 25} box THIN_UP_BOX color 196 labelfont 1 labelsize 12 labelcolor 64
      }
      Fl_Button resonance {
        label Resonance
        callback {//
            resui->resonancewindow->redraw();
            resui->Show();
            if ((Fl::event_button() == 3))
                ADnoteGlobalParameters->hide();
            ;}
        tooltip {Resonance. Right click: also close this} xywh {318 375 90 25} box GTK_THIN_UP_BOX color 198 labelfont 1 labelsize 12 labelcolor 64
      }
      Fl_Button globalcopy {
        label C
        callback {//
        synth->getGuiMaster()->getPresetsUi()->Ucopy(npart, kititem, PART::engine::addSynth);
        ;}
        xywh {455 380 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 197
      }
      Fl_Button globalpaste {
        label P
        callback {//
            synth->getGuiMaster()->getPresetsUi()->Upaste(npart, kititem, PART::engine::addSynth);
            ;}
        xywh {485 380 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 197
      }
    }
    Fl_Window ADnoteVoice {
      label {ADsynth Voice Parameters}
      callback {//
        saveWin(synth, o->w(), o->h(), o->x(), o->y(), false,"AddSynth-voice");
        o->hide();}
      xywh {460 96 805 610} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("AddSynth Voice"), npart, TOPLEVEL::windowTitle, kititem)).c_str());}
      code1 {voiceDW = int(760 * 9 / 10); voiceDH = int(610 * 9 / 10);}
      code2 {o->size_range(voiceDW, voiceDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Group advoice {
        xywh {0 0 809 615} box BORDER_BOX
        code0 {o->init(pars, npart, kititem, nvoice);}
        code1 {o->show();}
        class ADvoiceUI
      } {}
      Fl_Button Vclose {
        label Close
        callback {//
            ADnoteVoice->hide();
            saveWin(synth, ADnoteVoice->w(), ADnoteVoice->h(), ADnoteVoice->x(), ADnoteVoice->y(), false, "AddSynth-voice");
            voiceSeen = false;
            if (Fl::event_button() == 3)
            {
                if (fromVoiceList)
                    ADnoteVoiceList->show();
                else
                    ShowGlobal();
            }}
        tooltip {Right click: also reopen previous} xywh {695 575 90 25} box THIN_UP_BOX color 196 labelfont 1 labelsize 12 labelcolor 64
      }
      Fl_Button Vcopy {
        label C
        callback {//
            synth->getGuiMaster()->getPresetsUi()->Ucopy(npart, kititem, nvoice + PART::engine::addVoice1);}
        xywh {600 580 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 197
      }
      Fl_Button Vpaste {
        label P
        callback {//
            synth->getGuiMaster()->getPresetsUi()->Upaste(npart, kititem, nvoice + PART::engine::addVoice1);}
        xywh {630 580 25 15} box THIN_UP_BOX color 179 labelfont 1 labelsize 11 labelcolor 197
      }
      Fl_Button g1 {
        label 1
        callback {//
            setVoiceTabs(0, !o->value());}
        xywh {8 3 50 32} box PLASTIC_THIN_UP_BOX down_box PLASTIC_THIN_UP_BOX selection_color 223 labelfont 1 labelcolor 64
        code0 {o->value(1);}
      }
      Fl_Button g2 {
        label 2
        callback {//
            setVoiceTabs(1, !o->value());}
        xywh {60 3 50 32} box PLASTIC_THIN_UP_BOX down_box PLASTIC_THIN_UP_BOX selection_color 223 labelfont 1 labelcolor 64
        code0 {o->value(0);}
      }
      Fl_Button g3 {
        label 3
        callback {//
            setVoiceTabs(2, !o->value());}
        xywh {112 3 50 32} box PLASTIC_THIN_UP_BOX down_box PLASTIC_THIN_UP_BOX selection_color 223 labelfont 1 labelcolor 64
        code0 {o->value(0);}
      }
      Fl_Button g4 {
        label {4 }
        callback {//
            setVoiceTabs(3, !o->value());}
        xywh {164 3 50 32} box PLASTIC_THIN_UP_BOX down_box PLASTIC_THIN_UP_BOX selection_color 223 labelfont 1 labelcolor 64
        code0 {o->value(0);}
      }
      Fl_Button g5 {
        label 5
        callback {//
            setVoiceTabs(4, !o->value());}
        xywh {216 3 50 32} box PLASTIC_THIN_UP_BOX down_box PLASTIC_THIN_UP_BOX selection_color 223 labelfont 1 labelcolor 64
        code0 {o->value(0);}
      }
      Fl_Button g6 {
        label 6
        callback {//
            setVoiceTabs(5, !o->value());}
        xywh {268 3 50 32} box PLASTIC_THIN_UP_BOX down_box PLASTIC_THIN_UP_BOX selection_color 223 labelfont 1 labelcolor 64
        code0 {o->value(0);}
      }
      Fl_Button g7 {
        label 7
        callback {//
            setVoiceTabs(6, !o->value());}
        xywh {320 3 50 32} box PLASTIC_THIN_UP_BOX down_box PLASTIC_THIN_UP_BOX selection_color 223 labelfont 1 labelcolor 64
        code0 {o->value(0);}
      }
      Fl_Button g8 {
        label 8
        callback {//
            setVoiceTabs(7, !o->value());}
        xywh {372 3 50 32} box PLASTIC_THIN_UP_BOX down_box PLASTIC_THIN_UP_BOX selection_color 223 labelfont 1 labelcolor 64
        code0 {o->value(0);}
      }
      Fl_Group voiceTabBar {
        xywh {4 30 524 5} box PLASTIC_THIN_DOWN_BOX color 223
      } {}
    }
    Fl_Window ADnoteVoiceList {
      label {ADsynth Voices list}
      callback {//
          if (listSeen)
              saveWin(synth, o->w(), o->h(), o->x(), o->y(), false,"AddSynth-list");
          listSeen = false;
          o->hide();}
      xywh {101 233 705 260} type Double labelcolor 64 hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("AddSynth Voice List"), npart, TOPLEVEL::windowTitle, kititem)).c_str());}
      code1 {listDW = 705; listDH = 260;}
      code2 {o->size_range(listDW,listDH,0,0,0,0,1);}
    } {
      Fl_Text_Display listNo {
        label {No.}
        xywh {24 15 30 10} box NO_BOX selection_color 64 labelfont 1 labelsize 11 labelcolor 64 textcolor 64
      }
      Fl_Text_Display listVolume {
        label Volume
        xywh {230 15 30 10} box NO_BOX selection_color 64 labelfont 1 labelsize 11 labelcolor 64 textcolor 64
      }
      Fl_Text_Display listDetune {
        label Detune
        xywh {458 15 25 10} box NO_BOX selection_color 64 labelfont 1 labelsize 11 labelcolor 64 textcolor 64
      }
      Fl_Text_Display listPan {
        label Pan
        xywh {298 15 30 10} box NO_BOX selection_color 64 labelfont 1 labelsize 11 labelcolor 64 textcolor 64
      }
      Fl_Text_Display listVibrato {
        label {Vibrato Depth}
        xywh {618 15 30 10} box NO_BOX selection_color 64 labelfont 1 labelsize 11 labelcolor 64 textcolor 64
      }
      Fl_Text_Display listResonance {
        label Res
        xywh {329 15 25 10} box NO_BOX selection_color 64 labelfont 1 labelsize 11 labelcolor 64 textcolor 64
      }
      Fl_Button listClose {
        label Close
        callback {//
            ADnoteVoiceList->hide();
            listSeen = false;
            saveWin(synth, ADnoteVoiceList->w(), ADnoteVoiceList->h(), ADnoteVoiceList->x(), ADnoteVoiceList->y(), false, "AddSynth-list");

            if (Fl::event_button() == 3)
                ShowGlobal();
            ;}
        tooltip {Right click: also reopen previous} xywh {582 235 62 20} color 196 labelfont 1 labelsize 12 labelcolor 64
      }
      Fl_Group {} {
        xywh {5 15 695 214} box THIN_UP_BOX labelcolor 64
      } {
        Fl_Group {} {
          xywh {17 27 668 200}
          code0 {//
              for (int i = 0; i < NUM_VOICES; ++i)
              {
                  voicelistitem[i] = new ADvoicelistitem(4, 8, 620, 25, "");
                  voicelistitem[i]->init(pars, npart, kititem, i);
              }}
        } {}
      }
      Fl_Text_Display listWave {
        label Wave
        xywh {105 15 30 10} box NO_BOX labelfont 1 labelsize 11 labelcolor 64 textcolor 64
      }
      Fl_Text_Display listModulator {
        label Mod
        xywh {145 15 30 10} box NO_BOX labelfont 1 labelsize 11 labelcolor 64 textcolor 64
      }
    }
  }
  Function {setVoiceTabs(int num, bool edit = true)} {} {
    code {//
        g1->value(0);
        g2->value(0);
        g3->value(0);
        g4->value(0);
        g5->value(0);
        g6->value(0);
        g7->value(0);
        g8->value(0);
        switch (num)
        {
            case 0:
                g1->value(1);
                if (edit)
                    editVoice(0);
                break;
            case 1:
                g2->value(1);
                if (edit)
                    editVoice(1);
                break;
            case 2:
                g3->value(1);
                if (edit)
                    editVoice(2);
                break;
            case 3:
                g4->value(1);
                if (edit)
                    editVoice(3);
                break;
            case 4:
                g5->value(1);
                if (edit)
                    editVoice(4);
                break;
            case 5:
                g6->value(1);
                if (edit)
                    editVoice(5);
                break;
            case 6:
                g7->value(1);
                if (edit)
                    editVoice(6);
                break;
            case 7:
                g8->value(1);
                if (edit)
                    editVoice(7);
                break;
        }
    ;} {}
  }
  Function {setTabColour(int nvoice)} {} {
    code {//
        int set = voice_off;
        if (collect_readData(synth,0,ADDVOICE::control::enableVoice, npart, kititem, PART::engine::addVoice1 + nvoice))
            set = gen_text;

        switch (nvoice) // there should be a better way to do this
        {
            case 0:
                g1->labelcolor(set);
                break;
            case 1:
                g2->labelcolor(set);
                break;
            case 2:
                g3->labelcolor(set);
                break;
            case 3:
                g4->labelcolor(set);
                break;
            case 4:
                g5->labelcolor(set);
                break;
            case 5:
                g6->labelcolor(set);
                break;
            case 6:
                g7->labelcolor(set);
                break;
            case 7:
                g8->labelcolor(set);
                break;
        }
        ;} {}
  }
  Function {send_data(int action, int control, float value, int type)} {} {
    code {//
        type |= TOPLEVEL::type::Write;
        collect_writeData(synth, value, action, type, control, npart, kititem, PART::engine::addSynth);
        ;} {}
  }
  Function {returns_update(CommandBlock *getData)} {} {
    code {//
        float value = getData->data.value;
        unsigned char control = getData->data.control;
        bool val_bool = _SYS_::F2B(value);
        switch(control)
        {
            case ADDSYNTH::control::volume:
                globalvolume->value(value);
                globalvolume->selection_color(setKnob(value,90));
                break;

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

            case ADDSYNTH::control::panning:
                globalpan->value(value);
                globalpan->selection_color(setKnob(value,64));
                amplitudegrp->changed();
                break;

            case ADDSYNTH::control::enableRandomPan:
                globalrandompan->value(val_bool);
                if (val_bool)
                    globalwidth->activate();
                else
                    globalwidth->deactivate();
                amplitudegrp->changed();
                break;

            case ADDSYNTH::control::randomWidth:
                globalwidth->value(value);
                globalwidth->selection_color(setKnob(value,63));
                amplitudegrp->changed();
                break;

            case ADDSYNTH::control::detuneFrequency:
                freq->value(value);
                freq->selection_color(setSlider(value,0));
                detunevalueoutput->do_callback();
                break;

            case ADDSYNTH::control::octave:
                octave->value((int) value);
                break;

            case ADDSYNTH::control::detuneType:
                detunetype->value(int(value) -1);
                break;

            case ADDSYNTH::control::coarseDetune:
                coarsedet->value((int) value);
                break;

            case ADDSYNTH::control::relativeBandwidth:
                relBwidth->value(value);
                relBwidth->selection_color(setKnob(value,64));
                break;

            case ADDSYNTH::control::stereo:
                stereo->value(val_bool);
                break;

            case ADDSYNTH::control::randomGroup:
                rndgrp->value(val_bool);
                break;

            case ADDSYNTH::control::dePop:
                depop->value(value);
                depop->selection_color(setKnob(value,20));
                break;

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

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

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

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

        }
        ;} {}
  }
  Function {paste(CommandBlock *getData)} {} {
    code {//
        switch (getData->data.insert)
        {
            case TOPLEVEL::insert::resonanceGroup:
            {
                if (resui)
                    resui->refresh();
                break;
            }
        }
        ;} {}
  }
  Function {ADnoteUI(ADnoteParameters *parameters, int npart_, int kititem_)} {} {
    code {//
        synth = & parameters->getSynthEngine();
        pars = parameters;
        npart = npart_;
        kititem = kititem_;
        globalSeen = false;
        lastglobalW = 0;
        voiceSeen = false;
        lastvoiceW = 0;
        nvoice = 0;
        resui = new ResonanceUI(pars->GlobalPar.Reson, npart, kititem, PART::engine::addSynth);
        lastlistW = 0;
        listSeen = false;
        lastResuiW = 0;
        make_window();
        for (int i = 0; i < NUM_VOICES; ++i)
        {
            setTabColour(i);
        }
        ;} {}
  }
  Function {~ADnoteUI()} {return_type virtual
  } {
    code {//
        if(listSeen)
            saveWin(synth, ADnoteVoiceList->w(), ADnoteVoiceList->h(), ADnoteVoiceList->x(), ADnoteVoiceList->y(), listSeen, "AddSynth-list");
        ADnoteVoiceList->hide();
        listSeen = false;
        if (globalSeen)
            saveWin(synth,  ADnoteGlobalParameters->w(),  ADnoteGlobalParameters->h(), ADnoteGlobalParameters->x(), ADnoteGlobalParameters->y(), globalSeen, "AddSynth");
        ADnoteGlobalParameters->hide();
        globalSeen = false;
        if (voiceSeen)
            saveWin(synth, ADnoteVoice->w(), ADnoteVoice->h(), ADnoteVoice->x(), ADnoteVoice->y(), voiceSeen, "AddSynth-voice");
        voiceSeen = false;
        ADnoteVoice->hide();
        resui->resonancewindow->hide();
        delete ADnoteVoiceList;
        delete ADnoteGlobalParameters;
        delete ADnoteVoice;
        delete resui;
        ;} {}
  }
  Function {refresh()} {} {
    code {//
        globalvolume->value(collect_readData(synth, 0, ADDSYNTH::volume, npart, kititem, PART::engine::addSynth));
            globalvolume->selection_color(setKnob(globalvolume->value(),90));
        vsns->value(collect_readData(synth, 0, ADDSYNTH::velocitySense, npart, kititem, PART::engine::addSynth));
            vsns->selection_color(setKnob(vsns->value(),64));
        globalpan->value(collect_readData(synth, 0, ADDSYNTH::panning, npart, kititem, PART::engine::addSynth));
            globalpan->selection_color(setKnob(globalpan->value(),64));
        globalwidth->value(collect_readData(synth, 0, ADDSYNTH::randomWidth, npart, kititem, PART::engine::addSynth));
            globalwidth->selection_color(setKnob(globalwidth->value(),63));
        relBwidth->value(collect_readData(synth, 0, ADDSYNTH::relativeBandwidth, npart, kititem, PART::engine::addSynth));
            relBwidth->selection_color(setKnob(relBwidth->value(),64));
        stereo->value(collect_readData(synth, 0, ADDSYNTH::stereo, npart, kititem, PART::engine::addSynth));
        rndgrp->value(collect_readData(synth, 0, ADDSYNTH::randomGroup, npart, kititem, PART::engine::addSynth));

        pstr->value(collect_readData(synth, 0, ADDSYNTH::punchStrength, npart, kititem, PART::engine::addSynth));
            pstr->selection_color(setKnob(pstr->value(),0));
        depop->value(collect_readData(synth, 0, ADDSYNTH::dePop, npart, kititem, PART::engine::addSynth));
            depop->selection_color(setKnob(depop->value(),20));
        pt->value(collect_readData(synth, 0, ADDSYNTH::punchDuration, npart, kititem, PART::engine::addSynth));
            pt->selection_color(setKnob(pt->value(),60));
        pstc->value(collect_readData(synth, 0, ADDSYNTH::punchStretch, npart, kititem, PART::engine::addSynth));
            pstc->selection_color(setKnob(pstc->value(),64));
        pvel->value(collect_readData(synth, 0,ADDSYNTH::punchVelocity, npart, kititem, PART::engine::addSynth));
            pvel->selection_color(setKnob(pvel->value(),72));

        int detFreq = collect_readData(synth, 0, ADDSYNTH::detuneFrequency, npart, kititem, PART::engine::addSynth);
        freq->value(detFreq);
            freq->selection_color(setSlider(freq->value(), 0));

        int k = collect_readData(synth, 0, ADDSYNTH::coarseDetune, npart, kititem, PART::engine::addSynth) / 1024;
        if (k >= 8)
            k -= 16;
        octave->value(k);

        int detType = collect_readData(synth, 0, ADDSYNTH::detuneType, npart, kititem, PART::engine::addSynth);
        detunetype->value(detType - 1);
        k = collect_readData(synth,0,ADDSYNTH::control::octave, npart, kititem, PART::engine::addSynth);
        if (k >= 512)
            k -= 1024;
        coarsedet->value(k);
        detunevalueoutput->value(getDetune(detType, 0, detFreq + 8192));
        amplfo->refresh();
        freqlfo->refresh();
        filterlfo->refresh();

        ampenv->refresh();
        freqenv->refresh();
        filterenv->refresh();
        filterui->refresh();
        editVoice(nvoice);
        for (int i = 0; i < NUM_VOICES; ++i)
        {
            setTabColour(i);
            voicelistitem[i]->refreshlist(i);
        }
        resui->refresh();
        ;} {}
  }
  Function {ShowGlobal()} {} {
    code {//
        int fetchW, fetchH, fetchX, fetchY, fetchO;
        loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "AddSynth");
        if (fetchW < addDW || fetchH < addDH)
        {
            fetchW = addDW;
            fetchH = addDH;
        }
        checkSane(fetchX, fetchY, fetchW, fetchH, addDW, addDH);
        lastglobalW = 0;
        ADnoteGlobalParameters->resize(fetchX, fetchY, fetchW, fetchH);
        ADnoteGlobalParameters->show();
        globalSeen = true;
        ;} {}
  }
  Function {set_voice(bool type)} {} {
    code {//
        voicelistitem[nvoice]->refreshlist(nvoice);
        int fetchW, fetchH, fetchX, fetchY, fetchO;

        if (!voiceSeen)
        {
            loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "AddSynth-voice");
            if (fetchW < voiceDW || fetchH < voiceDH)
            {
                fetchW = voiceDW;
                fetchH = voiceDH;
            }
            checkSane(fetchX, fetchY, fetchW, fetchH, voiceDW, voiceDH);
            ADnoteVoice->resize(fetchX, fetchY, fetchW, fetchH);
        }

        ADnoteVoice->redraw();
        ADnoteVoice->show();
        lastvoiceW = 0;
        voiceSeen = true;
        fromVoiceList = type;
        ;} {}
  }
  Function {wincheck()} {} {
    code {//
        addRtext();
        addVoiceRtext();

        if (ADnoteVoiceList->visible())
            addVoiceListRtext();

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

        if (ampenv)
            ampenv->wincheck();
        if (filterenv)
            filterenv->wincheck();
        if (freqenv)
            freqenv->wincheck();
        ;} {}
  }
  Function {theme()} {} {
    code {//
        if(ADnoteGlobalParameters->visible())
        {
            lastglobalW = 0;
            addRtext();
        }
        if (ADnoteVoiceList->visible())
        {
            lastlistW = 0;
            addVoiceListRtext();
        }
        if (resui->resonancewindow->visible())
        {
            lastResuiW = 0;
            resui->resonanceRtext();
        }
        ampenv->theme();
        freqenv->theme();
        filterenv->theme();
        filterui->theme();

        lastvoiceW = 0;
        addVoiceRtext();
        advoice->voicetheme();
        ;} {}
  }
  Function {addRtext()} {} {
    code {//
        ampenv->wincheck();
        freqenv->wincheck();
        filterenv->wincheck();

        if (lastglobalW < 3)
        {
            ++lastglobalW;
            return; // in case it is  called before completely redrawn
        }

        if (lastglobalW == ADnoteGlobalParameters->w())
            return;
        lastglobalW = ADnoteGlobalParameters->w();

        float dScale = ADnoteGlobalParameters->w() / float(addDW);
        if (dScale < 0.2f)
            dScale = 0.2f;

        amplfo->lfoRtext(dScale);
        ampenv->envRtext(dScale);

        freqlfo->lfoRtext(dScale);
        freqenv->envRtext(dScale);

        filterlfo->lfoRtext(dScale);
        filterenv->envRtext(dScale);

        filterui->filterRtext(dScale);

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

        amplitudelabel->labelsize(size12);
        globalvolume->labelsize(size);
        vsns->labelsize(size);
        globalpan->labelsize(size);
        globalwidth->labelsize(size);
        globalrandompan->labelsize(size);
        depop->labelsize(size);
        pstr->labelsize(size);
        pt->labelsize(size);
        pstc->labelsize(size);
        pvel->labelsize(size);
        rndgrp->labelsize(size);

        stereo->labelsize(size11);

        filtergrp->labelsize(size12);

        globalfreq->labelsize(size12);
        detunevalueoutput->labelsize(size);
            detunevalueoutput->textsize(size);
        octavetext->labelsize(size);
            octave->textsize(size11);
            octave->redraw();
        relBwidth->labelsize(size);
        detunetype->labelsize(size);
            detunetype->textsize(size11);

        coarsedet->labelsize(size);
            coarsedet->textsize(size11);

        showvoicepars->labelsize(size12);
        showvoicelist->labelsize(size12);
        resonance->labelsize(size12);
        globalcopy->labelsize(size11);
        globalpaste->labelsize(size11);
        globalclose->labelsize(size11);

        ADnoteGlobalParameters->redraw();
        ;} {}
  }
  Function {addVoiceRtext()} {} {
    code {// this is just for the outer skin

        float dScale = ADnoteVoice->w() / float(voiceDW);
        if (dScale < 0.2f)
            dScale = 0.2f;

        advoice->voiceRtext(dScale); // must be entered (for waveform)

        if (!ADnoteVoice->visible())
            return;

        if (lastvoiceW < 2) // extra time to settle
        {
            ++lastvoiceW;
            return;
        }

        if (ADnoteVoice->w() == lastvoiceW)
            return;

        lastvoiceW = ADnoteVoice->w();

        Vclose->labelsize(int(12 * dScale));

        Vcopy->labelsize(int(11 * dScale));
        Vpaste->labelsize(int(11 * dScale));

        /*
        * scaling of tabs is in near tab size jumps so we
        * have to try to get the best overall size/position
        */
        int size = int((12 * dScale) + (1.85f * dScale * dScale));
        g1->labelsize(size);
        g2->labelsize(size);
        g3->labelsize(size);
        g4->labelsize(size);
        g5->labelsize(size);
        g6->labelsize(size);
        g7->labelsize(size);
        g8->labelsize(size);

        ADnoteVoice->redraw();
        ;} {}
  }
  Function {addVoiceListRtext()} {} {
    code {//
        if (lastlistW < 3)
        {
            ++lastlistW;
            return;
        }
        if (lastlistW == ADnoteVoiceList->w())
            return;

        lastlistW = ADnoteVoiceList->w();

        float dScale = ADnoteVoiceList->w() / float(listDW);
        if (dScale < 0.2f)
            dScale = 0.2f;

        for (int i = 0; i < NUM_VOICES; ++i)
        {
            voicelistitem[i]->resize(15 * dScale, (27 + (25 * i)) * dScale, 670 * dScale, 25 * dScale);
            voicelistitem[i]->itemRtext(dScale);
        }

        int size11 = int(11 * dScale);
        listNo->labelsize(size11);
        listVolume->labelsize(size11);
        listDetune->labelsize(size11);
        listPan->labelsize(size11);
        listVibrato->labelsize(size11);
        listResonance->labelsize(size11);
        listWave->labelsize(size11);
        listModulator->labelsize(size11);
        listClose->labelsize(int(14 * dScale));

        ADnoteVoiceList->redraw();
        ;} {}
  }
  Function {editVoice(int nvoice_)} {return_type void
  } {
    code {//
        nvoice = nvoice_;
        int adW = advoice->ADnoteVoiceParameters->w();
        int adH = advoice->ADnoteVoiceParameters->h();
        bool lastVoiceState = advoice->voiceonbutton->value();
        advoice->hide();
        ADnoteVoice->remove(advoice);
        delete advoice;

        advoice = new ADvoiceUI(0, 0, adW, adH);
        ADnoteVoice->add(advoice);
        advoice->init(pars, npart, kititem, nvoice);
        /*
        This is only needed to update the tab when a voice has been pasted,
        but duplicates the action every time a different voice is selected.
        Needs improvement!
        */
        if (advoice->voiceonbutton->value() != lastVoiceState)
        {
            setTabColour(nvoice);
        }
        voicelistitem[nvoice]->refreshlist(nvoice);
        advoice->ADnoteVoiceParameters->size(adW, adH);
        advoice->show();
        addVoiceRtext();
        ;} {}
  }
  decl {ADnoteParameters *pars;} {private local
  }
  decl {int addDW;} {private local
  }
  decl {int addDH;} {private local
  }
  decl {int lastglobalW;} {private local
  }
  decl {bool globalSeen;} {private local
  }
  decl {int voiceDW;} {private local
  }
  decl {int voiceDH;} {private local
  }
  decl {int lastvoiceW;} {private local
  }
  decl {bool voiceSeen;} {public local
  }
  decl {int listDW;} {private local
  }
  decl {int listDH;} {private local
  }
  decl {int lastlistW;} {private local
  }
  decl {bool listSeen;} {public local
  }
  decl {ResonanceUI *resui;} {public local
  }
  decl {int lastResuiW;} {private local
  }
  decl {int nvoice;} {public local
  }
  decl {ADvoicelistitem *voicelistitem[NUM_VOICES];} {public local
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {int npart;} {private local
  }
  decl {int kititem;} {private local
  }
  decl {bool fromVoiceList;} {public local
  }
}
