% --------------------------------------------------------------------------------
% Graphical User Interface for controlling the Generic Hearing Aid
% configuration of the open Master Hearing Aid running on the Portable
% Hearing Lab (PHL)
% Tested with Matlab R2020a and Mahalia 4.16, does not run on Octave
% Usage:
%  - start your PHL and connect it via Wifi to your PC
%  - make sure that the generic-hearing-aid configuration is running
%  - mha.port = 33337 % default mha-port
%  - mha.host = '10.0.0.1' % IP-address of the connected PHL
%  - mhagui_PHL_generic_hearing_aid(mha)
%
% Author: Lukas Jürgensen, some edits by Florian Denk
% German Institute of Hearing Aids, Lübeck, 2021
% --------------------------------------------------------------------------------

% This file is part of the HörTech Open Master Hearing Aid (openMHA)
% Copyright © 2021 HörTech gGmbH
%
% openMHA is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as published by
% the Free Software Foundation, version 3 of the License.
%
% openMHA 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 Affero General Public License, version 3 for more details.
%
% You should have received a copy of the GNU Affero General Public License,
% version 3 along with openMHA.  If not, see <http://www.gnu.org/licenses/>.

function mhagui_PHL_generic_hearing_aid(mha)

addpath(fullfile(fileparts(mfilename('fullpath')), 'mhagui_PHL_generic_hearing_aid_callbacks'));

% Store mha struct
handle.mha = mha;

h_fig = figure('units','normalized','position',[0.1 0.04 0.8 0.93],'menubar','none','toolbar','none','name','openMHA Fitting-GUI',...
    'color',[1 1 1]);
handle.fig = h_fig;
handle.right = uipanel('parent',handle.fig,'units','normalized','position',[0.01 0 0.49 0.99],...
    'title','Right','fontsize',13,'fontweight','bold','titleposition','lefttop');
handle.left = uipanel('parent',handle.fig,'units','normalized','position',[0.5 0 0.49 0.99],...
    'title','Left','fontsize',13,'fontweight','bold','titleposition','righttop');



%% link left and right HA
handle.link = uicontrol(handle.fig,'style','pushbutton','units','normalized','backgroundcolor',[1 1 1],'string','link',...
    'fontsize',13,'position',[0.475 0.8 0.05 0.04],'tag','nolink','callback',@sidelink);

%% Reset default settings
handle.reset = uicontrol(handle.fig,'style','pushbutton','units','normalized','backgroundcolor',[1 1 1],'string','reset',...
    'fontsize',13,'position',[0.475 0.86 0.05 0.04],'callback',@reset_cllb);

%% speaker selection
handle.speaker = uicontrol(handle.fig,'style','popupmenu','units','normalized','position',[0.465 0.9 0.07 0.05],...
    'string',{'M-speaker','S-speaker'},'value',1,'fontsize',12,'callback',@sel_speaker);
%% MPO right HA
handle.mpo_right = uipanel('parent',handle.right,'units','normalized','title','MPO','position',[0 0.8 0.9 0.20],'fontsize',13,...
    'backgroundcolor',[.9 .9 .9],'highlightcolor', [0.7 0.7 0.7]);

handle.cf1 = uicontrol('parent',handle.mpo_right,'style','text','units','normalized','fontsize',11,...
    'string','250 Hz','position',[0.065 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf2 = uicontrol('parent',handle.mpo_right,'style','text','units','normalized','fontsize',11,...
    'string','500 Hz','position',[0.16 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf3 = uicontrol('parent',handle.mpo_right,'style','text','units','normalized','fontsize',11,...
    'string','1 kHz','position',[0.255 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf4 = uicontrol('parent',handle.mpo_right,'style','text','units','normalized','fontsize',11,...
    'string','2 kHz','position',[0.35 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf5 = uicontrol('parent',handle.mpo_right,'style','text','units','normalized','fontsize',11,...
    'string','4 kHz','position',[0.445 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');

handle.mpo_right_slider1 = uicontrol('parent',handle.mpo_right,'style','slider','units','normalized','position',[0.1 0.2 0.025 0.6],...
    'tooltip','250 Hz','min',80,'max',140,'tag','slider_r_250Hz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[1 .5 .5],'callback',@mpo_slider_cllb);
handle.mpo_right_slider2 = uicontrol('parent',handle.mpo_right,'style','slider','units','normalized','position',[0.19 0.2 0.025 0.6],...
    'tooltip','500 Hz','min',80,'max',140,'tag','slider_r_500Hz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[1 .5 .5],'callback',@mpo_slider_cllb);
handle.mpo_right_slider3 = uicontrol('parent',handle.mpo_right,'style','slider','units','normalized','position',[0.29 0.2 0.025 0.6],...
    'tooltip','1 kHz','min',80,'max',140,'tag','slider_r_1kHz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[1 .5 .5],'callback',@mpo_slider_cllb);
handle.mpo_right_slider4 = uicontrol('parent',handle.mpo_right,'style','slider','units','normalized','position',[0.38 0.2 0.025 0.6],...
    'tooltip','2 kHz','min',80,'max',140,'tag','slider_r_2kHz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[1 .5 .5],'callback',@mpo_slider_cllb);
handle.mpo_right_slider5 = uicontrol('parent',handle.mpo_right,'style','slider','units','normalized','position',[0.475 0.2 0.025 0.6],...
    'tooltip','4 kHz','min',80,'max',140,'tag','slider_r_4kHz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[1 .5 .5],'callback',@mpo_slider_cllb);

handle.mpo_right_edit1 = uicontrol('parent',handle.mpo_right,'style','edit','units','normalized','position',[0.075 0.01 0.08 0.13],...
    'fontsize',11,'tag','edit_r_250Hz','callback',@mpo_edit_cllb);
handle.mpo_right_edit2 = uicontrol('parent',handle.mpo_right,'style','edit','units','normalized','position',[0.17 0.01 0.08 0.13],...
   'fontsize',11,'tag','edit_r_500Hz','callback',@mpo_edit_cllb);
handle.mpo_right_edit3 = uicontrol('parent',handle.mpo_right,'style','edit','units','normalized','position',[0.265 0.01 0.08 0.13],...
    'fontsize',11,'tag','edit_r_1kHz','callback',@mpo_edit_cllb);
handle.mpo_right_edit4 = uicontrol('parent',handle.mpo_right,'style','edit','units','normalized','position',[0.36 0.01 0.08 0.13],...
    'fontsize',11,'tag','edit_r_2kHz','callback',@mpo_edit_cllb);
handle.mpo_right_edit5 = uicontrol('parent',handle.mpo_right,'style','edit','units','normalized','position',[0.455 0.01 0.08 0.13],...
    'fontsize',11,'tag','edit_r_4kHz','callback',@mpo_edit_cllb);

handle.sel_all_mpo_right = uicontrol('parent',handle.mpo_right, 'style','radiobutton','units','normalized','position',[0.68 0.85 0.15 0.2],...
    'string','select all','tag','right','value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'callback',@mpo_sel_all);
handle.mpo_all_slider_right = uicontrol('parent',handle.mpo_right,'style','slider','units','normalized','position',[0.71 0.2 0.025 0.6],...
    'tooltip','all','min',80,'max',140,'tag','all_right','sliderstep',[1/(140-80) 5/(140-80)],'enable','off',...
    'backgroundcolor',[.5 .5 .5],'value',95,'callback',@mpo_slider_cllb);
handle.mpo_all_edit_right = uicontrol('parent',handle.mpo_right,'style','edit','units','normalized','position',[0.69 0.01 0.08 0.13],...
    'fontsize',11,'tag','all_right','string','','enable','off','callback',@mpo_edit_cllb);

%% MPO left HA
handle.mpo_left = uipanel('parent',handle.left,'units','normalized','title','MPO','position',[0.1 0.8 0.9 0.20],'fontsize',13,...
    'backgroundcolor',[.9 .9 .9],'highlightcolor', [0.7 0.7 0.7]);

handle.cf1 = uicontrol('parent',handle.mpo_left,'style','text','units','normalized','fontsize',11,...
    'string','250 Hz','position',[0.065 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf2 = uicontrol('parent',handle.mpo_left,'style','text','units','normalized','fontsize',11,...
    'string','500 Hz','position',[0.16 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf3 = uicontrol('parent',handle.mpo_left,'style','text','units','normalized','fontsize',11,...
    'string','1 kHz','position',[0.255 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf4 = uicontrol('parent',handle.mpo_left,'style','text','units','normalized','fontsize',11,...
    'string','2 kHz','position',[0.35 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf5 = uicontrol('parent',handle.mpo_left,'style','text','units','normalized','fontsize',11,...
    'string','4 kHz','position',[0.445 0.9 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');

handle.mpo_left_slider1 = uicontrol('parent',handle.mpo_left,'style','slider','units','normalized','position',[0.1 0.2 0.025 0.6],...
    'tooltip','250 Hz','min',80,'max',140,'tag','slider_l_250Hz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[.5 .5 1],'callback',@mpo_slider_cllb);
handle.mpo_left_slider2 = uicontrol('parent',handle.mpo_left,'style','slider','units','normalized','position',[0.19 0.2 0.025 0.6],...
    'tooltip','500 Hz','min',80,'max',140,'tag','slider_l_500Hz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[.5 .5 1],'callback',@mpo_slider_cllb);
handle.mpo_left_slider3 = uicontrol('parent',handle.mpo_left,'style','slider','units','normalized','position',[0.29 0.2 0.025 0.6],...
    'tooltip','1 kHz','min',80,'max',140,'tag','slider_l_1kHz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[.5 .5 1],'callback',@mpo_slider_cllb);
handle.mpo_left_slider4 = uicontrol('parent',handle.mpo_left,'style','slider','units','normalized','position',[0.38 0.2 0.025 0.6],...
    'tooltip','2 kHz','min',80,'max',140,'tag','slider_l_2kHz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[.5 .5 1],'callback',@mpo_slider_cllb);
handle.mpo_left_slider5 = uicontrol('parent',handle.mpo_left,'style','slider','units','normalized','position',[0.475 0.2 0.025 0.6],...
    'tooltip','4 kHz','min',80,'max',140,'tag','slider_l_4kHz','sliderstep',[1/(140-80) 5/(140-80)],...
    'backgroundcolor',[.5 .5 1],'callback',@mpo_slider_cllb);

handle.mpo_left_edit1 = uicontrol('parent',handle.mpo_left,'style','edit','units','normalized','position',[0.075 0.01 0.08 0.13],...
    'fontsize',11,'tag','edit_l_250Hz','callback',@mpo_edit_cllb);
handle.mpo_left_edit2 = uicontrol('parent',handle.mpo_left,'style','edit','units','normalized','position',[0.17 0.01 0.08 0.13],...
   'fontsize',11,'tag','edit_l_500Hz','callback',@mpo_edit_cllb);
handle.mpo_left_edit3 = uicontrol('parent',handle.mpo_left,'style','edit','units','normalized','position',[0.265 0.01 0.08 0.13],...
    'fontsize',11,'tag','edit_l_1kHz','callback',@mpo_edit_cllb);
handle.mpo_left_edit4 = uicontrol('parent',handle.mpo_left,'style','edit','units','normalized','position',[0.36 0.01 0.08 0.13],...
    'fontsize',11,'tag','edit_l_2kHz','callback',@mpo_edit_cllb);
handle.mpo_left_edit5 = uicontrol('parent',handle.mpo_left,'style','edit','units','normalized','position',[0.455 0.01 0.08 0.13],...
    'fontsize',11,'tag','edit_l_4kHz','callback',@mpo_edit_cllb);

handle.sel_all_mpo_left = uicontrol('parent',handle.mpo_left, 'style','radiobutton','units','normalized','position',[0.68 0.85 0.15 0.2],...
    'string','select all','tag','left','value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'callback',@mpo_sel_all);
handle.mpo_all_slider_left = uicontrol('parent',handle.mpo_left,'style','slider','units','normalized','position',[0.71 0.2 0.025 0.6],...
    'tooltip','all','min',80,'max',140,'tag','all_left','sliderstep',[1/(140-80) 5/(140-80)],'enable','off',...
    'backgroundcolor',[.5 .5 .5],'value',95,'callback',@mpo_slider_cllb);
handle.mpo_all_edit_left = uicontrol('parent',handle.mpo_left,'style','edit','units','normalized','position',[0.69 0.01 0.08 0.13],...
    'fontsize',11,'tag','all_left','string','','enable','off','callback',@mpo_edit_cllb);




%% Gain & compression right HA
handle.gain_right = uipanel('parent',handle.right,'units','normalized','title','Gain & Compression','position',[0 0.21 1 0.59],'fontsize',13,...
     'backgroundcolor',[0.9 0.9 0.9],'highlightcolor', [0.7 0.7 0.7]);

% max gain
handle.maxgain_text = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','max','position',[0 0.91 0.05 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.cf1_right = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','250 Hz','position',[0.055 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf2_right = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','500 Hz','position',[0.127 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf3_right = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','1 kHz','position',[0.199 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf4_right = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','2 kHz','position',[0.271 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf5_right = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','4 kHz','position',[0.343 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.bb_right = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','broadband','visible','off','position',[0.18 0.89 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');

handle.maxgain_right_edit1 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.055 0.92 0.07 0.04],...
    'fontsize',11,'tag','edit_r_250Hz','callback',@maxgain_cllb);
handle.maxgain_right_edit2 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.127 0.92 0.07 0.04],...
   'fontsize',11,'tag','edit_r_500Hz','callback',@maxgain_cllb);
handle.maxgain_right_edit3 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.199 0.92 0.07 0.04],...
    'fontsize',11,'tag','edit_r_1kHz','callback',@maxgain_cllb);
handle.maxgain_right_edit4 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.271 0.92 0.07 0.04],...
    'fontsize',11,'tag','edit_r_2kHz','callback',@maxgain_cllb);
handle.maxgain_right_edit5 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.343 0.92 0.07 0.04],...
    'fontsize',11,'tag','edit_r_4kHz','callback',@maxgain_cllb);

handle.sel_all_maxgain_right = uicontrol('parent',handle.gain_right, 'style','radiobutton','units','normalized','position',[0.44 0.9 0.1 0.1],...
    'string','sel. all','value',0,'fontsize',10,'tag','all_right','backgroundcolor',[0.9 0.9 0.9],'callback',@maxgain_sel_all);
handle.maxgain_all_edit_right = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.199 0.92 0.07 0.04],...
    'fontsize',11,'tag','all_right','visible','off','string','80 dB','callback',@maxgain_cllb);
% G80
handle.G80_text = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','G80','position',[0.01 0.77 0.05 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.G80_right_slider1 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.07 0.7 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_250Hz','callback',@G80_slider_cllb);
handle.G80_right_slider2 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.14 0.7 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_500Hz','callback',@G80_slider_cllb);
handle.G80_right_slider3 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.21 0.7 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_1kHz','callback',@G80_slider_cllb);
handle.G80_right_slider4 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.28 0.7 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_2kHz','callback',@G80_slider_cllb);
handle.G80_right_slider5 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.35 0.7 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_4kHz','callback',@G80_slider_cllb);

handle.G80_right_edit1 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.045 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_r_250Hz','string',40,'callback', @G80_edit_cllb);
handle.G80_right_edit2 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.117 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_r_500Hz','string',40,'callback',@G80_edit_cllb);
handle.G80_right_edit3 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.189 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_r_1kHz','string',40,'callback', @G80_edit_cllb);
handle.G80_right_edit4 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.261 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_r_2kHz','string',40,'callback', @G80_edit_cllb);
handle.G80_right_edit5 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.333 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_r_4kHz','string',40,'callback', @G80_edit_cllb);

handle.sel_all_G80_text = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','sel. all','position',[0.395 0.81 0.07 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.sel_all_G80_right = uicontrol('parent',handle.gain_right, 'style','radiobutton','units','normalized','position',[0.415 0.78 0.1 0.05],...
    'value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'tag','right','callback',@g80_sel_all);
handle.G80_all_slider_right = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.47 0.7 0.025 0.2],...
    'backgroundcolor',[.5 .5 .5],'min',0,'max',80,'value',0,'enable','off','tooltip','all','tag','all_right','callback',@G80_slider_cllb);
% handle.G80_all_edit_right = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.44 0.65 0.08 0.04],...
%     'fontsize',11,'enable','off','tag','all_right','string','0 dB','callback',@G80_edit_cllb);

handle.G50_text = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','G50','position',[0.01 0.46 0.05 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.G50_right_slider1 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.07 0.39 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_250Hz','callback', @G50_slider_cllb);
handle.G50_right_slider2 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.14 0.39 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_500Hz','callback', @G50_slider_cllb);
handle.G50_right_slider3 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.21 0.39 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_1kHz','callback', @G50_slider_cllb);
handle.G50_right_slider4 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.28 0.39 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_2kHz','callback', @G50_slider_cllb);
handle.G50_right_slider5 = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.35 0.39 0.025 0.2],...
    'backgroundcolor',[1 .5 .5],'tooltip','1kHz','tag','slider_r_4kHz','callback', @G50_slider_cllb);

handle.G50_right_edit1 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.045 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_r_250Hz','string',40,'callback',@G50_edit_cllb);
handle.G50_right_edit2 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.117 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_r_500Hz','string',40,'callback',@G50_edit_cllb);
handle.G50_right_edit3 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.189 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_r_1kHz','string',40,'callback',@G50_edit_cllb);
handle.G50_right_edit4 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.261 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_r_2kHz','string',40,'callback',@G50_edit_cllb);
handle.G50_right_edit5 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.333 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_r_4kHz','string',40,'callback',@G50_edit_cllb);

handle.sel_all_G50_text = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','sel. all','position',[0.395 0.49 0.07 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.sel_all_G50_right = uicontrol('parent',handle.gain_right, 'style','radiobutton','units','normalized','position',[0.415 0.46 0.03 0.05],...
    'value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'tag','right','callback',@g50_sel_all);
handle.G50_all_slider_right = uicontrol('parent',handle.gain_right,'style','slider','units','normalized','position',[0.47 0.39 0.025 0.2],...
    'backgroundcolor',[.5 .5 .5],'min',0,'max',80,'value',0,'enable','off','tooltip','all','tag','all_right','callback', @G50_slider_cllb);
% handle.G50_all_edit_right = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.44 0.34 0.08 0.04],...
%     'fontsize',11,'enable','off','tag','all_right','string','0 dB','callback',@G50_edit_cllb);
% CR
handle.CR = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','CR','position',[0 0.59 0.05 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);
handle.right_CR1 = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',11,...
    'position',[0.055 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.right_CR2 = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',11,...
    'position',[0.125 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.right_CR3 = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',11,...
    'position',[0.195 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.right_CR4 = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',11,...
    'position',[0.265 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.right_CR5 = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',11,...
    'position',[0.335 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);

handle.AT_text = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','attack time:','position',[0.62 0.185 0.2 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);
handle.RT_text = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string','release time:','position',[0.62 0.085 0.2 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);
handle.AT_right_edit = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.8 0.2 0.08 0.04],...
    'fontsize',11,'tag','edit_r_AT','string',[num2str(0.0050) ' s'],'callback',@tau_cllb);
handle.RT_right_edit = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.8 0.1 0.08 0.04],...
    'fontsize',11,'tag','edit_r_RT','string',[num2str(0.0150) ' s'],'callback',@tau_cllb);

handle.p_right = axes(handle.gain_right, 'Units', 'normalized', 'Position',[0.62 0.5 0.36 0.4], 'Box', 'on', 'Color', [1 1 1]);
plot(handle.p_right,[0 140],[0 140],'linestyle','--','linewidth',1,'color',[.5 .5 .5])
ylim([0 140]);
yticks(0:10:140)
yticklabels({'0','','20','','40','','60','','80','','100','','120','','140'})
xticks(0:10:140);
xticklabels({'0','','20','','40','','60','','80','','100','','120','','140'})
xlim([0 140]);
grid(handle.p_right,'on')
xlabel('LE (dB)')
ylabel('LA (dB)')
hold on

handle.TB1_right = uicontrol(handle.gain_right, 'style','togglebutton','units','normalized','position',[0.7 0.9 0.1 0.05],'string','LA / LE','value',1,...
    'tag','LA_right','callback', @TB_cllb);
handle.TB2_right = uicontrol(handle.gain_right, 'style','togglebutton','units','normalized','position',[0.8 0.9 0.1 0.05],'string','V / LE','value',0,...
    'tag','V_right','callback',@TB_cllb);

handle.all_gain_right_text = uicontrol('parent',handle.gain_right,'style','text','units','normalized','fontsize',10,...
    'string',sprintf('G80\n &\nG50'),'position',[0 0.1 0.04 0.1],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.all_gain_right1 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.045 0.13 0.07 0.04],...
    'fontsize',9,'tag','250 Hz_right','string','250 Hz','callback','');
handle.all_gain_rightp31 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.05 0.17 0.06 0.05],...
    'fontsize',9,'tag','250 Hz_right','string','+3dB','callback',@g_plus3);
handle.all_gain_rightm31 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.05 0.08 0.06 0.05],...
    'fontsize',9,'tag','250 Hz_right','string','-3dB','callback',@g_min3);
handle.all_gain_rightp11 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.055 0.22 0.05 0.04],...
    'fontsize',9,'tag','250 Hz_right','string','+1dB','callback',@g_plus1);
handle.all_gain_rightm11 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.055 0.04 0.05 0.04],...
    'fontsize',9,'tag','250 Hz_right','string','-1dB','callback',@g_min1);

handle.all_gain_right2 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.117 0.13 0.07 0.04],...
    'fontsize',9,'tag','500 Hz_right','string','500 Hz','callback','');
handle.all_gain_rightp32 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.122 0.17 0.06 0.05],...
    'fontsize',9,'tag','500 Hz_right','string','+3dB','callback',@g_plus3);
handle.all_gain_rightm32 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.122 0.08 0.06 0.05],...
    'fontsize',9,'tag','500 Hz_right','string','-3dB','callback',@g_min3);
handle.all_gain_rightp12 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.127 0.22 0.05 0.04],...
    'fontsize',9,'tag','500 Hz_right','string','+1dB','callback',@g_plus1);
handle.all_gain_rightm12 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.127 0.04 0.05 0.04],...
    'fontsize',9,'tag','500 Hz_right','string','-1dB','callback',@g_min1);


handle.all_gain_right3 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.189 0.13 0.07 0.04],...
    'fontsize',9,'tag','1 kHz_right','string','1 kHz','callback','');
handle.all_gain_rightp33 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.194 0.17 0.06 0.05],...
    'fontsize',9,'tag','1 kHz_right','string','+3dB','callback',@g_plus3);
handle.all_gain_rightm33 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.194 0.08 0.06 0.05],...
    'fontsize',9,'tag','1 kHz_right','string','-3dB','callback',@g_min3);
handle.all_gain_rightp13 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.199 0.22 0.05 0.04],...
    'fontsize',9,'tag','1 kHz_right','string','+1dB','callback',@g_plus1);
handle.all_gain_rightm13 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.199 0.04 0.05 0.04],...
    'fontsize',9,'tag','1 kHz_right','string','-1dB','callback',@g_min1);

handle.all_gain_right4 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.261 0.13 0.07 0.04],...
    'fontsize',9,'tag','2 kHz_right','string','2 kHz','callback','');
handle.all_gain_rightp34 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.266 0.17 0.06 0.05],...
    'fontsize',9,'tag','2 kHz_right','string','+3dB','callback',@g_plus3);
handle.all_gain_rightm34 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.266 0.08 0.06 0.05],...
    'fontsize',9,'tag','2 kHz_right','string','-3dB','callback',@g_min3);
handle.all_gain_rightp14 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.271 0.22 0.05 0.04],...
    'fontsize',9,'tag','2 kHz_right','string','+1dB','callback',@g_plus1);
handle.all_gain_rightm14 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.271 0.04 0.05 0.04],...
    'fontsize',9,'tag','2 kHz_right','string','-1dB','callback',@g_min1);

handle.all_gain_right5 = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.333 0.13 0.07 0.04],...
    'fontsize',9,'tag','4 kHz_right','string','4 kHz','callback','');
handle.all_gain_rightp35 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.338 0.17 0.06 0.05],...
    'fontsize',9,'tag','4 kHz_right','string','+3dB','callback',@g_plus3);
handle.all_gain_rightm35 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.338 0.08 0.06 0.05],...
    'fontsize',9,'tag','4 kHz_right','string','-3dB','callback',@g_min3);
handle.all_gain_rightp15 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.343 0.22 0.05 0.04],...
    'fontsize',9,'tag','4 kHz_right','string','+1dB','callback',@g_plus1);
handle.all_gain_rightm15 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.343 0.04 0.05 0.04],...
    'fontsize',9,'tag','4 kHz_right','string','-1dB','callback',@g_min1);

handle.sel_gall_right = uicontrol('parent',handle.gain_right, 'style','radiobutton','units','normalized','position',[0.43 0.13 0.1 0.05],...
    'string','select all','value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'tag','bb_right','callback', @g_all_bb);

handle.all_bb_right = uicontrol('parent',handle.gain_right,'style','edit','units','normalized','position',[0.189 0.13 0.07 0.04],...
    'fontsize',9,'tag','bb_right','visible','off','string','bb','callback','');
handle.all_bb_rightp3 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.194 0.17 0.06 0.05],...
    'fontsize',9,'tag','bb_right','visible','off','string','+3dB','callback',@g_plus3);
handle.all_bb_rightm3 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.194 0.08 0.06 0.05],...
    'fontsize',9,'tag','bb_right','visible','off','string','-3dB','callback',@g_min3);
handle.all_bb_rightp1 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.199 0.22 0.05 0.04],...
    'fontsize',9,'tag','bb_right','visible','off','string','+1dB','callback',@g_plus1);
handle.all_bb_rightm1 = uicontrol('parent',handle.gain_right,'style','pushbutton','units','normalized','position',[0.199 0.04 0.05 0.04],...
    'fontsize',9,'tag','bb_right','visible','off','string','-1dB','callback',@g_min1);
%% Gain & compression left HA
handle.gain_left = uipanel('parent',handle.left,'units','normalized','title','Gain & Compression','position',[0 0.21 1 0.59],'fontsize',13,...
     'backgroundcolor',[0.9 0.9 0.9],'highlightcolor', [0.7 0.7 0.7]);

% max gain
handle.maxgain_text = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','max','position',[0 0.91 0.05 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.cf1_left = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','250 Hz','position',[0.055 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf2_left = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','500 Hz','position',[0.127 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf3_left = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','1 kHz','position',[0.199 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf4_left = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','2 kHz','position',[0.271 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf5_left = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','4 kHz','position',[0.343 0.89 0.07 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.bb_left = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','broadband','visible','off','position',[0.18 0.89 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');

handle.maxgain_left_edit1 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.055 0.92 0.07 0.04],...
    'fontsize',11,'tag','edit_l_250Hz','callback',@maxgain_cllb);
handle.maxgain_left_edit2 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.127 0.92 0.07 0.04],...
   'fontsize',11,'tag','edit_l_500Hz','callback',@maxgain_cllb);
handle.maxgain_left_edit3 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.199 0.92 0.07 0.04],...
    'fontsize',11,'tag','edit_l_1kHz','callback',@maxgain_cllb);
handle.maxgain_left_edit4 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.271 0.92 0.07 0.04],...
    'fontsize',11,'tag','edit_l_2kHz','callback',@maxgain_cllb);
handle.maxgain_left_edit5 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.343 0.92 0.07 0.04],...
    'fontsize',11,'tag','edit_l_4kHz','callback',@maxgain_cllb);

handle.sel_all_maxgain_left = uicontrol('parent',handle.gain_left, 'style','radiobutton','units','normalized','position',[0.44 0.9 0.1 0.1],...
    'string','sel. all','value',0,'fontsize',10,'tag','all_left','backgroundcolor',[0.9 0.9 0.9],'callback',@maxgain_sel_all);
handle.maxgain_all_edit_left = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.199 0.92 0.07 0.04],...
    'fontsize',11,'tag','all_left','visible','off','string','80 dB','callback',@maxgain_cllb);
% G80
handle.G80_text = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','G80','position',[0.01 0.77 0.05 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.G80_left_slider1 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.07 0.7 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_250Hz','callback',@G80_slider_cllb);
handle.G80_left_slider2 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.14 0.7 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_500Hz','callback',@G80_slider_cllb);
handle.G80_left_slider3 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.21 0.7 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_1kHz','callback',@G80_slider_cllb);
handle.G80_left_slider4 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.28 0.7 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_2kHz','callback',@G80_slider_cllb);
handle.G80_left_slider5 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.35 0.7 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_4kHz','callback',@G80_slider_cllb);

handle.G80_left_edit1 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.045 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_l_250Hz','string',40,'callback',@G80_edit_cllb);
handle.G80_left_edit2 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.117 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_l_500Hz','string',40,'callback',@G80_edit_cllb);
handle.G80_left_edit3 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.189 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_l_1kHz','string',40,'callback',@G80_edit_cllb);
handle.G80_left_edit4 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.261 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_l_2kHz','string',40,'callback',@G80_edit_cllb);
handle.G80_left_edit5 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.333 0.65 0.07 0.04],...
    'fontsize',11,'tag','edit_l_4kHz','string',40,'callback',@G80_edit_cllb);

handle.sel_all_G80_text = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','sel. all','position',[0.395 0.81 0.07 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.sel_all_G80_left = uicontrol('parent',handle.gain_left, 'style','radiobutton','units','normalized','position',[0.415 0.78 0.1 0.05],...
    'value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'tag','left','callback', @g80_sel_all);
handle.G80_all_slider_left = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.47 0.7 0.025 0.2],...
    'backgroundcolor',[.5 .5 .5],'min',0,'max',80,'value',0,'enable','off','tooltip','all','tag','all_left','callback',@G80_slider_cllb);
% handle.G80_all_edit_left = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.44 0.65 0.08 0.04],...
%     'fontsize',11,'enable','off','tag','all_left','string','0 dB','callback',@G80_edit_cllb);


handle.G50_text = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','G50','position',[0.01 0.46 0.05 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.G50_left_slider1 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.07 0.39 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_250Hz','callback',@G50_slider_cllb);
handle.G50_left_slider2 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.14 0.39 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_500Hz','callback',@G50_slider_cllb);
handle.G50_left_slider3 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.21 0.39 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_1kHz','callback',@G50_slider_cllb);
handle.G50_left_slider4 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.28 0.39 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_2kHz','callback',@G50_slider_cllb);
handle.G50_left_slider5 = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.35 0.39 0.025 0.2],...
    'backgroundcolor',[.5 .5 1],'tooltip','1kHz','tag','slider_l_4kHz','callback',@G50_slider_cllb);

handle.G50_left_edit1 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.045 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_l_250Hz','string',40,'callback',@G50_edit_cllb);
handle.G50_left_edit2 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.117 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_l_500Hz','string',40,'callback',@G50_edit_cllb);
handle.G50_left_edit3 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.189 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_l_1kHz','string',40,'callback',@G50_edit_cllb);
handle.G50_left_edit4 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.261 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_l_2kHz','string',40,'callback',@G50_edit_cllb);
handle.G50_left_edit5 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.333 0.34 0.07 0.04],...
    'fontsize',11,'tag','edit_l_4kHz','string',40,'callback',@G50_edit_cllb);

handle.sel_all_G50_text = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','sel. all','position',[0.395 0.49 0.07 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.sel_all_G50_left = uicontrol('parent',handle.gain_left, 'style','radiobutton','units','normalized','position',[0.415 0.46 0.03 0.05],...
    'value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'tag','left','callback',@g50_sel_all);
handle.G50_all_slider_left = uicontrol('parent',handle.gain_left,'style','slider','units','normalized','position',[0.47 0.39 0.025 0.2],...
    'backgroundcolor',[.5 .5 .5],'min',0,'max',80,'value',0,'enable','off','tooltip','all','tag','all_left','callback',@G50_slider_cllb);
% handle.G50_all_edit_left = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.44 0.34 0.08 0.04],...
%     'fontsize',11,'enable','off','tag','all_left','string','0 dB','callback',@G50_edit_cllb);
% CR
handle.CR = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','CR','position',[0.01 0.59 0.05 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);
handle.left_CR1 = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'position',[0.055 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.left_CR2 = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'position',[0.125 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.left_CR3 = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'position',[0.195 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.left_CR4 = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'position',[0.265 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);
handle.left_CR5 = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'position',[0.335 0.59 0.05 0.05],'backgroundcolor',[0.9 0.9 0.9]);

handle.AT_text = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','attack time:','position',[0.62 0.185 0.2 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);
handle.RT_text = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string','release time:','position',[0.62 0.085 0.2 0.05],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);
handle.AT_left_edit = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.8 0.2 0.08 0.04],...
    'fontsize',11,'tag','edit_l_AT','string',[num2str(0.0050) ' s'],'callback',@tau_cllb);
handle.RT_left_edit = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.8 0.1 0.08 0.04],...
    'fontsize',11,'tag','edit_l_RT','string',[num2str(0.0150) ' s'],'callback',@tau_cllb);


handle.p_left = axes(handle.gain_left, 'Units', 'normalized', 'Position',[0.62 0.5 0.36 0.4], 'Box', 'on', 'Color', [1 1 1]);
plot(handle.p_left,[0 140],[0 140],'linestyle','--','linewidth',1,'color',[.5 .5 .5])
ylim([0 140]);
yticks(0:10:140)
yticklabels({'0','','20','','40','','60','','80','','100','','120','','140'})
xticks(0:10:140);
xticklabels({'0','','20','','40','','60','','80','','100','','120','','140'})
xlim([0 140]);
grid(handle.p_left,'on')
xlabel('LE (dB)')
ylabel('LA (dB)')
hold on

handle.TB1_left = uicontrol(handle.gain_left, 'style','togglebutton','units','normalized','position',[0.7 0.9 0.1 0.05],'string','LA / LE','value',1,...
    'tag','LA_left','callback',@TB_cllb);
handle.TB2_left = uicontrol(handle.gain_left, 'style','togglebutton','units','normalized','position',[0.8 0.9 0.1 0.05],'string','V / LE','value',0,...
    'tag','V_left','callback',@TB_cllb);

handle = maxGainCheck(handle);

handle.all_gain_left_text = uicontrol('parent',handle.gain_left,'style','text','units','normalized','fontsize',10,...
    'string',sprintf('G80\n &\nG50'),'position',[0 0.1 0.04 0.1],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.all_gain_left1 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.045 0.13 0.07 0.04],...
    'fontsize',9,'tag','250 Hz_left','string','250 Hz','callback','');
handle.all_gain_leftp31 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.05 0.17 0.06 0.05],...
    'fontsize',9,'tag','250 Hz_left','string','+3dB','callback',@g_plus3);
handle.all_gain_leftm31 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.05 0.08 0.06 0.05],...
    'fontsize',9,'tag','250 Hz_left','string','-3dB','callback',@g_min3);
handle.all_gain_leftp11 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.055 0.22 0.05 0.04],...
    'fontsize',9,'tag','250 Hz_left','string','+1dB','callback',@g_plus1);
handle.all_gain_leftm11 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.055 0.04 0.05 0.04],...
    'fontsize',9,'tag','250 Hz_left','string','-1dB','callback',@g_min1);

handle.all_gain_left2 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.117 0.13 0.07 0.04],...
    'fontsize',9,'tag','500 Hz_left','string','500 Hz','callback','');
handle.all_gain_leftp32 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.122 0.17 0.06 0.05],...
    'fontsize',9,'tag','500 Hz_left','string','+3dB','callback',@g_plus3);
handle.all_gain_leftm32 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.122 0.08 0.06 0.05],...
    'fontsize',9,'tag','500 Hz_left','string','-3dB','callback',@g_min3);
handle.all_gain_leftp12 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.127 0.22 0.05 0.04],...
    'fontsize',9,'tag','500 Hz_left','string','+1dB','callback',@g_plus1);
handle.all_gain_leftm12 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.127 0.04 0.05 0.04],...
    'fontsize',9,'tag','500 Hz_left','string','-1dB','callback',@g_min1);


handle.all_gain_left3 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.189 0.13 0.07 0.04],...
    'fontsize',9,'tag','1 kHz_left','string','1 kHz','callback','');
handle.all_gain_leftp33 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.194 0.17 0.06 0.05],...
    'fontsize',9,'tag','1 kHz_left','string','+3dB','callback',@g_plus3);
handle.all_gain_leftm33 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.194 0.08 0.06 0.05],...
    'fontsize',9,'tag','1 kHz_left','string','-3dB','callback',@g_min3);
handle.all_gain_leftp13 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.199 0.22 0.05 0.04],...
    'fontsize',9,'tag','1 kHz_left','string','+1dB','callback',@g_plus1);
handle.all_gain_leftm13 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.199 0.04 0.05 0.04],...
    'fontsize',9,'tag','1 kHz_left','string','-1dB','callback',@g_min1);

handle.all_gain_left4 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.261 0.13 0.07 0.04],...
    'fontsize',9,'tag','2 kHz_left','string','2 kHz','callback','');
handle.all_gain_leftp34 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.266 0.17 0.06 0.05],...
    'fontsize',9,'tag','2 kHz_left','string','+3dB','callback',@g_plus3);
handle.all_gain_leftm34 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.266 0.08 0.06 0.05],...
    'fontsize',9,'tag','2 kHz_left','string','-3dB','callback',@g_min3);
handle.all_gain_leftp14 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.271 0.22 0.05 0.04],...
    'fontsize',9,'tag','2 kHz_left','string','+1dB','callback',@g_plus1);
handle.all_gain_leftm14 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.271 0.04 0.05 0.04],...
    'fontsize',9,'tag','2 kHz_left','string','-1dB','callback',@g_min1);

handle.all_gain_left5 = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.333 0.13 0.07 0.04],...
    'fontsize',9,'tag','4 kHz_left','string','4 kHz','callback','');
handle.all_gain_leftp35 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.338 0.17 0.06 0.05],...
    'fontsize',9,'tag','4 kHz_left','string','+3dB','callback',@g_plus3);
handle.all_gain_leftm35 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.338 0.08 0.06 0.05],...
    'fontsize',9,'tag','4 kHz_left','string','-3dB','callback',@g_min3);
handle.all_gain_leftp15 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.343 0.22 0.05 0.04],...
    'fontsize',9,'tag','4 kHz_left','string','+1dB','callback',@g_plus1);
handle.all_gain_leftm15 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.343 0.04 0.05 0.04],...
    'fontsize',9,'tag','4 kHz_left','string','-1dB','callback',@g_min1);

handle.sel_gall_left = uicontrol('parent',handle.gain_left, 'style','radiobutton','units','normalized','position',[0.43 0.13 0.1 0.05],...
    'string','select all','value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'tag','bb_left','callback',@g_all_bb);

handle.all_bb_left = uicontrol('parent',handle.gain_left,'style','edit','units','normalized','position',[0.189 0.13 0.07 0.04],...
    'fontsize',9,'tag','bb_left','visible','off','string','bb','callback','');
handle.all_bb_leftp3 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.194 0.17 0.06 0.05],...
    'fontsize',9,'tag','bb_left','visible','off','string','+3dB','callback',@g_plus3);
handle.all_bb_leftm3 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.194 0.08 0.06 0.05],...
    'fontsize',9,'tag','bb_left','visible','off','string','-3dB','callback',@g_min3);
handle.all_bb_leftp1 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.199 0.22 0.05 0.04],...
    'fontsize',9,'tag','bb_left','visible','off','string','+1dB','callback',@g_plus1);
handle.all_bb_leftm1 = uicontrol('parent',handle.gain_left,'style','pushbutton','units','normalized','position',[0.199 0.04 0.05 0.04],...
    'fontsize',9,'tag','bb_left','visible','off','string','-1dB','callback',@g_min1);
%% Expansion left HA
handle.exp_left = uipanel('parent',handle.left,'units','normalized','title','Expansion','position',[0.205 0.005 0.795 0.205],'fontsize',13,...
    'backgroundcolor',[.9 .9 .9],'highlightcolor', [0.7 0.7 0.7]);

handle.cf1 = uicontrol('parent',handle.exp_left,'style','text','units','normalized','fontsize',11,...
    'string','250 Hz','position',[0.09 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf2 = uicontrol('parent',handle.exp_left,'style','text','units','normalized','fontsize',11,...
    'string','500 Hz','position',[0.21 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf3 = uicontrol('parent',handle.exp_left,'style','text','units','normalized','fontsize',11,...
    'string','1 kHz','position',[0.33 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf4 = uicontrol('parent',handle.exp_left,'style','text','units','normalized','fontsize',11,...
    'string','2 kHz','position',[0.45 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf5 = uicontrol('parent',handle.exp_left,'style','text','units','normalized','fontsize',11,...
    'string','4 kHz','position',[0.57 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');

handle.CK = uicontrol('parent',handle.exp_left,'style','text','units','normalized','fontsize',11,...
    'string','CK','position',[0.01 0.46 0.05 0.14],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);
handle.slope = uicontrol('parent',handle.exp_left,'style','text','units','normalized','fontsize',11,...
    'string','slope','position',[0.25 0.14 0.1 0.14],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.exp_left_edit1 = uicontrol('parent',handle.exp_left,'style','edit','units','normalized','position',[0.09 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_l_250Hz','callback',@exp_threshold);
handle.exp_left_edit2 = uicontrol('parent',handle.exp_left,'style','edit','units','normalized','position',[0.21 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_l_500Hz','callback',@exp_threshold);
handle.exp_left_edit3 = uicontrol('parent',handle.exp_left,'style','edit','units','normalized','position',[0.33 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_l_1kHz','callback',@exp_threshold);
handle.exp_left_edit4 = uicontrol('parent',handle.exp_left,'style','edit','units','normalized','position',[0.45 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_l_2kHz','callback',@exp_threshold);
handle.exp_left_edit5 = uicontrol('parent',handle.exp_left,'style','edit','units','normalized','position',[0.57 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_l_4kHz','callback',@exp_threshold);

handle.sel_all_exp_left = uicontrol('parent',handle.exp_left, 'style','radiobutton','units','normalized','position',[0.81 0.64 0.15 0.1],...
    'string','select all','value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'tag','all_left','callback',@exp_sel_all);
handle.exp_all_edit_left = uicontrol('parent',handle.exp_left,'style','edit','units','normalized','position',[0.83 0.47 0.1 0.14],...
    'fontsize',11,'tag','all_left','enable','off','string','','callback',@exp_threshold);


handle.slope_left_edit = uicontrol('parent',handle.exp_left,'style','edit','units','normalized','position',[0.35 0.15 0.1 0.14],...
    'fontsize',11,'tag','left','callback',@exp_slope);

%% Expansion right HA
handle.exp_right = uipanel('parent',handle.right,'units','normalized','title','Expansion','position',[0 0.005 0.795 0.205],'fontsize',13,...
    'backgroundcolor',[.9 .9 .9],'highlightcolor', [0.7 0.7 0.7]);

handle.cf1 = uicontrol('parent',handle.exp_right,'style','text','units','normalized','fontsize',11,...
    'string','250 Hz','position',[0.09 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf2 = uicontrol('parent',handle.exp_right,'style','text','units','normalized','fontsize',11,...
    'string','500 Hz','position',[0.21 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf3 = uicontrol('parent',handle.exp_right,'style','text','units','normalized','fontsize',11,...
    'string','1 kHz','position',[0.33 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf4 = uicontrol('parent',handle.exp_right,'style','text','units','normalized','fontsize',11,...
    'string','2 kHz','position',[0.45 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');
handle.cf5 = uicontrol('parent',handle.exp_right,'style','text','units','normalized','fontsize',11,...
    'string','4 kHz','position',[0.57 0.7 0.1 0.1],'backgroundcolor',[0.9 0.9 0.9],'fontweight','bold');

handle.CK = uicontrol('parent',handle.exp_right,'style','text','units','normalized','fontsize',11,...
    'string','CK','position',[0.01 0.46 0.05 0.14],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);
handle.slope = uicontrol('parent',handle.exp_right,'style','text','units','normalized','fontsize',11,...
    'string','slope','position',[0.25 0.14 0.1 0.14],'fontweight','bold','backgroundcolor',[0.9 0.9 0.9]);

handle.exp_right_edit1 = uicontrol('parent',handle.exp_right,'style','edit','units','normalized','position',[0.09 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_r_250Hz','callback',@exp_threshold);
handle.exp_right_edit2 = uicontrol('parent',handle.exp_right,'style','edit','units','normalized','position',[0.21 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_r_500Hz','callback',@exp_threshold);
handle.exp_right_edit3 = uicontrol('parent',handle.exp_right,'style','edit','units','normalized','position',[0.33 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_r_1kHz','callback',@exp_threshold);
handle.exp_right_edit4 = uicontrol('parent',handle.exp_right,'style','edit','units','normalized','position',[0.45 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_r_2kHz','callback',@exp_threshold);
handle.exp_right_edit5 = uicontrol('parent',handle.exp_right,'style','edit','units','normalized','position',[0.57 0.47 0.1 0.14],...
    'fontsize',11,'tag','edit_r_4kHz','callback',@exp_threshold);

handle.sel_all_exp_right = uicontrol('parent',handle.exp_right, 'style','radiobutton','units','normalized','position',[0.81 0.64 0.15 0.1],...
    'string','select all','value',0,'fontsize',10,'backgroundcolor',[0.9 0.9 0.9],'tag','all_right','callback',@exp_sel_all);
handle.exp_all_edit_right = uicontrol('parent',handle.exp_right,'style','edit','units','normalized','position',[0.83 0.47 0.1 0.14],...
    'fontsize',11,'tag','all_right','enable','off','string','','callback',@exp_threshold);


handle.slope_right_edit = uicontrol('parent',handle.exp_right,'style','edit','units','normalized','position',[0.35 0.15 0.1 0.14],...
    'fontsize',11,'tag','right','callback',@exp_slope);

%% activate / deactivate certain plugins
handle.plugins = uipanel('parent',handle.fig,'units','normalized','title','Features / Plugins','titleposition','centertop',...
    'position',[0.4 0.007 0.2 0.198],'fontsize',13,'backgroundcolor',[.9 .9 .9],'highlightcolor', [0.7 0.7 0.7]);

% handle.rb.text_status = uicontrol('parent', handle.plugins,'style','text','units','normalized','fontweight','bold',...
%     'string','Status:','backgroundcolor',[.9 .9 .9],'position',[0.5 0.85 0.2 0.1],'fontsize',11,'horizontalalignment','left');

handle.rb.text_bbc = uicontrol('parent', handle.plugins,'style','text','units','normalized','fontweight','bold',...
    'string','bbc:','backgroundcolor',[.9 .9 .9],'position',[0.2 0.9 0.2 0.1],'fontsize',11,'horizontalalignment','left');
handle.rb.text_adm = uicontrol('parent', handle.plugins,'style','text','units','normalized','fontweight','bold',...
    'string','adm:','backgroundcolor',[.9 .9 .9],'position',[0.2 0.7 0.2 0.1],'fontsize',11,'horizontalalignment','left');
handle.rb.text_coh = uicontrol('parent', handle.plugins,'style','text','units','normalized','fontweight','bold',...
    'string','coh:','backgroundcolor',[.9 .9 .9],'position',[0.2 0.5 0.2 0.1],'fontsize',11,'horizontalalignment','left');
handle.rb.text_fshift = uicontrol('parent', handle.plugins,'style','text','units','normalized','fontweight','bold',...
    'string','fshift:','backgroundcolor',[.9 .9 .9],'position',[0.2 0.3 0.2 0.1],'fontsize',11,'horizontalalignment','left');
handle.rb.text_mbc = uicontrol('parent', handle.plugins,'style','text','units','normalized','fontweight','bold',...
    'string','mbc:','backgroundcolor',[.9 .9 .9],'position',[0.2 0.1 0.2 0.1],'fontsize',11,'horizontalalignment','left');

handle.rb.bbc_on = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.5 0.9 0.2 0.1],...
    'string','on','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback', @bbc_on);
handle.rb.bbc_off = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.7 0.9 0.2 0.1],...
    'string','off','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@bbc_off);

handle.rb.adm_on = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.5 0.7 0.2 0.1],...
    'string','on','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@adm_on);
handle.rb.adm_off = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.7 0.7 0.2 0.1],...
    'string','off','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@adm_off);


handle.rb.coh_on = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.5 0.5 0.2 0.1],...
    'string','on','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@coh_on);
handle.rb.coh_off = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.7 0.5 0.2 0.1],...
    'string','off','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@coh_off);

handle.rb.fshift_on = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.5 0.3 0.2 0.1],...
    'string','on','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@fshift_on);
handle.rb.fshift_off = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.7 0.3 0.2 0.1],...
    'string','off','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@fshift_off);

handle.rb.mbc_on = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.5 0.1 0.2 0.1],...
    'string','on','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@mbc_on);
handle.rb.mbc_off = uicontrol('parent',handle.plugins, 'style','radiobutton','units','normalized','position',[0.7 0.1 0.2 0.1],...
    'string','off','backgroundcolor',[.9 .9 .9],'fontsize',10,'callback',@mbc_off);


handle = readoutPlugin(handle,'bbc');
handle = readoutPlugin(handle,'adm');
handle = readoutPlugin(handle,'coh');
handle = readoutPlugin(handle,'fshift');
handle = readoutPlugin(handle,'mbc');
handle = readoutPlugin(handle,'hpvol');
handle = readoutPlugin(handle,'mpo');
handle = readoutPlugin(handle,'gain');
handle = readoutPlugin(handle,'exp');
handle = plot_data_right(handle);
handle = plot_data_left(handle);

mha_set(handle.mha,'mha.transducers.mhachain.signal_processing.ola.c.fresponse.equalize.gains',ones(4,82));

handle.dat.g50.old = mha_get(handle.mha,'mha.transducers.mhachain.signal_processing.ola.c.mbc.multibandcompressor.dc_simple.g50');
handle.dat.g80.old = mha_get(handle.mha,'mha.transducers.mhachain.signal_processing.ola.c.mbc.multibandcompressor.dc_simple.g80');

handle.dat.g1.max_right = max([handle.G80_right_slider1.Max-handle.G80_right_slider1.Value; handle.G50_right_slider1.Max-handle.G50_right_slider1.Value ]);
handle.dat.g1.min_right = -max([handle.G80_right_slider1.Value-handle.G80_right_slider1.Min; handle.G50_right_slider1.Value-handle.G50_right_slider1.Min]);

handle.dat.g2.max_right = max([handle.G80_right_slider2.Max-handle.G80_right_slider2.Value; handle.G50_right_slider2.Max-handle.G50_right_slider2.Value ]);
handle.dat.g2.min_right = -max([handle.G80_right_slider2.Value-handle.G80_right_slider2.Min; handle.G50_right_slider2.Value-handle.G50_right_slider2.Min]);

handle.dat.g3.max_right = max([handle.G80_right_slider3.Max-handle.G80_right_slider3.Value; handle.G50_right_slider3.Max-handle.G50_right_slider3.Value ]);
handle.dat.g3.min_right = -max([handle.G80_right_slider3.Value-handle.G80_right_slider3.Min; handle.G50_right_slider3.Value-handle.G50_right_slider3.Min]);

handle.dat.g4.max_right = max([handle.G80_right_slider4.Max-handle.G80_right_slider4.Value; handle.G50_right_slider4.Max-handle.G50_right_slider4.Value ]);
handle.dat.g4.min_right = -max([handle.G80_right_slider4.Value-handle.G80_right_slider4.Min; handle.G50_right_slider4.Value-handle.G50_right_slider4.Min]);

handle.dat.g5.max_right = max([handle.G80_right_slider5.Max-handle.G80_right_slider5.Value; handle.G50_right_slider5.Max-handle.G50_right_slider5.Value ]);
handle.dat.g5.min_right = -max([handle.G80_right_slider5.Value-handle.G80_right_slider5.Min; handle.G50_right_slider5.Value-handle.G50_right_slider5.Min]);

handle.dat.bb.max_right = max([handle.G80_right_slider5.Max-handle.G80_right_slider5.Value;handle.G80_right_slider4.Max-handle.G80_right_slider4.Value;...
    handle.G80_right_slider3.Max-handle.G80_right_slider3.Value;handle.G80_right_slider2.Max-handle.G80_right_slider2.Value;...
    handle.G80_right_slider1.Max-handle.G80_right_slider1.Value;handle.G50_right_slider5.Max-handle.G50_right_slider5.Value;...
    handle.G50_right_slider4.Max-handle.G50_right_slider4.Value;handle.G50_right_slider3.Max-handle.G50_right_slider3.Value;...
    handle.G50_right_slider2.Max-handle.G50_right_slider2.Value;handle.G50_right_slider1.Max-handle.G50_right_slider1.Value]);
handle.dat.bb.min_right = -max([handle.G80_right_slider5.Value-handle.G80_right_slider5.Min;handle.G80_right_slider4.Value-handle.G80_right_slider4.Min;...
    handle.G80_right_slider3.Value-handle.G80_right_slider3.Min;handle.G80_right_slider2.Value-handle.G80_right_slider2.Min;...
    handle.G80_right_slider1.Value-handle.G80_right_slider1.Min;handle.G50_right_slider5.Value-handle.G50_right_slider5.Min;...
    handle.G50_right_slider4.Value-handle.G50_right_slider4.Min;handle.G50_right_slider3.Value-handle.G50_right_slider3.Min;...
    handle.G50_right_slider2.Value-handle.G50_right_slider2.Min;handle.G50_right_slider1.Value-handle.G50_right_slider1.Min]);

handle.dat.g1.max_left = max([handle.G80_left_slider1.Max-handle.G80_left_slider1.Value; handle.G50_left_slider1.Max-handle.G50_left_slider1.Value ]);
handle.dat.g1.min_left = -max([handle.G80_left_slider1.Value-handle.G80_left_slider1.Min; handle.G50_left_slider1.Value-handle.G50_left_slider1.Min]);

handle.dat.g2.max_left = max([handle.G80_left_slider2.Max-handle.G80_left_slider2.Value; handle.G50_left_slider2.Max-handle.G50_left_slider2.Value ]);
handle.dat.g2.min_left = -max([handle.G80_left_slider2.Value-handle.G80_left_slider2.Min; handle.G50_left_slider2.Value-handle.G50_left_slider2.Min]);

handle.dat.g3.max_left = max([handle.G80_left_slider3.Max-handle.G80_left_slider3.Value; handle.G50_left_slider3.Max-handle.G50_left_slider3.Value ]);
handle.dat.g3.min_left = -max([handle.G80_left_slider3.Value-handle.G80_left_slider3.Min; handle.G50_left_slider3.Value-handle.G50_left_slider3.Min]);

handle.dat.g4.max_left = max([handle.G80_left_slider4.Max-handle.G80_left_slider4.Value; handle.G50_left_slider4.Max-handle.G50_left_slider4.Value ]);
handle.dat.g4.min_left = -max([handle.G80_left_slider4.Value-handle.G80_left_slider4.Min; handle.G50_left_slider4.Value-handle.G50_left_slider4.Min]);

handle.dat.g5.max_left = max([handle.G80_left_slider5.Max-handle.G80_left_slider5.Value; handle.G50_left_slider5.Max-handle.G50_left_slider5.Value ]);
handle.dat.g5.min_left = -max([handle.G80_left_slider5.Value-handle.G80_left_slider5.Min; handle.G50_left_slider5.Value-handle.G50_left_slider5.Min]);

handle.dat.bb.max_left = max([handle.G80_left_slider5.Max-handle.G80_left_slider5.Value;handle.G80_left_slider4.Max-handle.G80_left_slider4.Value;...
    handle.G80_left_slider3.Max-handle.G80_left_slider3.Value;handle.G80_left_slider2.Max-handle.G80_left_slider2.Value;...
    handle.G80_left_slider1.Max-handle.G80_left_slider1.Value;handle.G50_left_slider5.Max-handle.G50_left_slider5.Value;...
    handle.G50_left_slider4.Max-handle.G50_left_slider4.Value;handle.G50_left_slider3.Max-handle.G50_left_slider3.Value;...
    handle.G50_left_slider2.Max-handle.G50_left_slider2.Value;handle.G50_left_slider1.Max-handle.G50_left_slider1.Value]);
handle.dat.bb.min_left = -max([handle.G80_left_slider5.Value-handle.G80_left_slider5.Min;handle.G80_left_slider4.Value-handle.G80_left_slider4.Min;...
    handle.G80_left_slider3.Value-handle.G80_left_slider3.Min;handle.G80_left_slider2.Value-handle.G80_left_slider2.Min;...
    handle.G80_left_slider1.Value-handle.G80_left_slider1.Min;handle.G50_left_slider5.Value-handle.G50_left_slider5.Min;...
    handle.G50_left_slider4.Value-handle.G50_left_slider4.Min;handle.G50_left_slider3.Value-handle.G50_left_slider3.Min;...
    handle.G50_left_slider2.Value-handle.G50_left_slider2.Min;handle.G50_left_slider1.Value-handle.G50_left_slider1.Min]);
if handle.rb.mbc_on.Value == 1
    [handle] = maxGainCheck(handle);
end

% Store handle to fig
guidata(h_fig, handle)
