# data file for the Fltk User Interface Designer (fluid)
version 1.0308
header_name {.h}
code_name {.cpp}
decl {\#include <cmath>} {public local
}

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

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

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

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

This file is derivative of ZynAddSubFX original code.

} {selected in_source in_header
}

decl {\#include <iostream>} {public local
}

decl {\#include "Misc/Config.h"} {public local
}

decl {\#include "Misc/SynthEngine.h"} {private local
}

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

decl {\#include "UI/WidgetSpinner.h"} {public global
}

decl {\#include "Misc/Bank.h"} {private local
}

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

decl {\#include "Misc/FileMgrFuncs.h"} {private local
}

decl {\#include "Misc/NumericFuncs.h"} {private local
}

decl {\#include "Misc/FormatFuncs.h"} {private local
}

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

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

class ConfigUI {} {
  Function {isLV2()} {return_type bool} {
      code { return synth->getRuntime().isLV2; } {}
  }
  Function {make_window()} {} {
    Fl_Window configwindow {
      label {Yoshimi Settings}
      callback {close->do_callback();}
      xywh {905 61 390 330} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Settings"), UNUSED, TOPLEVEL::windowTitle)).c_str());}
      code1 {if (isLV2()){jackTab->deactivate();alsaTab->deactivate();}}
      code2 {confDW = o->w();confDH = o->h();}
      code3 {o->size_range(confDW, confDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Button Tab1 {
        label {&Main Settings}
        callback {mainTab->show();
patch1->show();
patch2->hide();
patch3->hide();
patch4->hide();
patch5->hide();
patch6->hide();
switchesTab->hide();
jackTab->hide();
alsaTab->hide();
midiTab->hide();
themeTab->hide();}
        xywh {5 5 91 22} box THIN_UP_FRAME selection_color 47 labelsize 12 labelcolor 64
      }
      Fl_Button Tab2 {
        label {&Switches}
        callback {switchesTab->show();
patch2->show();
patch1->hide();
patch3->hide();
patch4->hide();
patch5->hide();
patch6->hide();
mainTab->hide();
jackTab->hide();
alsaTab->hide();
midiTab->hide();
themeTab->hide();}
        xywh {98 5 66 22} box THIN_UP_FRAME selection_color 47 labelsize 12 labelcolor 64
      }
      Fl_Button Tab3 {
        label {&Jack}
        callback {jackTab->show();
patch3->show();
patch1->hide();
patch2->hide();
patch4->hide();
patch5->hide();
patch6->hide();
mainTab->hide();
switchesTab->hide();
alsaTab->hide();
midiTab->hide();
themeTab->hide();}
        xywh {166 5 38 22} box THIN_UP_FRAME selection_color 47 labelsize 12 labelcolor 64
      }
      Fl_Button Tab4 {
        label {&Alsa}
        callback {alsaTab->show();
patch4->show();
patch1->hide();
patch2->hide();
patch3->hide();
patch5->hide();
patch6->hide();
mainTab->hide();
switchesTab->hide();
jackTab->hide();
midiTab->hide();
themeTab->hide();}
        xywh {206 5 38 22} box THIN_UP_FRAME selection_color 47 labelsize 12 labelcolor 64
      }
      Fl_Button Tab5 {
        label {MIDI &CCs}
        callback {midiTab->show();
patch5->show();
patch1->hide();
patch2->hide();
patch3->hide();
patch4->hide();
patch6->hide();
mainTab->hide();
switchesTab->hide();
jackTab->hide();
alsaTab->hide();
themeTab->hide();}
        xywh {246 5 58 22} box THIN_UP_FRAME selection_color 47 labelsize 12 labelcolor 64
      }
      Fl_Button Tab6 {
        label {&Theme}
        callback {themeTab->show();
patch6->show();
patch1->hide();
patch2->hide();
patch3->hide();
patch4->hide();
patch5->hide();
mainTab->hide();
switchesTab->hide();
jackTab->hide();
alsaTab->hide();
midiTab->hide();
fillThemes();
;}
        xywh {305 5 58 22} box THIN_UP_FRAME selection_color 47 labelsize 12 labelcolor 64
      }
      Fl_Group configTabs {
        xywh {5 5 385 298} labelcolor 64
      } {
        Fl_Group mainTab {
          xywh {5 25 382 277} box THIN_UP_BOX labelsize 12 labelcolor 64 hide
        } {
          Fl_Choice buff_size {
            label {* Internal Buffer Size}
            callback {//
                        send_data(0, CONFIG::control::bufferSize, 16 << o->value(), TOPLEVEL::type::Integer);}
            tooltip {Number of samples. Smaller has more accurate internal timings but this may change some sounds.} xywh {245 34 105 20} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("16");o->add("32");o->add("64");o->add("128");o->add("256");o->add("512");o->add("1024");o->add("2048");o->add("4096");o->add("8192");}
            code1 {o->value(func::bitFindHigh(synth->getRuntime().buffersize) - 4);}
            code2 {//if (isLV2()) o->deactivate();}
          } {}
          Fl_Choice osc_size {
            label {* AddSynth Oscillator Size}
            callback {//
                        send_data(0, CONFIG::control::oscillatorSize, 256 << o->value(), TOPLEVEL::type::Integer);}
            tooltip {ADSynth Oscillator Size (samples)} xywh {245 58 105 20} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("256");o->add("512");o->add("1024");o->add("2048");o->add("4096");o->add("8192");o->add("16384");}
            code1 {o->value(func::bitFindHigh(synth->getRuntime().oscilsize) - 8);}
          } {}
          Fl_Choice pad_interpol {
            label {PadSynth Interpolation}
            callback {//
                        send_data(0, CONFIG::control::padSynthInterpolation, o->value(), TOPLEVEL::type::Integer);}
            xywh {245 82 105 20} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("Linear(fast)");o->add("Cubic(slow)");}
            code1 {o->value(synth->getRuntime().Interpolation);}
          } {}
          Fl_Choice handlePadSynthBuild {
            label {PadSynth Wavetable Build Mode}
            callback {//
                        send_data(0, CONFIG::control::handlePadSynthBuild, o->value(), TOPLEVEL::type::Integer);}
            tooltip {How to rebuild wavetable after changes: Trigger manually and mute part (legacy), build in background and activate when ready, or automatically trigger background build on each parameter change (expensive)} xywh {245 106 105 20} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("Muted");o->add("Background");o->add("Auto-Apply");}
            code1 {o->value(synth->getRuntime().handlePadSynthBuild);}
          } {}
          Fl_Choice v_keyboard {
            label {Virtual Keyboard Layout}
            callback {//
                        send_data(0, CONFIG::control::virtualKeyboardLayout, o->value(), TOPLEVEL::type::Integer);}
            xywh {245 130 105 20} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("QWERTY");o->add("Dvorak");o->add("QWERTZ");o->add("AZERTY");}
            code1 {o->value(synth->getRuntime().virKeybLayout);}
          } {}
          Fl_Choice reports {
            label {Send reports to:}
            callback {//
                        send_data(TOPLEVEL::action::forceUpdate, CONFIG::control::reportsDestination, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Some system errors always go to stdout} xywh {200 178 150 20} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("stdout");o->add("Console Window");}
            code1 {o->value(synth->getRuntime().toConsole);}
          } {}
          Fl_Counter logText {
            label {Console text Size}
            callback {//
                        send_data(0, CONFIG::control::logTextSize, o->value(), TOPLEVEL::type::Integer);
                        synth->getGuiMaster()->yoshiLog->setLogText(o->value());}
            tooltip {Console Font Size} xywh {260 202 90 20} type Simple labelsize 12 labelcolor 64 align 4 minimum 11 maximum 100 step 1 value 12 textfont 1 textsize 12 textcolor 64
            code1 {o->value(synth->getRuntime().consoleTextSize);}
            code2 {if (synth->getRuntime().toConsole) o->activate(); else o->deactivate();}
          }
          Fl_Counter compression {
            label {XML Compression Level}
            callback {//
                        send_data(0, CONFIG::control::XMLcompressionLevel, o->value(), TOPLEVEL::type::Integer);}
            tooltip {gzip compression level (0 - uncompressed)} xywh {260 154 90 20} type Simple labelsize 12 labelcolor 64 align 4 minimum 0 maximum 9 step 1 textfont 1 textsize 12 textcolor 64
            code0 {o->value(synth->getRuntime().gzipCompression);}
            code1 {if (current_ID != 0) o->hide();}
          }
          Fl_Choice instrument {
            label {Saved Instrument Format}
            callback {//
                        send_data(0, CONFIG::control::savedInstrumentFormat, o->value() + 1, TOPLEVEL::type::Integer);}
            tooltip {Yoshimi format includes Controllers and Humanise} xywh {200 226 150 20} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("Legacy");o->add("Yoshimi");o->add("Both");}
            code1 {o->value(synth->getRuntime().instrumentFormat - 1);}
          } {}
          Fl_Choice PanelLayout {
            label {Mixer Panel Layout}
            callback {//
            int style = 2 - int(o->value());
            synth->getGuiMaster()->changepanelstyle(style, true);}
            tooltip {Select single row or compact format} xywh {200 250 150 20} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("2 row x 8 entries");o->add("1 row x 16 entries");}
          } {}
          Fl_Box settingsNote {
            label {* Changing these settings requires a restart}
            xywh {38 276 306 17} labelfont 1 labelsize 12 labelcolor 64 align 128
            code0 {if (current_ID != 0) o->hide();}
          }
        }
        Fl_Group switchesTab {
          xywh {5 25 382 277} box THIN_UP_BOX labelsize 12 labelcolor 64 hide
        } {
          Fl_Check_Button bankHighlight {
            label {Enable Bank Highlight}
            callback {//
                        send_data(0, CONFIG::control::enableHighlight, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Show the last patch fetched from or saved to a bank} xywh {190 40 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().bankHighlight);}
            class Fl_Check_Button2
          }
          Fl_Check_Button nonFatal {
            label {Hide Non Fatal Errors}
            callback {//
                        send_data(0, CONFIG::control::hideNonFatalErrors, o->value(), TOPLEVEL::type::Integer);}
            xywh {190 60 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().hideErrors);}
            code1 {if (isLV2()) o->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Check_Button showSplash {
            label {Show Splash Screen}
            callback {//
                        send_data(0, CONFIG::control::showSplash, o->value(), TOPLEVEL::type::Integer);}
            xywh {190 80 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().showSplash);}
            code1 {if (current_ID != 0) o->hide(); else if (isLV2()) o->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Check_Button logXML {
            label {Log XML Headers}
            callback {//
                        send_data(0, CONFIG::control::logXMLheaders, o->value(), TOPLEVEL::type::Integer);}
            xywh {190 100 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().logXMLheaders);}
            code1 {if (isLV2()) o->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Check_Button logTimes {
            label {Log Load times}
            callback {//
                        send_data(0, CONFIG::control::logInstrumentLoadTimes, o->value(), TOPLEVEL::type::Integer);}
            xywh {190 120 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().showTimes);}
            class Fl_Check_Button2
          }
          Fl_Check_Button saveAllXML {
            label {Retain all Data}
            callback {//
                        send_data(0, CONFIG::control::saveAllXMLdata, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Include all data in XML files, even inactive settings} xywh {190 140 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().xmlmax);}
            class Fl_Check_Button2
          }
          Fl_Check_Button enableGUI {
            label {* Enable GUI}
            callback {//
                        int tmp = o->value();
                        int doit = true;
                        if (tmp == 0)
                            doit = choice(synth, "", "Yes", "No", "Are you sure you want to disable the GUI?\\nThis can only be restored via the command line.") > 1;
                        if (doit)
                            send_data(0, CONFIG::control::enableGUI, o->value(), TOPLEVEL::type::Integer);
                        else
                            o->value(1);}
            tooltip {Enable starting with this graphical interface} xywh {190 160 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().showGui);}
            code1 {if (current_ID != 0) o->hide(); else if (isLV2()) o->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Check_Button enableCLI {
            label {* Enable CLI}
            callback {//
                        send_data(0, CONFIG::control::enableCLI, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Enable starting with interactive command line interface} xywh {190 180 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().showCli);}
            code1 {if (current_ID != 0) o->hide(); else if (isLV2()) o->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Check_Button enableAuto {
            label {Enable Auto Instance}
            callback {//
                        send_data(0, CONFIG::control::enableAutoInstance, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Allow main instance to start all those open when last closed.} xywh {190 200 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().autoInstance);}
            code1 {if (current_ID != 0) o->hide(); else if (isLV2()) o->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Check_Button singleMaster {
            label {* Enable Single Master}
            callback {//
          send_data(0, CONFIG::control::enableSinglePath, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Redirect new start from desktop to create new instance instead.} xywh {190 220 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(fetchData(0, CONFIG::control::enableSinglePath, TOPLEVEL::section::config));}
            code1 {if (current_ID != 0) o->hide(); else if (isLV2()) o->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Check_Button setDefaultState {
            label {* Start With Default State}
            callback {//
                        send_data(0, CONFIG::control::defaultStateStart, o->value(), TOPLEVEL::type::Integer);}
            tooltip {If you change this you must re-save the default state
or when that loads it will revert to the previous value} xywh {190 250 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().loadDefaultState);}
            code1 {if (isLV2()) o->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Group {} {
            tooltip {When locked new entries will not not be added or change the list order} xywh {230 70 130 180} box EMBOSSED_FRAME
          } {
            Fl_Text_Display historyLocks {
              label {History Locks}
              xywh {278 110 50 1} box NO_BOX labelsize 12 labelcolor 64 align 129 textsize 12 textcolor 64
            }
            Fl_Check_Button H_instrument {
              label Instrument
              callback {//
                       send_data(TOPLEVEL::action::lowPrio, CONFIG::control::historyLock, o->value(), TOPLEVEL::type::Integer, TOPLEVEL::section::config,TOPLEVEL::XML::Instrument);}
              xywh {240 120 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 8
              code0 {o->value(_SYS_::F2B(fetchData(0, CONFIG::control::historyLock, TOPLEVEL::section::config, TOPLEVEL::XML::Instrument, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, TOPLEVEL::action::lowPrio)));}
              class Fl_Check_Button2
            }
            Fl_Check_Button H_patchset {
              label {Patch Set}
              callback {//
                       send_data(TOPLEVEL::action::lowPrio, CONFIG::control::historyLock, o->value(), TOPLEVEL::type::Integer, TOPLEVEL::section::config,TOPLEVEL::XML::Patch);}
              xywh {240 140 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 8
              code0 {o->value(_SYS_::F2B(fetchData(0, CONFIG::control::historyLock, TOPLEVEL::section::config, TOPLEVEL::XML::Patch, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, TOPLEVEL::action::lowPrio)));}
              class Fl_Check_Button2
            }
            Fl_Check_Button H_scale {
              label Scale
              callback {//
                       send_data(TOPLEVEL::action::lowPrio, CONFIG::control::historyLock, o->value(), TOPLEVEL::type::Integer, TOPLEVEL::section::config,TOPLEVEL::XML::Scale);}
              xywh {240 160 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 8
              code0 {o->value(_SYS_::F2B(fetchData(0, CONFIG::control::historyLock, TOPLEVEL::section::config, TOPLEVEL::XML::Scale, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, TOPLEVEL::action::lowPrio)));}
              class Fl_Check_Button2
            }
            Fl_Check_Button H_state {
              label State
              callback {//
                       send_data(TOPLEVEL::action::lowPrio, CONFIG::control::historyLock, o->value(), TOPLEVEL::type::Integer, TOPLEVEL::section::config,TOPLEVEL::XML::State);}
              xywh {240 180 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 8
              code0 {o->value(_SYS_::F2B(fetchData(0, CONFIG::control::historyLock, TOPLEVEL::section::config, TOPLEVEL::XML::State, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, TOPLEVEL::action::lowPrio)));}
              class Fl_Check_Button2
            }
            Fl_Check_Button H_vector {
              label Vector
              callback {//
                       send_data(TOPLEVEL::action::lowPrio, CONFIG::control::historyLock, o->value(), TOPLEVEL::type::Integer, TOPLEVEL::section::config,TOPLEVEL::XML::Vector);}
              xywh {240 200 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 8
              code0 {o->value(_SYS_::F2B(fetchData(0, CONFIG::control::historyLock, TOPLEVEL::section::config, TOPLEVEL::XML::Vector, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, TOPLEVEL::action::lowPrio)));}
              class Fl_Check_Button2
            }
            Fl_Check_Button H_mlearn {
              label {Midi Learn}
              callback {//
                       send_data(TOPLEVEL::action::lowPrio, CONFIG::control::historyLock, o->value(), TOPLEVEL::type::Integer, TOPLEVEL::section::config,TOPLEVEL::XML::MLearn);}
              xywh {240 220 27 25} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 8
              code0 {o->value(_SYS_::F2B(fetchData(0, CONFIG::control::historyLock, TOPLEVEL::section::config, TOPLEVEL::XML::MLearn, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, TOPLEVEL::action::lowPrio)));}
              class Fl_Check_Button2
            }
          }
          Fl_Box switchesNote {
            label {* Changing these settings requires a restart}
            xywh {38 276 306 17} labelfont 1 labelsize 12 labelcolor 64 align 128
          }
        }
        Fl_Group jackTab {
          xywh {5 25 382 277} box THIN_UP_BOX labelsize 12 labelcolor 64 hide
        } {
          Fl_Input jackSource {
            label {Jack MIDI Source}
            callback {//
                        string tmp = string(o->value());
                        send_data(TOPLEVEL::action::lowPrio, CONFIG::control::jackMidiSource, 0, TOPLEVEL::type::Integer, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(tmp));}
            tooltip {Device Jack tries to connect to for input.} xywh {195 62 120 22} labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->value(synth->getRuntime().jackMidiDevice.c_str());}
          }
          Fl_Check_Button jackMidi {
            label {Set as preferred MIDI}
            callback {//
                        send_data(TOPLEVEL::action::forceUpdate, CONFIG::control::jackPreferredMidi, o->value(), TOPLEVEL::type::Integer);}
            xywh {195 88 37 26} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {if (synth->getRuntime().midiEngine == jack_midi) o->value(1);}
            class Fl_Check_Button2
          }
          Fl_Input jackServer {
            label {Jack Server}
            callback {//
                        string tmp = string(o->value());
                        send_data(TOPLEVEL::action::lowPrio, CONFIG::control::jackServer, 0, TOPLEVEL::type::Integer, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(tmp));}
            tooltip {Name of the jack server to connect to - default, ...} xywh {195 182 120 22} labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->value(synth->getRuntime().jackServer.c_str());}
          }
          Fl_Check_Button jackAudio {
            label {Set as preferred audio}
            callback {//
                        send_data(TOPLEVEL::action::forceUpdate, CONFIG::control::jackPreferredAudio, o->value(), TOPLEVEL::type::Integer);}
            xywh {195 209 37 26} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {if (synth->getRuntime().audioEngine == jack_audio) o->value(1);}
            class Fl_Check_Button2
          }
          Fl_Check_Button connectJackAudio {
            label {Autoconnect audio}
            callback {//
                        send_data(0, CONFIG::control::jackAutoConnectAudio, o->value(), TOPLEVEL::type::Integer);}
            xywh {195 233 37 26} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().connectJackaudio);}
            class Fl_Check_Button2
          }
          Fl_Box jackNote {
            label {Changing settings requires a restart}
            xywh {60 276 267 17} labelfont 1 labelsize 12 labelcolor 64 align 128
          }
        }
        Fl_Group alsaTab {
          xywh {5 25 382 277} box THIN_UP_BOX labelsize 12 labelcolor 64 hide
        } {
          Fl_Choice alsaType {
            label {Alsa Connection Type}
            callback {if (o->value() == 0) // fixed
    alsaSource->activate();
else
     alsaSource->deactivate();


send_data (0, CONFIG::control::alsaMidiType, o->value(), TOPLEVEL::type::Integer, TOPLEVEL::section::config);}
            xywh {195 45 120 22} box DOWN_BOX down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("Fixed");o->add("Search");o->add("External");}
          } {}
          Fl_Input alsaSource {
            label {Alsa MIDI Source}
            callback {//
                        string tmp = string(o->value());
                        send_data(TOPLEVEL::action::lowPrio, CONFIG::control::alsaMidiSource, 0, TOPLEVEL::type::Integer, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(tmp));}
            tooltip {Device Alsa tries to connect to for input.} xywh {195 80 120 22} labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->value(synth->getRuntime().alsaMidiDevice.c_str());}
          }
          Fl_Check_Button alsaMidi {
            label {Set as preferred MIDI}
            callback {//
                        send_data(TOPLEVEL::action::forceUpdate, CONFIG::control::alsaPreferredMidi, o->value(), TOPLEVEL::type::Integer);}
            xywh {195 110 37 26} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {if (synth->getRuntime().midiEngine == alsa_midi) o->value(1);}
            class Fl_Check_Button2
          }
          Fl_Input alsaDevice {
            label {Alsa Audio Device}
            callback {//
                        string tmp = string(o->value());
                        send_data(TOPLEVEL::action::lowPrio, CONFIG::control::alsaAudioDevice, 0, TOPLEVEL::type::Integer, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(tmp));}
            tooltip {Alsa audio device - default, hw:0, ...} xywh {195 143 120 22} labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->value(synth->getRuntime().alsaAudioDevice.c_str());}
          }
          Fl_Choice alsaSamplerate {
            label {Sample Rate}
            callback {//
    send_data(0, CONFIG::control::alsaSampleRate, o->value(), TOPLEVEL::type::Integer);}
            xywh {195 199 80 22} down_box BORDER_BOX labelsize 12 labelcolor 64 textfont 1 textsize 12 textcolor 64
            code0 {o->add("192000");o->add("96000");o->add("48000");o->add("44100");}
            code1 {o->value(convertSrate(synth->getRuntime().samplerate));}
          } {}
          Fl_Check_Button alsaAudio {
            label {Set as preferred audio}
            callback {//
                        send_data(TOPLEVEL::action::forceUpdate, CONFIG::control::alsaPreferredAudio, o->value(), TOPLEVEL::type::Integer);}
            xywh {195 169 37 26} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {if (synth->getRuntime().audioEngine == alsa_audio) o->value(1);}
            class Fl_Check_Button2
          }
          Fl_Box alsaNote {
            label {Changing settings requires a restart}
            xywh {60 276 267 17} labelfont 1 labelsize 12 labelcolor 64 align 128
          }
        }
        Fl_Group midiTab {
          callback {//
                        EPCvalue = synth->getRuntime().midi_upper_voice_C;
                        if (EPCvalue >= 128)
                        {
                            EPCspinner->value(110);
                            EPCspinner->deactivate();
                        }
                        else
                        {
                            EPCspinner->value(EPCvalue);
                            EPCspinner->activate();
                        }
                        /*BankRootvalue = synth->getRuntime().midi_bank_root;
                        if (BankRootvalue >= 128)
                        {
                            BankRoot->value(0);
                            BankRoot->deactivate();
                        }
                        else
                        {
                            BankRoot->value(BankRootvalue);
                            BankRoot->activate();
                        }*/}
          tooltip {MIDI CC preferences} xywh {5 25 382 277} box THIN_UP_BOX labelsize 12 hide
          code0 {EPCvalue = synth->getRuntime().midi_upper_voice_C;}
          code1 {BankRootvalue = synth->getRuntime().midi_bank_root;}
        } {
          Fl_Choice bankrootchange {
            label {Bank Root Change}
            callback {//
                        int candidate;
                        switch (o->value())
                        {
                            case 0:
                                candidate = 32;
                                break;
                            case 1:
                                candidate = 0;
                                break;
                            default:
                                candidate = 128;
                                break;
                        }
                        string name = testCC(candidate, CONFIG::control::bankRootCC);
                        if (!name.empty())
                        {
                            o->value(oldBank);
                            o->redraw();
                            switch(oldBank)
                            {
                                case 0:
                                    candidate = 32;
                                    break;
                                case 1:
                                    candidate = 0;
                                    break;
                                default:
                                    candidate = 128;
                                    break;
                            }
                            alert(synth, "In use for " + name);
                        }
                        send_data(0, CONFIG::control::bankRootCC, candidate, TOPLEVEL::type::Integer);}
            tooltip {CC0 = msb, CC32 = lsb. If using LV2, the plugin needs to be reloaded in order to reflect the change in the MIDI program list.} xywh {234 57 53 18} down_box BORDER_BOX labelsize 12 labelcolor 64 align 132 textfont 1 textsize 12 textcolor 64
            code0 {o->add("LSB");o->add("MSB");o->add("Off");}
            code1 {int bankRoot = synth->getRuntime().midi_bank_root;}
            code2 {if (bankRoot == 32) o->value(0); else if (bankRoot == 0) o->value(1); else o->value(2);}
            code3 {oldBank = o->value();}
          } {}
          Fl_Choice bankchange {
            label {Bank Change}
            callback {//
                        int candidate;
                        switch (o->value())
                        {
                            case 0:
                                candidate = 32;
                                break;
                            case 1:
                                candidate = 0;
                                break;
                            default:
                                candidate = 128;
                                break;
                        }
                        string name = testCC(candidate, CONFIG::control::bankCC);
                        if (!name.empty())
                        {
                            o->value(oldBank);
                            o->redraw();
                            switch(oldBank)
                            {
                                case 0:
                                    candidate = 32;
                                    break;
                                case 1:
                                    candidate = 0;
                                    break;
                                default:
                                    candidate = 128;
                                    break;
                            }
                            alert(synth, "In use for " + name);
                        }
                        send_data(0, CONFIG::control::bankCC, candidate, TOPLEVEL::type::Integer);}
            tooltip {CC0 = msb, CC32 = lsb. If using LV2, the plugin needs to be reloaded in order to reflect the change in the MIDI program list.} xywh {235 80 53 18} down_box BORDER_BOX labelsize 12 labelcolor 64 align 132 textfont 1 textsize 12 textcolor 64
            code0 {o->add("LSB");o->add("MSB");o->add("Off");}
            code1 {if (synth->getRuntime().midi_bank_C == 32) o->value(0); else if (synth->getRuntime().midi_bank_C == 0) o->value(1); else o->value(2);}
            code2 {oldBank = o->value();}
          } {}
          Fl_Check_Button progenable {
            label {Enable Program Change}
            callback {//
                        send_data(0, CONFIG::control::enableProgramChange, o->value(), TOPLEVEL::type::Integer);}
            tooltip {MIDI program change enable/disable. If using LV2, the plugin needs to be reloaded in order to reflect the change in the MIDI program list.} xywh {234 110 18 18} down_box DOWN_BOX value 1 selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().enableProgChange);}
            class Fl_Check_Button2
          }
          Fl_Spinner EPCspinner {
            label {Extended Program Change CC}
            callback {//
                        Epend->show();}
            xywh {235 180 50 18} labelsize 12 labelcolor 64 minimum 0 maximum 119 value 110 textfont 1 textsize 12 textcolor 64
            code0 {EPCvalue = synth->getRuntime().midi_upper_voice_C;}
            code1 {if (EPCvalue < 128) o->value(EPCvalue); else o->value(110);}
            class WidgetSpinner
          }
          Fl_Button Epend {
            label Pending
            callback {//
                        int candidate = EPCspinner->value();
                        if (candidate == EPCvalue)
                        {
                            o->hide();
                            return;
                        }
                        string name = testCC(candidate, CONFIG::control::extendedProgramChangeCC);
                        if (!name.empty())
                        {
                            alert(synth, "In use for " + name);
                            if (EPCvalue < 128)
                            {
                                EPCspinner->value(EPCvalue);
                                EPCspinner->redraw();
                            }
                            return;
                        }
                        EPCvalue = candidate;
                        o->hide();
                        send_data(0, CONFIG::control::extendedProgramChangeCC, EPCvalue, TOPLEVEL::type::Integer);}
            tooltip {Click to set} xywh {300 180 70 20} box PLASTIC_UP_BOX color 90 labelsize 12 labelcolor 64 hide
          }
          Fl_Check_Button Epcheck {
            label {Enable Extended Program Change}
            callback {// for some weird reason this *must* be the last item in the group
                        if (o->value() == 0)
                        {
                            EPCspinner->value(110);
                            EPCspinner->deactivate();
                            Epend->hide();
                            send_data(0, CONFIG::control::extendedProgramChangeCC, 128, TOPLEVEL::type::Integer);
                        }
                        else
                        {
                            EPCspinner->activate();
                            Epend->show();
                            EPCspinner->value(110);
                            EPCvalue = 128;
                        }
                        EPCspinner->redraw();}
            xywh {234 160 18 18} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value((synth->getRuntime().midi_upper_voice_C < 128));}
            code1 {if (o->value() == 0) EPCspinner->deactivate();}
            class Fl_Check_Button2
          }
          Fl_Check_Button enableNRPN {
            label {Enable Incoming NRPNs}
            callback {//
                        send_data(0, CONFIG::control::enableNRPNs, o->value(), TOPLEVEL::type::Integer);}
            xywh {234 210 18 18} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().enable_NRPN);}
            class Fl_Check_Button2
          }
          Fl_Check_Button ignoreReset {
            label {Ignore Reset all CCs}
            callback {//
                        send_data(0, CONFIG::control::ignoreResetAllCCs, o->value(), TOPLEVEL::type::Integer);}
            xywh {234 230 18 18} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().ignoreResetCCs);}
            class Fl_Check_Button2
          }
          Fl_Check_Button midiMon {
            label {Log Incoming Events}
            callback {//
                        send_data(0, CONFIG::control::logIncomingCCs, o->value(), TOPLEVEL::type::Integer);}
            xywh {234 250 18 18} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().monitorCCin);}
            class Fl_Check_Button2
          }
          Fl_Check_Button midiLearned {
            label {Show Learn Editor}
            callback {//
                        send_data(0, CONFIG::control::showLearnEditor, o->value(), TOPLEVEL::type::Integer);}
            tooltip {Open the MIDI learn window for editing when a new CC has been learned} xywh {234 270 18 18} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64 align 4
            code0 {o->value(synth->getRuntime().showLearnedCC);}
            class Fl_Check_Button2
          }
        }
        Fl_Group themeTab {
          callback {//}
          xywh {5 25 382 277} box THIN_UP_BOX
        } {
          Fl_Browser theme_browser {
            label Themes
            callback {//
        if (!o->value())
            return;
        int result = o->value();
        if (result < 0)
            return;
        string line = string(o->text(result));
        if (line == "classic")
        {
            setClassicTable();
        }
        else
        {
            string fileName = file::localDir()+ "/themes/" + line + EXTEN::theme;
            int errLine = setUserTable(fileName);
            if (errLine != -1)
                themeError(errLine);

            //synth->getRuntime().remoteGuiTheme = file::localDir()+ "/themes/" + line + ".clr";
        }
        selectedTheme->copy_label(line.c_str());
        currentTheme = line;
        while (defaultTheme.at(defaultTheme.length() - 1) < '!') // tidy up
            defaultTheme.pop_back(); // deals with spurious trailing whitespace

       if (line == defaultTheme)
        {
            nuTheme->deactivate();
        }
        else
        {
            nuTheme->activate();
        }
        synth->getGuiMaster()->themeTrigger = true;
        //send_data(TOPLEVEL::action::muteAndLoop | TOPLEVEL::action::forceUpdate, MAIN::control::masterResetAndMlearn, 0, TOPLEVEL::type::Integer, TOPLEVEL::section::main);}
            xywh {40 50 190 215} type Select labelcolor 64 align 1 textcolor 64
          }
          Fl_Button themeImport {
            label {Import Theme}
            callback {//
        string filename = setfiler(synth,"", "", false, TOPLEVEL::XML::Themes);
        if (filename.empty())
        {
            //synth->getRuntime().Log("Can't find " + filename);
            return;
        }
        filename += EXTEN::theme;
        string newfile = file::localDir() + "/themes/" + file::findLeafName(filename) + EXTEN::theme;
        int result = file::copyFile(filename, newfile,1);
        if (result == 0)
        {
            fillThemes();
        }
        else
        {
           synth->getRuntime().Log("Failed to install " + filename);
        }}
            xywh {255 51 100 20} box GTK_THIN_UP_BOX color 198 labelsize 12 labelcolor 64
          }
          Fl_Button themeExport {
            label {Export Theme}
            callback {//
            string source = file::localDir() + "/themes/" + currentTheme + EXTEN::theme;
            string filename = setfiler(synth,"", currentTheme, true, TOPLEVEL::XML::Themes);
            size_t found = filename.find(file::localDir());
            if (found!=std::string::npos)
            {
                alert(synth, "Can't export on top of internal themes");
                return;
            }
            if (filename.empty())
            {
                //synth->getRuntime().Log("Nothing to export " + filename);
                return;
            }
            filename += EXTEN::theme;
            if (file::copyFile(source, filename, 0))
            {
                synth->getRuntime().Log("Failed to export " + filename);
            }
        ;}
            xywh {255 89 100 20} box GTK_THIN_UP_BOX color 198 labelsize 12 labelcolor 64
          }
          Fl_Box storedLabel {
            label {Default Theme}
            xywh {288 115 35 17} labelsize 12 labelcolor 64
          }
          Fl_Button storedTheme {
            label {Default Theme}
            xywh {255 132 100 20} box THIN_DOWN_BOX color 7 selection_color 64 labelsize 12 labelcolor 64 align 64
          }
          Fl_Group nuTheme {
            xywh {242 158 123 86} deactivate
          } {
            Fl_Box currentLabel {
              label {Current Theme}
              xywh {288 168 35 17} labelsize 12 labelcolor 64
            }
            Fl_Button setAsStored {
              label {Make Default}
              callback {//
                    string name = currentTheme + EXTEN::theme;
                    string file = file::localDir() + "/themes/ID/current.txt";
                    file::saveText(name, file);
                    defaultTheme = currentTheme;
                    storedTheme->copy_label(defaultTheme.c_str());
                    nuTheme->deactivate();
                    ;}
              xywh {255 220 100 20} box PLASTIC_THIN_UP_BOX color 228 labelsize 12 labelcolor 64
            }
            Fl_Button selectedTheme {
              label {Current Theme}
              xywh {255 187 100 20} box THIN_DOWN_BOX color 7 selection_color 7 labelsize 12 labelcolor 64 align 64
            }
          }
          Fl_Check_Button monochrome {
            label Monochrome
            callback {//
                monoChrome = o->value();
                if (currentTheme == "classic")
                {
                    setClassicTable();
                }
                else
                {
                    string fileName = file::localDir()+ "/themes/" + currentTheme + EXTEN::theme;
                    int errLine = setUserTable(fileName);
                    if (errLine != -1)
                        themeError(errLine);

                    //synth->getRuntime().remoteGuiTheme = file::localDir()+ "/themes/" + line + ".clr";
                }
                o->parent()->parent()->parent()->damage(1);
                o->parent()->parent()->parent()->redraw();
                synth->getGuiMaster()->themeTrigger = true;
                ;}
            xywh {256 250 102 20} down_box DOWN_BOX selection_color 64 labelsize 12 labelcolor 64
                code0 {o->value(0);}
          }
        }
        Fl_Box patch1 {
          xywh {6 24 89 3} box FLAT_BOX labelcolor 64
        }
        Fl_Box patch2 {
          xywh {98 24 65 3} box FLAT_BOX labelcolor 64
        }
        Fl_Box patch3 {
          xywh {166 24 37 3} box FLAT_BOX labelcolor 64
        }
        Fl_Box patch4 {
          xywh {206 24 37 3} box FLAT_BOX labelcolor 64
        }
        Fl_Box patch5 {
          xywh {246 24 57 3} box FLAT_BOX labelcolor 64
        }
        Fl_Box patch6 {
          xywh {305 24 57 3} box FLAT_BOX labelcolor 64
        }
      }
      Fl_Button close {
        label Close
        callback {//
         configwindow->hide();
         configSeen = false;
         saveWin(synth, configwindow->w(), configwindow->h(),configwindow->x(), configwindow->y(), false, "Config")}
        xywh {300 306 60 20} box THIN_UP_BOX color 196 labelsize 12 labelcolor 64
      }
    }
    Fl_Window presets {
      label Presets
      callback {pClose->do_callback();}
      xywh {5 437 460 270} type Double hide resizable
      code0 {o->copy_label(textMsgBuffer.fetch(collect_readData(synth, textMsgBuffer.push("Presets"), UNUSED, TOPLEVEL::windowTitle)).c_str());}
      code1 {preDW = o->w();preDH = o->h();}
      code2 {o->size_range(preDW, preDH, 0, 0, 0, 0, 1);}
    } {
      Fl_Browser presetbrowse {
        callback {//
                    activatebutton_presetdir(o->value() != 0);}
        tooltip {Click on an entry to make it the readable one.} xywh {5 5 450 200} type Hold labelsize 12 labelcolor 64 textsize 12 textcolor 64
      }
      Fl_Button addpreset {
        label {Add preset directory...}
        callback {//
                    string dirname = setfiler(synth,"Path for Presets dir", "", false, TOPLEVEL::XML::Dir);
                    if (dirname.length() < 3)
                        return;

                    send_data(TOPLEVEL::action::lowPrio | TOPLEVEL::action::forceUpdate,CONFIG::control::addPresetRootDir, 0, TOPLEVEL::type::Integer, UNUSED, UNUSED, UNUSED, UNUSED, UNUSED, textMsgBuffer.push(dirname));
                    if (presetbrowse->size() >= MAX_PRESET_DIRS)
                        o->deactivate();}
        xywh {10 220 85 35} box GTK_THIN_UP_BOX color 198 labelsize 12 labelcolor 64 align 128
      }
      Fl_Button removepresetbutton {
        label {Remove preset dir...}
        callback {//
                    if (presetbrowse->value() != 0)
                        send_data(TOPLEVEL::action::lowPrio | TOPLEVEL::action::forceUpdate,CONFIG::control::removePresetRootDir, presetbrowse->value() - 1, TOPLEVEL::type::Integer);}
        xywh {115 220 85 35} box PLASTIC_UP_BOX color 228 labelsize 12 labelcolor 64 align 128
        code0 {o->deactivate();}
      }
      Fl_Button makedefaultpresetbutton {
        label {Make Current}
        callback {//
                    send_data(TOPLEVEL::action::lowPrio | TOPLEVEL::action::forceUpdate,CONFIG::control::currentPresetRoot, presetbrowse->value() - 1, TOPLEVEL::type::Integer);}
        xywh {220 220 85 35} box PLASTIC_UP_BOX color 228 labelsize 12 labelcolor 64 align 128
        code0 {o->deactivate();}
      }
      Fl_Button pClose {
        label Close
        callback {//
        saveWin(synth, presets->w(), presets->h(), presets->x(), presets->y(), false, "Config-presets");
        presetsSeen = false;
        presets->hide();}
        xywh {362 220 85 35} box THIN_UP_BOX color 196 labelsize 12 labelcolor 64
      }
    }
  }
  Function {send_data(int action, int control, float value, int type, int part = UNUSED, int kit = UNUSED, int engine = UNUSED, int insert = UNUSED, int par = UNUSED, int miscmsg = UNUSED)} {} {
    code {//
            type |= TOPLEVEL::type::Write;
            if (part == UNUSED)
                part = TOPLEVEL::section::config;
            collect_writeData(synth, value, action, type, control, part, kit, engine, insert, par, UNUSED, miscmsg);} {}
  }
  Function {fetchData(float value, int control, int part, int kititem = UNUSED, int engine = UNUSED, int insert = UNUSED, int parameter = UNUSED, int offset = UNUSED, int miscmsg = UNUSED, int request = UNUSED)} {return_type float
  } {
    code {//
        return collect_readData(synth, value, control, part, kititem, engine, insert, parameter, offset, miscmsg, request);} {}
  }
  Function {returns_update(CommandBlock *getData)} {} {
    code {//
            int value_int = lrint(getData->data.value);
            bool wasFromHere = ((getData->data.source & TOPLEVEL::action::noAction) == TOPLEVEL::action::fromGUI);
            unsigned char control = getData->data.control;
            unsigned char kititem = getData->data.kit;
            unsigned char miscmsg = getData->data.miscmsg;
            string msg = textMsgBuffer.fetch(miscmsg);

            bool value_bool = value_int > 0;
            int tmp;
            string name;
            switch (control)
            {
                case CONFIG::control::oscillatorSize:
                    tmp = 0;
                    while (value_int > 256)
                    {
                        value_int = value_int >> 1;
                        ++ tmp; // count the bits for switch number
                    }
                    osc_size->value(tmp);
                    break;
                case CONFIG::control::bufferSize:
                    tmp = CONFIG::control::bufferSize;
                    while (value_int > 16)
                    {
                        value_int = value_int >> 1;
                        ++ tmp; // count the bits for switch number
                    }
                    buff_size->value(tmp - 1);
                    break;
                case CONFIG::control::padSynthInterpolation:
                    pad_interpol->value(value_int);
                    break;
                case CONFIG::control::virtualKeyboardLayout:
                    v_keyboard->value(value_int);
                    break;
                case CONFIG::control::XMLcompressionLevel:
                    compression->value(value_int);
                    break;
                case CONFIG::control::reportsDestination:
                    if(!wasFromHere)
                        reports->value(value_bool);
                    synth->getGuiMaster()->setLogging(value_bool);
                    if (value_bool)
                        logText->activate();
                    else
                        logText->deactivate();
                    break;
                case CONFIG::control::logTextSize:
                    logText->value(value_int);
                    //synth->getGuiMaster()->yoshiLog->logConsole->setLogText(value_int);
                    break;
                case CONFIG::control::savedInstrumentFormat:
                    instrument->value(value_int - 1);
                    break;

                case CONFIG::control::defaultStateStart:
                    setDefaultState->value(value_bool);
                    break;
                case CONFIG::control::handlePadSynthBuild:
                    handlePadSynthBuild->value(value_int);
                    break;
                case CONFIG::control::hideNonFatalErrors:
                    nonFatal->value(value_bool);
                    break;
                case CONFIG::control::showSplash:
                    showSplash->value(value_bool);
                    break;
                case CONFIG::control::logInstrumentLoadTimes:
                    logTimes->value(value_bool);
                    break;
                case CONFIG::control::logXMLheaders:
                    logXML->value(value_bool);
                    break;
                case CONFIG::control::saveAllXMLdata:
                    saveAllXML->value(value_bool);
                    break;
                case CONFIG::control::enableGUI:
                    enableGUI->value(value_bool);
                    break;
                case CONFIG::control::enableCLI:
                    enableCLI->value(value_bool);
                    break;
                case CONFIG::control::enableAutoInstance:
                    enableAuto->value(value_bool);
                    break;
                case CONFIG::control::enableSinglePath:
                    singleMaster->value(value_bool);
                    break;
                case CONFIG::control::enableHighlight:
                    bankHighlight->value(value_bool);
                    break;

                case CONFIG::control::historyLock:
                    if (!wasFromHere)
                    {
                        switch (kititem)
                        {
                            case TOPLEVEL::XML::Instrument:
                                H_instrument->value(value_int);
                                break;
                            case TOPLEVEL::XML::Patch:
                                H_patchset->value(value_int);
                                break;
                            case TOPLEVEL::XML::Scale:
                                H_scale->value(value_int);
                                break;
                            case TOPLEVEL::XML::State:
                                H_state->value(value_int);
                                break;
                            case TOPLEVEL::XML::Vector:
                                H_vector->value(value_int);
                                break;
                            case TOPLEVEL::XML::MLearn:
                                H_mlearn->value(value_int);
                                break;
                            default:
                                break;
                        }
                    }
                    break;

                case CONFIG::control::jackMidiSource:
                    jackSource->value(msg.c_str());
                    break;
                case CONFIG::control::jackPreferredMidi:
                    jackMidi->value(value_bool);
                    alsaMidi->value(!value_bool);
                    break;
                case CONFIG::control::jackServer:
                    jackServer->value(msg.c_str());
                    break;
                case CONFIG::control::jackPreferredAudio:
                    jackAudio->value(value_bool);
                    alsaAudio->value(!value_bool);
                    break;
                case CONFIG::control::jackAutoConnectAudio:
                    connectJackAudio->value(value_bool);
                    break;

                case CONFIG::control::alsaMidiSource:
                    alsaSource->value(msg.c_str());
                    break;
                case CONFIG::control::alsaPreferredMidi:
                    alsaMidi->value(value_bool);
                    jackMidi->value(!value_bool);
                    break;
                case CONFIG::control::alsaMidiType:
                    alsaType->value(value_int);
                    if (value_int == 0) // fixed
                        alsaSource->activate();
                    else
                        alsaSource->deactivate();
                    break;
                case CONFIG::control::alsaAudioDevice:
                    alsaDevice->value(msg.c_str());
                    break;
                case CONFIG::control::alsaPreferredAudio:
                    alsaAudio->value(value_bool);
                    jackAudio->value(!value_bool);
                    break;
                case CONFIG::control::alsaSampleRate:
                    alsaSamplerate->value(convertSrate(value_int));
                    break;
                case CONFIG::control::addPresetRootDir:
                case CONFIG::control::removePresetRootDir:
                case CONFIG::control::currentPresetRoot:
                {
                    if (msg.find("FAILED") == 1)
                    {
                        if (wasFromHere)
                            alert(synth, msg);
                    }
                    else
                        readpresetcfg();
                    break;
                }
                case CONFIG::control::bankRootCC:
                    switch (value_int)
                    {
                        case 0:
                            bankrootchange->value(1);
                            break;
                        case 32:
                            bankrootchange->value(0);
                            break;
                        default:
                            bankrootchange->value(2);
                            break;
                    }
                    break;

                case CONFIG::control::bankCC:
                    switch (value_int)
                    {
                        case 0:
                            bankchange->value(1);
                            break;
                        case 32:
                            bankchange->value(0);
                            break;
                        default:
                            bankchange->value(2);
                            break;
                    }
                    break;
                case CONFIG::control::enableProgramChange:
                    progenable->value(value_bool);
                    break;
                case CONFIG::control::extendedProgramChangeCC:
                    if (value_int > 119)
                    {
                        EPCspinner->value(110);
                        EPCspinner->deactivate();
                        Epcheck->value(0);
                    }
                    else
                    {
                        EPCspinner->value(value_int);
                        EPCspinner->activate();
                        Epcheck->value(1);
                    }
                    break;
                case CONFIG::control::ignoreResetAllCCs:
                    ignoreReset->value(value_bool);
                    break;
                case CONFIG::control::logIncomingCCs:
                    midiMon->value(value_bool);
                    break;
                case CONFIG::control::showLearnEditor:
                    midiLearned->value(value_bool);
                    break;
                case CONFIG::control::enableNRPNs:
                    enableNRPN->value(value_bool);
                    break;

                case CONFIG::control::saveCurrentConfig:
                    name = msg;
                    if (wasFromHere && name.find("FAILED") == 1)
                        alert(synth, name);
                    break;
    }} {}
  }
  Function {ConfigUI(SynthEngine *_synth, int _current_ID)} {} {
    code {//
            synth = _synth;
            current_ID = _current_ID;
            manageThemes();
            make_window();
            readpresetcfg();
            configSeen = false;
            presetsSeen = false;
            selectedRootID = -1;
            Tab1->do_callback();
            string themeDir = file::localDir() + "/themes/";
            string name = file::loadText(themeDir + "ID/current.txt");
            string fullName = themeDir + name;

            while (fullName.at(fullName.length() - 1) < '!') // tidy up
            fullName.pop_back(); // deals with spurious trailing whitespace

            themeTime = file::isRegularFile(fullName);
            if (themeTime == 0)
            {
                defaultTheme = "classic";
                currentTheme = defaultTheme;
                themeDirTime = 1;
            }
            else
            {
                size_t pos = name.rfind('.');
                defaultTheme = name.substr(0, pos);
                currentTheme = defaultTheme;
            }
            monoChrome = 0;
            themeDirTime = 1;} {}
  }
  Function {~ConfigUI()} {} {
    code {//
        if (presetsSeen)
            saveWin(synth, presets->w(), presets->h(), presets->x(), presets->y(), true, "Config-presets");
        presets->hide();
        delete presets;

        if (configSeen)
            saveWin(synth, configwindow->w(), configwindow->h(),configwindow->x(), configwindow->y(), true, "Config");
        configwindow->hide();
        delete configwindow;} {}
  }
  Function {halfSecTimer()} {} {
    code {//
        if (themeTab->visible())
        {
            string themeDir = file::localDir() + "/themes/";
            bool changed = false;
            if (currentTheme != "classic")
            {
                string fileName = themeDir + currentTheme +".clr";
                size_t testTime = file::isRegularFile(fileName);
                if (testTime != themeTime)
                {
                    //std::cout << "test " << testTime << "  theme " << themeTime << std::endl;
                    setUserTable(fileName);
                    synth->getGuiMaster()->theme();
                    changed = true;
                    themeTime = testTime;
                }
            }
            if (!changed) // we don't want to rebuild the menu if it's just a theme change
            {
                size_t testDirTime = file::isDirectory(themeDir);
                if (testDirTime != themeDirTime)
                {
                    //std::cout << "test " << testDirTime << "  theme dir " << themeDirTime << std::endl;
                    fillThemes();
                    themeDirTime = testDirTime;
                }
            }
        }} {}
  }
  Function {fillNative()} {} {
    code {//
        for (int i = 0; i < 256; ++i)
        {
            getNativeLine(i);
        }
        ;} {}
  }
  Function {getNativeLine(int line)} {} {
    code {//
        unsigned char rt, gt, bt;
        Fl::get_color(line, rt, gt, bt);
        nativeTable[line] = int(rt);
        nativeTable[line + 256] = int(gt);
        nativeTable[line + 512] = int(bt);
        ;} {}
  }
  Function {fillThemes()} {return_type int
  } {
    code {//
        string sourceDir = file::localDir() + "/themes/";
        std::list<string> themes;
        int count = file::listDir(&themes, sourceDir);
        if (count == 0)
            return 0;
        themes.sort();
        theme_browser->clear();
        std::list<string>::iterator itr = themes.begin();
        while (itr != themes.end())
        {
            string text = file::findExtension(*itr);
            if (text == ".clr")
            {
                text = *itr;
                size_t pos = text.find(".clr");
                text = text.substr(0, pos);
                theme_browser->add(text.c_str());
            }
            ++itr;
        }
        storedTheme->copy_label(defaultTheme.c_str());
        selectedTheme->copy_label(currentTheme.c_str());
        return count;
        ;} {}
  }
  Function {manageThemes()} {} {
    code {//
        static bool seen = false;
        if (!seen)
        {
            fillNative();
            seen = true;

            if (!file::isRegularFile(file::localDir() + "/themes/demo.clr"))
            {
                string demo = file::findExampleFile("themes/demo.clr");
                if (!demo.empty())
                    file::copyFile(demo, file::localDir() + "/themes/demo.clr", 1);
            }

        }

       /*
        * Note: Fluid screws up text with control values and @
        * so we enter them as char(n)
        */

      // prints the native colour table
      /*unsigned char RR,GG,BB;
      for (int i = 0; i < 256; ++i)
      {
          Fl::get_color(i, RR, GG, BB);
          std::cout << '"'<< int(RR) << "," << int(GG) << "," << int(BB) << '"' << "," << std::endl;
      }*/

      int colour2find = 0;
      if (colour2find > 0) // for testing
      {
          unsigned char rt,gt,bt;
          Fl::get_color(colour2find, rt, gt, bt);
          std::cout << "r " << int(rt) << " g " << int(gt) << " b " << int(bt) << std::endl;
      }
      if (!checkVersions())
      {
          setClassicTable();
          themeTime = 1;
          return;
      }

      if (findRemote()) // externally CLI sourced
          return;

      string themeDir = file::localDir() + "/themes/";

      string selectedTheme = file::loadText(themeDir+"ID/current.txt");
      while (selectedTheme.at(selectedTheme.length() - 1) < '!') // tidy up
          selectedTheme.pop_back(); // deals with spurious trailing whitespace

      if (selectedTheme != "classic.clr")
      {
          string fileName = themeDir+ selectedTheme;
          themeTime = file::isRegularFile(fileName);
          if (themeTime != 0)
          {
                int errLine = setUserTable(fileName);
                if (errLine != -1)
                    themeError(errLine);
                return;
          }
      }
      setClassicTable();

      //Fl::set_color(196, 127, 145, 191); // for testing

      ;} {}
  }
  Function {checkVersions()} {return_type bool
  } {
    code {//
        string themeDir = file::localDir() + "/themes/";
        file::createDir(themeDir);
        file::createDir(themeDir + "ID");
        int build_ID = synth->getRuntime().build_ID;
        int theme_ID = 0;
        string defaultName = "classic.clr";
        bool ok = true;
        if (!file::isRegularFile(themeDir + defaultName))
            ok = false;
        if (ok)
        {
            if(!file::isRegularFile(themeDir +"ID/version"))
                ok = false;
            else
                theme_ID = func::string2int(file::loadText(themeDir + "ID/version"));
        }
        if (ok)
        {
            if (build_ID > theme_ID)
                ok = false;
        }
        if (ok)
        {
            string filename = themeDir +"ID/" + "current.txt";
            if(!file::isRegularFile(filename))
                ok = false;
        }

        if (ok)
            return true;

        file::saveText(to_string(build_ID), themeDir + "ID/version");
        string res = themeDir + "ID/version";
        //std::cout << "version>" << res << std::endl;
        string colourText;
        int info = 0;
        do {
            colourText += (colourPreamble[info] + char(10));
            ++info;
            if (info > 100)
            {
                std::cout << "failed preamble" << std::endl;
            }
        } while(colourPreamble[info] != "END");

        int data = 0;
        do {
            colourText += (colourData[data] + char(10));
            ++data;
            if (data > 200)
            {
                std::cout << "failed data" << std::endl;
            }
        }  while(colourData[data] != "END");

        file::saveText(defaultName + char(10), themeDir + "ID/current.txt");
        file::saveText(colourText, themeDir + defaultName);
        return false;} {}
  }
  Function {findRemote()} {return_type bool
  } {
    code {//
       bool ok = true;
       string selectedTheme = synth->getRuntime().remoteGuiTheme;
       if ((!file::isRegularFile(selectedTheme)))
       {
           return false;
       }
       if (!selectedTheme.empty())
       {
           int errLine = setUserTable(selectedTheme);
           if (errLine != -1)
           {
               themeError(errLine);
               ok = false;
           }
       }
       return ok;} {}
  }
  Function {setNativeTable()} {} {
    code {//
        for (int i = 0; i < 256; ++i)
            setNativeLine(i);
        ;} {}
  }
  Function {setNativeLine(int line)} {} {
    code {//;
        unsigned char R, G, B;
        R = nativeTable[line];
        G = nativeTable[line + 256];
        B = nativeTable[line + 512];
        Fl::set_color(line, R, G, B);
        ;} {}
  }
  Function {setClassicTable()} {return_type bool
  } {
    code {//
        setGreyScale(colourData[0]);
        for (int lineCount = 0; lineCount < COLOURLIST; ++ lineCount)
        {
            if (setColourLine(colourData[lineCount + 1], lineCount) != 0) // we don't want the greyscale line!
            {
                synth->getRuntime().Log("Corrupted Classic theme data.");
                return false;
            }
        }
        return true;} {}
  }
  Function {setUserTable(string table)} {return_type int
  } {
    code {//
        string colourText = file::loadText(table);
        themeTime = file::isRegularFile(table);
        std::size_t nextPos;

        // strip out preamble text
        string text = "";
        int lineCount = 0;
        int totalCount = 1;
        while (text.substr(0, 7) != "-------")
        {
            nextPos = colourText.find(char(10));
            if (nextPos == std::string::npos)
            {
                return -2;
            }

            text = colourText.substr(0, nextPos);
            colourText = colourText.substr(nextPos + 1);
            ++lineCount;
            ++totalCount;
        }
        if (text.substr(0, 7) != "-------")
        {
            return -2;
        }

        int dataStart = totalCount;
        if (colourText.at(0) == char(64)) // all native colour table
        {
            setNativeTable();
            return -1; // doesn't matter if there's no more to the file
        }

        nextPos = colourText.find(char(10));
        int scaletype = setGreyScale(colourText.substr(0, nextPos));
        if (scaletype == 0)
        {
            return totalCount;
        }

        ++totalCount; // allow for greyscale line
        colourText = colourText.substr(nextPos + 1);
        lineCount = 0;
        int test = 0;
        do {
            if ((totalCount - dataStart) > COLOURLIST && colourText.substr(0, 7) != "=======")
            {
                return -3; // missing marker
            }

            nextPos = colourText.find(char(10));
            if (nextPos == std::string::npos)
            {
                return -4; // too short
            }

            text = colourText.substr(0, nextPos);
            if (text.at(0) == char(64))
            {
                int actual_line = colourNumbers[lineCount];
                setNativeLine(actual_line);
            }
            else
            {
                string lineText = colourText.substr(0, nextPos);
                if (lineText.find("RESERVED") != std::string::npos)
                {
                    // use actual default value, stepping over greyscale line
                    test = setColourLine(colourData[lineCount + 1], lineCount);
                }
                else
                    test = setColourLine(lineText, lineCount);
            }

            if (test == -1)
            {
                if (colourText.substr(0, 7) == "-------")
                    return -4; // old style too short
                return totalCount;
            }

            ++lineCount;
            ++totalCount;
            colourText = colourText.substr(nextPos + 1);
        } while(colourText.substr(0, 7) != "=======");

        //std::cout << "lines " << lineCount << std::endl;

        if ((totalCount - dataStart) <= COLOURLIST)
        {
            return -4; // too short
        }
        return -1;
        ;} {}
  }
  Function {setGreyTint(string text, float &R, float &G, float &B)} {return_type bool
  } {
    code {//
        float r,g,b;
        if (!isdigit(text.at(0)))
        {
            return false;
        }
        size_t nextPos = text.find(",");
        r = string2int(text.substr(0, nextPos));
        if (r > 255 || r < 0)
            return false;
        r = (r-127) / 511.0f;

        text = text.substr(nextPos + 1);
        nextPos = text.find(",");
        if (nextPos == std::string::npos)
        {
            return false;
        }
        if (!isdigit(text.at(0)))
        {
            return false;
        }
        g = string2int(text.substr(0, nextPos));
        if (g > 255 || g < 0)
            return false;
        g = (g-127) / 511.0f;

        text = text.substr(nextPos + 1);
        nextPos = text.find(",");
        if (nextPos == std::string::npos)
        {
            return false;
        }
        if (!isdigit(text.at(0)))
        {
            return false;
        }
        b = string2int(text.substr(0, nextPos));
        if (b > 255 || b < 0)
            return false;
        b = (b-127) / 511.0;

        float offset = (r+g+b) / 3;
        R = 1+r - offset;
        if (R < 0)
            R = 0;
        G = 1+g - offset;
        if (G < 0)
            G = 0;
        B = 1+b - offset;
        if (B < 0)
            B = 0;
        return true;} {}
  }
  Function {setGreyScale(string text)} {return_type int
  } {
    code {//
        size_t nextPos = text.find(",");
        if (nextPos == std::string::npos)
        {
            return 0;
        }

        if (!isdigit(text.at(0)))
        {
            return 0;
        }

        int min = string2int(text.substr(0, nextPos));
        if (min < 0 || min > 255)
        {
            return 0;
        }

        text = text.substr(nextPos + 1);
        nextPos = text.find(",");
        if (nextPos == std::string::npos)
        {
            return 0;
        }

        if (!isdigit(text.at(0)))
        {
            return 0;
        }

        int max = string2int(text.substr(0, nextPos));

        if (max < 0 || max > 255)
        {
            return 0;
        }

        if (min == 127 && max == 127)
            return 2; // this sets a totally grey colourmap
                      // useful for testing contrast

        float Rmult, Gmult, Bmult = 1;
        bool useTint = false;
        if(!monoChrome)
        {
            text = text.substr(nextPos + 1);
            if(isdigit(text.at(0)))
            {
                if (setGreyTint(text,Rmult,Gmult,Bmult))
                    useTint = true;
                else
                    synth->getRuntime().Log("Invalid grey tint");
            }
        }

        float greyRange;
        if (max > min)
        {
           greyRange =  (max - min) / 23;
           for (int i = 0; i < 24; ++i)
           {
                int diff = (min + int(i * greyRange)) + 1;
                if (useTint)
                {
                    int r = diff*Rmult;
                    if (r > 255)
                        r = 255;
                    else if (r < 0)
                        r = 0;
                    int g = diff*Gmult;
                    if (g > 255)
                        g = 255;
                    else if (g < 0)
                        g = 0;
                    int b = diff*Bmult;
                    if (b > 255)
                        b = 255;
                    else if (b < 0)
                        b = 0;
                    Fl::set_color(i + 32, r, g, b);
                }
                else
                    Fl::set_color(i + 32, diff, diff, diff);
           }
        }
        else
        {
           greyRange = (min - max) / 23;
           for (int i = 0; i < 24; ++i)
           {
               int diff = (min - int(i * greyRange)) - 1 ;
               if (useTint)
                {
                    int r = diff*Rmult;
                    if (r > 255)
                        r = 255;
                    else if (r < 0)
                        r = 0;
                    int g = diff*Gmult;
                    if (g > 255)
                        g = 255;
                    else if (g < 0)
                        g = 0;
                    int b = diff*Bmult;
                    if (b > 255)
                        b = 255;
                    else if (b < 0)
                        b = 0;
                    Fl::set_color(i + 32, r, g, b);
                }
                else
                    Fl::set_color(i + 32, diff, diff, diff);
           }
       }
  return 1;
  ;} {}
  }
  Function {setColourLine(string text, int item)} {return_type int
  } {
    code {//
        size_t nextPos = text.find(",");
        if (nextPos == std::string::npos)
            return -1;
        if (text.at(0) == char(35))
        {
            text = text.substr(1,nextPos);
            unsigned int hexNumber;
            sscanf(text.c_str(), "%x", &hexNumber);
            Fl::set_color(colourNumbers[item],hexNumber * 256);
            return 0;
        }
        if (!isdigit(text.at(0)))
            return -1;
        int red = string2int(text.substr(0, nextPos));
        if (red < 0 || red > 255)
            return -1;

        text = text.substr(nextPos + 1);
        nextPos = text.find(",");
        if (nextPos == std::string::npos)
            return -1;
        if (!isdigit(text.at(0)))
            return -1;
        int green = string2int(text.substr(0, nextPos));
        if (green < 0 || green > 255)
            return -1;

        text = text.substr(nextPos + 1);
        if (!isdigit(text.at(0)))
            return -1;
        int blue = string2int(text); // don't need comma test here
        if (blue < 0 || blue > 255)
            return -1;
        if (monoChrome == 1)
        {
            int allGrey = (red+green+blue)/3;
            red = green = blue = allGrey;
        }
        Fl::set_color(colourNumbers[item], red, green, blue);
        return 0;
        ;} {}
  }
  Function {activatebutton_presetdir(bool active)} {} {
    code {//
            if (active)
            {
                removepresetbutton->activate();
                makedefaultpresetbutton->activate();
            }
            else
            {
                removepresetbutton->deactivate();
                makedefaultpresetbutton->deactivate();
            }} {}
  }
  Function {themeError(int errLine)} {} {
    code {//
        themeTime = 1;
        if (errLine == -2)
            synth->getRuntime().Log("Theme: Missing data start marker");
        else if (errLine == -3)
            synth->getRuntime().Log("Theme: Missing data end marker");
        else if (errLine == -4)
            synth->getRuntime().Log("Theme: Short file");
        else
            synth->getRuntime().Log("Theme: Failed at line " + std::to_string(errLine));
        ;} {}
  }
  Function {recoverID()} {return_type int
  } {
    code {// No longer using this. Why not?
            if (selectedRootID >= 0)
            {
                return selectedRootID;
            }
            return 0;} {}
  }
  Function {readpresetcfg()} {} {
    code {//
            presetbrowse->clear();
            for (int i = 0; i < MAX_PRESET_DIRS; ++i)
                if (synth->getRuntime().presetsDirlist[i].size())
                {
                    string name;
                    if (i == synth->getRuntime().presetsRootID)
                        name = "* ";
                    else
                        name = "  ";
                    name += synth->getRuntime().presetsDirlist[i];
                    presetbrowse->add(name.c_str());
                }} {}
  }
  Function {convertSrate(int source)} {return_type int
  } {
    code {//
    int result = 2;
    switch (source)
    {
        case 0:
            result = 192000;
            break;
        case 1:
            result = 96000;
            break;
        case 2:
            result = 48000;
            break;
        case 3:
            result = 44100;
            break;
        case 192000:
            result = 0;
            break;
        case 96000:
            result = 1;
            break;
        case 48000:
            result = 2;
            break;
        case 44100:
            result = 3;
            break;
    }
    return result;} {}
  }
  Function {update_config(int tabnumber)} {} {
    code {//
            int tmp;
            switch (tabnumber)
            {
                case 1 : // Main
                    osc_size->value( (int)(logf(synth->getRuntime().oscilsize / 256.0f - 1.0f) / logf(2.0f)) + 1);
                    buff_size->value( (int)(logf(synth->getRuntime().buffersize / 16.0f - 1.0f) / logf(2.0f)) + 1);
                    pad_interpol->value(synth->getRuntime().Interpolation);
                    v_keyboard->value(synth->getRuntime().virKeybLayout);
                    compression->value(synth->getRuntime().gzipCompression);
                    reports->value(synth->getRuntime().toConsole);
                    instrument->value(synth->getRuntime().instrumentFormat - 1);
                    break;

                case 2 : // Jack
                    jackSource->value(synth->getRuntime().jackMidiDevice.c_str());
                    if (synth->getRuntime().midiEngine == jack_midi)
                    {
                        jackMidi->value(1);
                        alsaMidi->value(0);
                    }
                    jackServer->value(synth->getRuntime().jackServer.c_str());
                    if (synth->getRuntime().audioEngine == jack_audio)
                    {
                        jackAudio->value(1);
                        alsaAudio->value(0);
                    }
                    break;

                case 3 : // Alsa
                    {
                        alsaSource->value(synth->getRuntime().alsaMidiDevice.c_str());
                        if (synth->getRuntime().midiEngine == alsa_midi)
                        {
                            alsaMidi->value(1);
                            jackMidi->value(0);
                        }
                        alsaDevice->value(synth->getRuntime().alsaAudioDevice.c_str());
                        if (synth->getRuntime().audioEngine == alsa_audio)
                        {
                            alsaAudio->value(1);
                            jackAudio->value(0);
                        }
                        alsaSamplerate->value(convertSrate(synth->getRuntime().samplerate));
                    }
                    break;

                case 4 : // MIDI
                    switch (synth->getRuntime().midi_bank_root)
                    {
                        case 32:
                            bankrootchange->value(0);
                            break;
                        case 0:
                            bankrootchange->value(1);
                            break;
                        default:
                            bankrootchange->value(2);
                            break;
                    }

                    switch (synth->getRuntime().midi_bank_C)
                    {
                        case 32:
                            bankchange->value(0);
                            break;
                        case 0:
                            bankchange->value(1);
                            break;
                        default:
                            bankchange->value(2);
                            break;
                    }
                    progenable->value(synth->getRuntime().enableProgChange);

                    tmp = synth->getRuntime().midi_upper_voice_C;
                    if (tmp == 128)
                    {
                        EPCspinner->value(110);
                        EPCspinner->deactivate();
                        Epcheck->value(0);
                    }
                    else
                    {
                        EPCspinner->value(tmp);
                        EPCspinner->activate();
                        Epcheck->value(1);
                    }
                    Epend->hide();
                    enableNRPN->value(synth->getRuntime().enable_NRPN);
                    ignoreReset->value(synth->getRuntime().ignoreResetCCs);
                    midiMon->value(synth->getRuntime().monitorCCin);
                    midiLearned->value(synth->getRuntime().showLearnedCC);
                    break;

                case 5 : // Switches
                    handlePadSynthBuild->value(synth->getRuntime().handlePadSynthBuild);
                    setDefaultState->value(synth->getRuntime().loadDefaultState > 0);
                    nonFatal->value(synth->getRuntime().hideErrors);
                    showSplash->value(synth->getRuntime().showSplash);
                    logTimes->value(synth->getRuntime().showTimes);
                    logXML->value(synth->getRuntime().logXMLheaders);
                    saveAllXML->value(synth->getRuntime().xmlmax);
                    enableGUI->value(synth->getRuntime().showGui);
                    enableCLI->value(synth->getRuntime().showCli);
                    break;
    }} {}
  }
  Function {Show(SynthEngine *synth)} {} {
    code {//
                    if (isLV2() == false && synth->getUniqueId() == 0)
                        singleMaster->show();
                    int tmp = fetchData (0, CONFIG::control::alsaMidiType,TOPLEVEL::section::config);
                    alsaType->value(tmp);
                    if (tmp == 0)
                        alsaSource->activate();
                    else
                        alsaSource->deactivate();

                    int fetchW, fetchH, fetchX, fetchY, fetchO;
                    loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Config");
                    if (fetchW < confDW || fetchH < confDH)
                    {
                        fetchW = confDW;
                        fetchH = confDH;
                    }
                    checkSane(fetchX, fetchY, fetchW, fetchH, confDW, confDH);
                    configwindow->resize(fetchX, fetchY, fetchW, fetchH);
                    lastconfigW = 0;
                    configSeen = true;
                    configwindow->show();} {}
  }
  Function {Showpresets(SynthEngine *synth)} {} {
    code {//
                int fetchW, fetchH, fetchX, fetchY, fetchO;
                loadWin(synth, fetchW, fetchH, fetchX, fetchY, fetchO, "Config-presets");

                if (fetchW < preDW || fetchH < preDH)
                {
                    fetchW = preDW;
                    fetchH = preDH;
                }
                presets->resize(fetchX, fetchY, fetchW, fetchH);
                presets->resizable();
                lastpresetW = 0;
                presetsSeen = true;
                presets->show();} {}
  }
  Function {configRtext()} {} {
    code {//
    if (lastconfigW == configwindow->w())
        return;
    lastconfigW = configwindow->w();

    float dScale =  configwindow->w() / confDW;

    int size = int(dScale * 12);

    Tab1->labelsize(size);
    osc_size->labelsize(size);
        osc_size->textsize(size);

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

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

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

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

    compression->labelsize(size);
        compression->textsize(size);
    reports->labelsize(size);
        reports->textsize(size);
    logText->labelsize(size);
        logText->textsize(size);

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

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

    settingsNote->labelsize(size);

//
    Tab2->labelsize(size);
    handlePadSynthBuild->labelsize(size);
    bankHighlight->labelsize(size);
    setDefaultState->labelsize(size);
    nonFatal->labelsize(size);
    showSplash->labelsize(size);
    logTimes->labelsize(size);
    logXML->labelsize(size);
    saveAllXML->labelsize(size);
    enableGUI->labelsize(size);
    enableCLI->labelsize(size);
    enableAuto->labelsize(size);
    singleMaster->labelsize(size);

    historyLocks->labelsize(size);
    H_instrument->labelsize(size);
    H_patchset->labelsize(size);
    H_scale->labelsize(size);
    H_state->labelsize(size);
    H_vector->labelsize(size);
    H_mlearn->labelsize(size);

    switchesNote->labelsize(size);
//
    Tab3->labelsize(size);
    jackSource->labelsize(size);
        jackSource->textsize(size);
    jackMidi->labelsize(size);
    jackServer->labelsize(size);
        jackServer->textsize(size);
    jackAudio->labelsize(size);
    connectJackAudio->labelsize(size);

    jackNote->labelsize(size);
//
    Tab4->labelsize(size);
    alsaType->labelsize(size);
        alsaType->textsize(size);

    alsaSource->labelsize(size);
        alsaSource->textsize(size);
    alsaMidi->labelsize(size);
    alsaDevice->labelsize(size);
    alsaDevice->textsize(size);

    alsaAudio->labelsize(size);
    alsaSamplerate->labelsize(size);
        alsaSamplerate->textsize(size);

    alsaNote->labelsize(size);

//
    Tab5->labelsize(size);
    bankrootchange->labelsize(size);
        bankrootchange->textsize(size);

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

    progenable->labelsize(size);
    EPCspinner->labelsize(size);
        EPCspinner->textsize(size);
    Epend->labelsize(size);
    Epcheck->labelsize(size);
    enableNRPN->labelsize(size);
    ignoreReset->labelsize(size);
    midiMon->labelsize(size);
    midiLearned->labelsize(size);
//
    Tab6->labelsize(size);
    themeImport->labelsize(size);
    themeExport->labelsize(size);
    theme_browser->labelsize(size);
        theme_browser->textsize(size);
    themeImport->labelsize(size);
    storedLabel->labelsize(size);
    storedTheme->labelsize(size);
    currentLabel->labelsize(size);
    selectedTheme->labelsize(size);
    setAsStored->labelsize(size);
    monochrome->labelsize(size);
//
    close->labelsize(size);

    configwindow->redraw();} {}
  }
  Function {presetsRtext()} {} {
    code {//
    if (lastpresetW == presets->w())
        return;

    lastpresetW = presets->w();

    float dScale = presets->w() / preDW;

    int size = int(12 * dScale);

    addpreset->labelsize(size);
    removepresetbutton->labelsize(size);
    makedefaultpresetbutton->labelsize(size);
    pClose->labelsize(size);

    presetbrowse->textsize(size);

    presets->redraw();} {}
  }
  Function {testCC(int value, int control)} {return_type string
  } {
    code {//
            CommandBlock getData;
            getData.data.value = value;
            getData.data.control = control;
            getData.data.part = 248;
            synth->interchange.testLimits(getData);
            return textMsgBuffer.fetch(getData.data.miscmsg);} {}
  }
  decl {SynthEngine *synth;} {private local
  }
  decl {int current_ID;} {private local
  }
  decl {long selectedRootID;} {private local
  }
  decl {int EPCvalue;} {private local
  }
  decl {int BankRootvalue;} {private local
  }
  decl {int oldBank;} {private local
  }
  decl {float confDW;} {private local
  }
  decl {float confDH;} {private local
  }
  decl {float preDW;} {private local
  }
  decl {float preDH;} {private local
  }
  decl {int lastconfigW;} {private local
  }
  decl {int lastpresetW;} {public local
  }
  decl {bool configSeen;} {private local
  }
  decl {bool presetsSeen;} {private local
  }
  decl {string defaultTheme;} {private local
  }
  decl {string currentTheme;} {private local
  }
  decl {int nativeTable[768];} {private local
  }
  decl {int monoChrome;} {private local
  }
  decl {size_t themeTime;} {private local
  }
  decl {size_t themeDirTime;} {private local
  }
}
