%SLT_GUI Graphical User Interface definition for SLT: Speech/Spectrogram labelling tool
%  
%  Original Author: Stuart N Wrigley       
%  (c) University of Sheffield 1998
%  Revision 0.01: 6 September 1998
%  This version substantially modified by Martin Cooke, September 1998

mainfig=createmadfig('slt'); 

% menus

filemenu = uimenu('Parent',mainfig,'Label','File');
   uimenu('Parent',filemenu, 'Callback','slt loadSpeech', ...
      'Label','load speech ...',...
      'Accelerator','L');
   ud.loadopt=uimenu('Parent',filemenu, ...
      'Accelerator','T',...
      'Callback','slt loadannot', 'Label','load transcription ...');
   ud.saveopt=uimenu('Parent',filemenu, ...
      'Accelerator','S',...
      'Callback','slt saveannot', 'Label','save transcription');
   ud.saveAsopt=uimenu('Parent',filemenu, ...
      'Accelerator','A',...
      'Callback','slt saveAsannot', 'Label','save transcription as ...');

 mainfig=createmadmenus(mainfig);

ud.signaldir=fullfile(madroot,'data','sounds');
ud.annotdir=fullfile(madroot,'data','annots');
ud.noplay=1;

% some dimensions
   
left=0.02; width=0.98;
wavbase=0.17; wavheight=0.15;
labelbase=wavbase+wavheight; labelheight=0.2;
annotbase=labelbase+labelheight;  annotheight=0.07;
spectbase=annotbase+annotheight; spectheight=0.99-spectbase;

ud.wavleft=left;
ud.wavbase=wavbase;

row=spectbase+spectheight;
%uicontrol('Parent',mainfig,'Style','text','FontAngle','italic','String','spectrogram type:',...
%   'Position',[left row 0.15 0.08],'HorizontalAlignment','right');

uicontrol('Parent',mainfig,'Style','text','String','spectrogram type:',...
   'Position',[0.68 0.1 0.19 0.05],'HorizontalAlignment','right');
ud.spectResMenu=uicontrol('Parent',mainfig,'Style','popupmenu',...
   'String','wide|medium|narrow',...
   'Value',1,...
   'Position',[0.88 0.1 0.12 0.05],...
   'Callback','slt spectResChanged');
   
uicontrol('Parent',mainfig,'Style','text','String','quality:',...
   'Position',[0.72 0.05 0.15 0.05],'HorizontalAlignment','right');
ud.qualityMenu=uicontrol('Parent',mainfig,'Style','popupmenu',...
   'String','rough|good|best',...
   'Value',1,...
   'Position',[0.88 0.05 0.12 0.05],...
   'Callback','slt qualityChanged'); 

uicontrol('Parent',mainfig,'Style','text','String','contrast:',...
   'Position',[0.72 0.0 0.15 0.05],'HorizontalAlignment','right');
ud.inccontrastbutton=uicontrol('Parent',mainfig,'Style','Pushbutton','String','+',...
   'Position',[0.88 0.0 0.05 0.05],...
   'Callback','slt inccontrast','Enable','off');
ud.deccontrastbutton=uicontrol('Parent',mainfig,'Style','Pushbutton','String','-',...
   'Position',[0.92 0.0 0.05 0.05],...
   'Callback','slt deccontrast','Enable','off');
   
uicontrol('Parent',mainfig,'Style','text','String','Time:',...
  'Position',[left 0.05 0.08 0.05],'HorizontalAlignment','right');
ud.timebox=uicontrol('Parent',mainfig,'Style','text','String','0',...
  'Position',[left+0.1 0.05 0.1 0.05]);
uicontrol('Parent',mainfig,'Style','text','FontAngle','italic','String','ms',...
  'Position',[left+0.18 0.05 0.1 0.05],'HorizontalAlignment','left');
  
uicontrol('Parent',mainfig,'Style','text','String','Freq:',...
  'Position',[left 0.0 0.08 0.05],'HorizontalAlignment','right');
ud.freqbox=uicontrol('Parent',mainfig,'Style','text','String','0',...
  'Position',[left+0.1 0.0 0.1 0.05]);
uicontrol('Parent',mainfig,'Style','text','FontAngle','italic','String','Hz',...
  'Position',[left+0.18 0.0 0.1 0.05],'HorizontalAlignment','left');
  
ud.spectAxes = axes('Parent',mainfig, ...
	'Box','on', ...
	'ButtonDownFcn','slt play', ...
	'DrawMode','fast', ...
	'FontSize',9, ...
	'NextPlot','replacechildren', ...
   'XLimMode','manual', ...
	'Position',[left spectbase width spectheight], ...
   'YLim',[0 6000],...
   'XTick',[],...
   'YTick',[],...
   'YLimMode','manual');

ud.YLim = 1.1*[-1 1];
ud.signalAxes = axes('Parent',mainfig, ...
	'Box','on', ...
	'ButtonDownFcn','slt play', ...
	'DrawMode','fast', ...
	'FontSize',9, ...
	'NextPlot','replacechildren', ...
	'Position',[left wavbase width wavheight], ...
   'XLimMode','manual', ...
   'XTick',[],...
   'YTick',[],...
	'YLim',ud.YLim, ...
	'YLimMode','manual');

ud.leftbutton=uicontrol('Parent',mainfig,'Style','Pushbutton','String','<<--',...
   'Position',[0.35 0.0 0.05 0.15],...
   'Callback','slt goleft','Enable','off');
ud.zoomcursorsbutton=uicontrol('Parent',mainfig,'Style','Pushbutton','String','zoom to cursors',...
   'Position',[0.4 0.05 0.2 0.05],...
   'Callback','slt zoomcursors','Enable','off');
ud.zoombutton=uicontrol('Parent',mainfig,'Style','Pushbutton','String','zoom',...
   'Position',[0.4 0.1 0.1 0.05],...
   'Callback','slt zoom','Enable','off');
ud.unzoombutton=uicontrol('Parent',mainfig,'Style','Pushbutton','String','unzoom',...
   'Position',[0.5 0.1 0.1 0.05],...
   'Callback','slt unzoom','Enable','off');
ud.showallbutton=uicontrol('Parent',mainfig,'Style','Pushbutton','String','show whole signal',...
   'Position',[0.4 0.0 0.2 0.05],...
   'Callback','slt unzoomall','Enable','off');
ud.rightbutton=uicontrol('Parent',mainfig,'Style','Pushbutton','String','-->>',...
   'Position',[0.6 0.0 0.05 0.15],...
   'Callback','slt goright','Enable','off');
   
ud.annotAxes = axes('Parent',mainfig, ...
	'Box','on', ...
	'Color',[1 1 1], ...
   'ButtonDownFcn','slt playBetweenLabels',...
	'DrawMode','fast', ...
	'FontSize',9, ...
	'NextPlot','replacechildren', ...
	'Position',[left annotbase width annotheight], ...
	'XLimMode','manual', ...
	'XTick',[], ...
   'YTick',[],...
	'XTickMode','manual', ...
	'YLimMode','manual', ...
	'YLim',ud.YLim);


ud.signalLine = line('Parent',ud.signalAxes, ...
	'ButtonDownFcn','slt play', ...
	'Color',[0 0 1],...
   'XData',[0 0],'YData',[0 0]);
   
ud.signalLC = line('Parent',ud.signalAxes,'ButtonDownFcn','slt left',...
   'EraseMode','xor','XData',[0 0],'YData',ud.YLim,'Color','red');
ud.signalRC = line('Parent',ud.signalAxes,'ButtonDownFcn','slt right',...
   'EraseMode','xor','XData',[0 0],'YData',ud.YLim,'Color','red');
ud.annotLC = line('Parent',ud.annotAxes,'Color','red',...
   'EraseMode','xor','XData',[0 0],'YData',ud.YLim,'ButtonDownFcn','slt left');
ud.annotRC = line('Parent',ud.annotAxes,'Color','red',...
   'EraseMode','xor','XData',[0 0],'YData',ud.YLim,'ButtonDownFcn','slt right');
ud.spectLC = line('Parent',ud.spectAxes,'ButtonDownFcn','slt left',...
   'EraseMode','xor','XData',[0 0],'YData',ud.YLim,'Color','red');
   
set(findobj(gcf,'Style','pushbutton'),'Enable','off');
set(findobj(gcf,'Style','popupmenu'),'Enable','off');


ud.suv='sil (silence)|U (unvoiced)|V (voiced)|?? (non-speech/unclassified) |D (digits)';
ud.voiced='VS - stop (voiced)|N - nasal|V - vowel|SV - semivowel|DP - diphthong|VF - fricative (voiced)';
ud.unvoiced='US - stop (unvoiced)|UF - fricative (unvoiced)|hh - aspirant (hat)';
ud.voicedstops='b (but)|d (den)|g (game)';
ud.unvoicedstops='p (put)|t (ten)|k (can)';
ud.voicedfrics='z (zoo)|zh (measure)|dh (then)|v (very)|jh (Jane)';
ud.unvoicedfrics='s (sum)|sh (ship)|th (thin)|f (full)|ch (chain)';
ud.semivowels='r (run)|w (went)|l (like)|y (yes)';
ud.vowels='iy (bead)|aa (bard)|ao (born)|uw (boon)|ih (bid)|eh (bed)|ae (bad)|ah (putt)|oh (pot)|uh (bud)|er (bird)|ax (about)';
ud.diphthongs='ey (bay)|ay (buy)|oy (boy)|ow (no)|aw (now)|ia (peer)|ea (pair)|ua (poor)';
ud.nasals='m (man)|n (not)|ng (thing)';
ud.digits='oh|zero|one|two|three|four|five|six|seven|eight|nine';

% NB I know that jh and ch are affricates, but ...

ud.SUVlabels=uicontrol('Parent',mainfig,'Style','listbox',...
   'String',ud.suv,...
   'Value',1,...
   'Position',[left labelbase+0.01 0.25 0.18],...
   'Callback','slt selectSUV');
   
ud.broadlistbox=uicontrol('Parent',mainfig,'Style','listbox',...
   'String','',...
   'Value',1,...
   'Position',[left+0.35 labelbase+0.01 0.25 0.18],...
   'Callback','slt selectBroad');
 
ud.narrowlistbox=uicontrol('Parent',mainfig,'Style','listbox',...
   'String','',...
   'Value',1,...
   'Position',[left+0.7 labelbase+0.01 0.25 0.18],...
   'Callback','slt selectfine');

set(mainfig,'UserData',ud);

