fig=createmadfig('intmel'); 
globalmenu=uimenu('Parent',fig,'Label','&Preferences','Accelerator','P');
tonedurmenu=uimenu('Parent',globalmenu,'Label','tone dur (ms)');
for i=10:10:100
  uimenu('Parent',tonedurmenu,'Label',num2str(i),...
  'Callback','intmel tonedurChanged','Tag','tonedur');
end
set(findobj(fig,'Tag','tonedur','Label','80'),'Checked','on');
ratemenu=uimenu('Parent',globalmenu,'Label','rate (tone pairs/s)');
for i=2:2:20
  uimenu('Parent',ratemenu,'Label',num2str(i),...
  'Callback','intmel presentationRateChanged','Tag','rate');
end 
set(findobj(fig,'Tag','rate','Label','4'),'Checked','on');


% AVAILABLE TUNES

m =zeros(12,16);
m(1,:)=[65 67 69 65 65 67 69 65 69 70 72 72 69 70 72 72]; n(1,:)='Frere Jacques              ';
m(2,:)=[65 65 72 72 74 74 72 72 70 70 69 69 67 67 65 65]; n(2,:)='Twinkle twinkle little star';
m(3,:)=[73 69 71 69 66 69 64 69 73 69 71 69 66 69 64 69]; n(3,:)='Peter Peter pumpkin eater  ';
m(4,:)=[69 69 71 73 69 73 71 64 69 69 71 73 69 69 68 64]; n(4,:)='Yankee doodle              ';
m(5,:)=[68 68 68 68 70 70 70 70 72 73 75 68 67 68 70 63]; n(5,:)='Sur le pont d''Avignon      ';
m(6,:)=[66 66 73 73 71 69 68 66 64 66 68 69 71 73 73 73]; n(6,:)='god rest ye merry gentlemen';
m(7,:)=[66 67 68 67 66 67 68 68 66 66 68 70 71 75 75 75]; n(7,:)='Spartan fight song         ';
m(8,:)=[68 68 72 72 75 75 72 72 73 73 70 70 67 67 63 63]; n(8,:)='Surprise Symphony (Hadyn)  ';
m(9,:)=[61 66 66 65 66 70 70 68 73 73 73 71 70 68 70 70]; n(9,:)='Hark the herald angels sing';
m(10,:)=[70 70 71 73 73 71 70 68 66 66 68 70 70 68 68 68]; n(10,:)='Ode to joy (Beethoven 9th) ';
m(11,:)=[70 70 70 72 70 70 65 65 67 65 67 69 70 70 70 70]; n(11,:)='Good king Wenceslas        ';
m(12,:)=[64 64 69 71 73 73 73 74 66 66 71 71 64 64 68 69]; n(12,:)='Man on the flying trapeze  ';

ud.melody=m;
ud.names=n;
[nummels,melsize]=size(m);
ud.nummels=nummels;
ud.melsize=melsize;
ud.knowntunes=1:2;

tunes = uimenu('Parent',fig, 'Label','&Melodies', 'Accelerator','M',...
'Tag','tunesmenu');
for i=1:nummels
  uimenu('Parent',tunes,'Label',n(i,:),'Callback','intmel selectTune',...
  'Position',i,'Checked','off');
end
set(findobj('Label',n(1,:)),'Checked','on'); 	
set(findobj('Label',n(2,:)),'Checked','on'); 	


fig=createmadmenus(fig);


left=0.1;
top=0.9;
bottom=0.1;
mid=0.5;
right=0.9;
bwidth=0.08;
blevel=0.15;

uicontrol('Parent',fig, ...
'Position',[left blevel bwidth 0.1], ...
'Callback','intmel playAB',...
'String','A + B', ...
'Style','pushbutton',...
'Tag','ABbutton');

uicontrol('Parent',fig, ...
'Position',[left+3.3*bwidth blevel bwidth 0.1], ...
'Callback','intmel next',...
'String','next ...', ...
'Style','pushbutton',...
'Tag','nextbutton',...
'Enable','off');

uicontrol('Parent',fig, ...
'Position',[left+1.1*bwidth blevel bwidth 0.1], ...
'Callback','intmel playA',...
'String','A', ...
'Style','pushbutton',...
'Tag','Abutton',...
'Enable','off');

uicontrol('Parent',fig, ...
'Position',[left+2.2*bwidth blevel bwidth 0.1], ...
'Callback','intmel playB',...
'String','B', ...
'Style','pushbutton',...
'Tag','Bbutton',...
'Enable','off');

% streaming radios

rightcol=0.55; rightcol2=0.8;
cy=0.4;
rwidth=0.1; pwidth=0.13;
twidth=0.2;
rheight=0.08; pheight=0.08;
popcol=rightcol+rwidth;

%uicontrol('Parent',fig,'Position',[rightcol-0.05 0.02 0.01 0.37]);

ud.axes = axes('Parent',fig,...
'Position',[0.05 0.5 0.94 0.45],...
'DrawMode','fast',...
'NextPlot','replacechildren',...
'Box','on',...
'XTick',[],...
'YTick',[]);

cy=cy-1.2*rheight;

uicontrol('Parent',fig, ...
'Position',[rightcol cy twidth rheight], ...
'String','freq. separation', ...
'Style','text',...
'Tag','freqsep');

ud.freqsep=uicontrol('Parent',fig, ...
'Position',[rightcol2 cy pwidth pheight], ...
'Callback','intmel redosigs',...
'String','0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20', ...
'Style','popupmenu', ...
'Value',7);

cy=cy-1.2*rheight;

uicontrol('Parent',fig, ...
'Position',[rightcol cy twidth rheight], ...
'String','relative level', ...
'Style','text',...
'Tag','relativeLevel');

ud.relativelevel=uicontrol('Parent',fig, ...
'Position',[rightcol2 cy pwidth pheight], ...
'Callback','intmel redosigs',...
'String','0|3|6|9|12|15', ...
'Style','popupmenu', ...
'Value',1);

cy=cy-1.2*rheight;

uicontrol('Parent',fig, ...
'Position',[rightcol cy twidth rheight], ...
'String','duration ratio   1:', ...
'Style','text',...
'Tag','durationRatio');

ud.durationratio=uicontrol('Parent',fig, ...
'Callback','intmel redosigs',...
'Position',[rightcol2 cy pwidth pheight], ...
'String','1|2|3|4|5', ...
'Style','popupmenu', ...
'Value',1);

cy=cy-1.2*rheight;

uicontrol('Parent',fig, ...
'Position',[rightcol cy twidth rheight], ...
'Callback','intmel redosigs',...
'String','dichotic', ...
'Tag','binaural', ...
'Style','radio');

set(fig,'UserData',ud);            

