fig=createmadfig('detuning'); 
set(fig,'KeyPressFcn','detuning keypressed');
fig=createmadmenus(fig);


% major row & column positions

left=0.1;
top=0.9;
bottom=0.15;
right=0.7;

ud.testAxes = ...
axes('Parent',fig,...
'Position',[left bottom right-left top-bottom],...
'Tag','TestAxes',...
'DrawMode','fast',...
'NextPlot','replacechildren',...
'Box','on',...
'ButtonDownFcn','detuning generate',...
'XLim', [-15 15],...
'YLim', [-2 2],...
'XGrid','on',...
'YGrid','on');

xlabel('Harmonic detuning %');
ylabel('Matching tone pitch');
title('Click in the grid to hear a tuned/detuned alternation');


uicontrol('Parent',fig, 'Position',[left 0.01 0.5 0.05], ...
'Style', 'checkbox',...
'String', 'show Moore data',...
'Value',0,...
'Callback','detuning showexpt');

lcol = 0.75;
top = 0.9;
ww = 0.2;
eh = 0.0521;
lh = 0.05;
ch = 0.13;

% Select repeats of tone
h1 = uicontrol('Parent',fig, ...
'HorizontalAlignment','left', ...
'Position',[lcol, top, ww, lh], ...
'String','Presentation cycles', ...
'Style','text', ...
'Tag','StaticText0');

h1 = uicontrol('Parent',fig, ...
'Callback','detuning numCyclesChanged', ...
'Position',[lcol, top-lh, ww, eh], ...
'String',{'1','2','3','4','5','6','7','8','9','10','15','20','30','50'}, ...
'Style','popupmenu', ...
'Tag','numCyclesMenu', ...
'Value',3);

top = top-ch;

% Select detuned harmonic
h1 = uicontrol('Parent',fig, ...
'HorizontalAlignment','left', ...
'Position',[lcol, top, ww, lh], ...
'String','Mistuned harmonic', ...
'Style','text', ...
'Tag','StaticText1');

h1 = uicontrol('Parent',fig, ...
'Callback','detuning misHChanged', ...
'Position',[lcol, top-lh, ww, eh], ...
'String',{'1','2','3','4','5','6','7','8','9','10','11','12','13','14'}, ...
'Style','popupmenu', ...
'Tag','detuneMisHMenu', ...
'Value',4);

top = top-ch;

% Total number of harmonics
h1 = uicontrol('Parent',fig, ...
'HorizontalAlignment','left', ...
'Position',[lcol, top, ww, lh], ...
'String','Total num harmonics', ...
'Style','text', ...
'Tag','StaticText2');

h1 = uicontrol('Parent',fig, ...
'Callback','detuning nHarmsChanged', ...
'Position',[lcol, top-lh, ww, eh], ...
'String',{'4','6','8','10','12','14','16','18','20'}, ...
'Style','popupmenu', ...
'Tag','detuneNHarmMenu', ...
'Value',3);

top = top-ch;	

% Base periodicity
h1 = uicontrol('Parent',fig, ...
'HorizontalAlignment','left', ...
'Position',[lcol, top, ww, lh], ...
'String','Fund. freq. (Hz)', ...
'Style','text', ...
'Tag','StaticText3');

h1 = uicontrol('Parent',fig, ...
'Callback','detuning f0SliderChanged', ...
'Max',1000, ...
'Min',0, ...
'Position',[lcol, top-lh, ww, eh], ...
'Style','slider', ...
'Tag','f0Slider', ...
'Value',250);

h1 = uicontrol('Parent',fig, ...
'BackgroundColor',[1 1 1], ...
'Callback','detuning f0BoxChanged', ...
'Position',[lcol, top-lh-eh, ww, eh], ...
'String','250', ...
'Style','edit', ...
'Tag','f0Box');

top = top - ch - eh;

% Tone duration
h1 = uicontrol('Parent',fig, ...
'HorizontalAlignment','left', ...
'Position',[lcol, top, ww, lh], ...
'String','Tone duration (ms)', ...
'Style','text', ...
'Tag','StaticText3');

h1 = uicontrol('Parent',fig, ...
'Callback','detuning durSliderChanged', ...
'Max',1000, ...
'Min',0, ...
'Position',[lcol, top-lh, ww, eh], ...
'Style','slider', ...
'Tag','durSlider', ...
'Value',200);

h1 = uicontrol('Parent',fig, ...
'BackgroundColor',[1 1 1], ...
'Callback','detuning durBoxChanged', ...
'Position',[lcol, top-lh-eh, ww, eh], ...
'String','200', ...
'Style','edit', ...
'Tag', 'durBox');

top = top - ch - eh;

% Onset skew
h1 = uicontrol('Parent',fig, ...
'HorizontalAlignment','left', ...
'Position',[lcol, top, ww, lh], ...
'String','Onset skew (ms)', ...
'Style','text', ...
'Tag','StaticText3');

h1 = uicontrol('Parent',fig, ...
'Callback','detuning onsSliderChanged', ...
'Max',200, ...
'Min',-200, ...
'Position',[lcol, top-lh, ww, eh], ...
'Style','slider', ...
'Tag','onsSlider', ...
'Value',0);

h1 = uicontrol('Parent',fig, ...
'BackgroundColor',[1 1 1], ...
'Callback','detuning onsBoxChanged', ...
'Position',[lcol, top-lh-eh, ww, eh], ...
'String','0', ...
'Style','edit', ...
'Tag', 'onsBox');

top = top - ch - eh;


