Home > fcn > DIVA_GUI_callbacks > gui_model_cbk.m

gui_model_cbk

PURPOSE ^

SYNOPSIS ^

function gui_model_cbk(src,eventdata,options)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function gui_model_cbk(src,eventdata,options)
0002   switch(get(src,'tag')),
0003    case 'menu',
0004     % Callback for learned sounds menu
0005     targets=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0006     for n=1:length(targets),
0007       names{n}=targets(n).label;
0008     end
0009     selIdx=get(src,'value');
0010     if(selIdx~=1)
0011       selected=get(src,'String');
0012       selStr=selected{selIdx};
0013       idx=findstr('(',selStr);
0014       match = strmatch(selStr(1:idx-2),names,'exact');
0015       DIVA('AuditoryCortexCategorical','match',match-1);            
0016       DIVA('GUI','AC_WeightsFromTargets','target');
0017       % maintain current_file with selected target for Glottal param purposes
0018       auTarget.filename=[selStr(1:idx-2),'.mat'];
0019       auTarget.pathname=['.',filesep,'Sessiontargets',filesep,'Session_',DIVA('SessionName'),filesep];
0020       DIVA('GUI','auTarget',auTarget);
0021       DIVA('GUI','train_sound',1);
0022 
0023       % disable play button, enable produce button
0024       matchstart = (match-1)*DIVA('AuditoryCortexCategorical','ntimepoints');
0025       motorweights=DIVA('MotorCortex','WeightsFromTargets');
0026       if(~isempty(motorweights))
0027         if(matchstart < size(motorweights,2) - ...
0028            DIVA('AuditoryCortexCategorical','ntimepoints')),...
0029               producef='on';
0030         else
0031           producef='off';
0032         end
0033       else
0034         producef='off';
0035       end
0036       if(exist(fullfile('RESULTS','movies',['Session_',DIVA('SessionName')],...
0037                         [selStr(1:idx-2),'.mov']),'file'))
0038         playf='on';
0039       else
0040         playf='off';
0041       end
0042       DIVA('GUI','play',playf,'produce',producef);
0043     end
0044     %-----------------------------------------------------------%
0045 
0046    case 'play', % Change to reflect selected "stored target"
0047     target=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0048     trained_sound=target(DIVA('AuditoryCortexCategorical','match')+1).label;
0049 
0050     % Play most recently produced sound
0051     if(DIVA('GUI','AutoMovie'))
0052       if(exist(fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]),'dir'))
0053         pname = fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]);      
0054         web(['file:///',pwd,filesep,pname,filesep,[trained_sound,'.mov']],'-browser');
0055       end
0056     else
0057       [sound,fs]=getSynthSound();
0058       soundview(sound,fs);
0059     end
0060 
0061     %-----------------------------------------------------------%
0062 
0063    case 'produce',
0064     % Simulate model based on learned weights
0065     % NO learning for production trials
0066 
0067     old_WeightLearn.motor=DIVA('MotorCortex','WeightLearn');
0068     old_WeightLearn.somato=DIVA('SomatosensoryCortex','eps_learn');
0069 
0070     % Set weights to 0 for NO learning condition
0071     DIVA('MotorCortex','WeightLearn',0);
0072     DIVA('SomatosensoryCortex','eps_learn',0);
0073 
0074     old_blockmode=DIVA('BlockMode');
0075     DIVA('BlockMode',1);
0076 
0077     target=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0078     trained_sound=target(DIVA('AuditoryCortexCategorical','match')+1).label;
0079     DIVA('AuditoryCortexCategorical','target',trained_sound);
0080     DIVA('simulate');
0081 
0082     searchTarg = DIVA('MotorCortex','target',[],DIVA('TimeStep')*(-1000:0));
0083     idx=getQueueIdx(searchTarg);
0084     motor = DIVA('VocalTract','motor',[],DIVA('TimeStep')*(-idx:0));
0085     targ = searchTarg(1000-idx+1:end);
0086     [targ motor]=chompIdx(targ,motor);
0087 
0088     %DIVA('GUI','VT_Configuration',motor);
0089 
0090 
0091     % Reset learning rates to previous values
0092     DIVA('MotorCortex','WeightLearn',old_WeightLearn.motor);
0093     DIVA('SomatosensoryCortex','eps_learn',old_WeightLearn.somato);
0094     DIVA('BlockMode',old_blockmode);
0095 
0096     DIVA('GUI','AC_WeightsFromTargets','update');
0097     DIVA('GUI','other_weights',[]);
0098 
0099     % enable play button
0100     DIVA('GUI','play','on');
0101     [y,fs,motor]=getSynthSound(trained_sound);
0102     DIVA('GUI','Cochlea_plot',y);
0103     if(DIVA('GUI','AutoMovie'))
0104      produceAutoMovie(y,fs,motor,trained_sound);
0105     end
0106 
0107     %-----------------------------------------------------------%
0108 
0109    case 'browse',
0110     % Browse for target file
0111     browse_files;
0112 
0113     %-----------------------------------------------------------%
0114 
0115    case 'mic',
0116     % Specify target via microphone
0117 
0118     %-----------------------------------------------------------%
0119 
0120    case 'acquire',
0121     train_sound=DIVA('GUI','train_sound');
0122 
0123     if(train_sound == 1)
0124       fname=DIVA('GUI','current_file');
0125       au_info=load(fname);
0126       DIVA('SoundChannel','sound',au_info.f.mean');
0127       DIVA('AuditoryCortexCategorical','label',au_info.name);
0128       DIVA('simulate');
0129       DIVA('GUI','ACC_AuditoryTargets','update');
0130     end
0131 
0132     %-----------------------------------------------------------%
0133 
0134    case {'reset'}
0135     %     % clear model weight parameters, need to clear state values too!
0136     %     matchstart = DIVA('AuditoryCortexCategorical','ntimepoints')*...
0137     %         DIVA('AuditoryCortexCategorical','match')+1;
0138     %     matchend=matchstart+DIVA('AuditoryCortexCategorical','ntimepoints')-1;
0139     
0140     %     % Reset Motor Weights
0141     %     motorweight=DIVA('MotorCortex','WeightsFromTargets');
0142     %     motorweight(:,matchstart:matchend)=...
0143     %         repmat(DIVA('MotorCortex','default_motorSound'),1,...
0144     %                DIVA('AuditoryCortexCategorical','ntimepoints'));
0145     %     DIVA('MotorCortex','WeightsFromTargets',motorweight);
0146     
0147     %     % Reset Somatosensory Weights
0148     %     somatoweight=DIVA('SomatosensoryCortex','WeightsFromTargets');
0149     %     somatoweight(:,matchstart:matchend)=...
0150     %         repmat(DIVA('SomatosensoryCortex','default_somatosensory'),1,...
0151     %                DIVA('AuditoryCortexCategorical','ntimepoints'));
0152     %     DIVA('SomatosensoryCortex','WeightsFromTargets',somatoweight);
0153     
0154     %     % Reset stored training trials
0155     %     tmp=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0156     %     tmp(DIVA('AuditoryCortexCategorical','match')+1).ntrained=0;
0157     %     DIVA('AuditoryCortexCategorical','AuditoryTargets',tmp);
0158     DIVA('reset');
0159     DIVA('GUI','ACC_AuditoryTargets','update');
0160 
0161     %-----------------------------------------------------------%
0162 
0163    case {'train'},
0164     % Train or Retrain model on specified target
0165 
0166     target=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0167     trained_sound = target(DIVA('AuditoryCortexCategorical','match')+1).label;
0168     progWin = waitbar(0,sprintf('Training %d%% complete',0));
0169     nTrain = DIVA('GUI','nTrain');
0170 
0171     for i=1:nTrain,
0172       DIVA('AuditoryCortexCategorical','target',trained_sound);
0173       DIVA('simulate');
0174       DIVA('GUI','AC_WeightsFromTargets','update');
0175       DIVA('GUI','other_weights',[]);
0176       waitbar(i/nTrain,progWin,sprintf('Training %d%% complete',round(100*i/nTrain)));
0177       [y,fs,motor]=getSynthSound(trained_sound);
0178       DIVA('GUI','Cochlea_plot',y);
0179       DIVA('GUI','ACC_AuditoryTargets','update');
0180 %           DIVA('AuditoryCortexCategorical','AuditoryTargets'));
0181     end
0182     close(progWin);
0183 
0184     % enable play button, enable produce button
0185     DIVA('GUI','play','on','produce','on');
0186     [y,fs,motor]=getSynthSound(trained_sound);
0187     DIVA('GUI','Cochlea_plot',y);
0188 
0189     % Create Movie
0190     if(DIVA('GUI','AutoMovie'))
0191       produceAutoMovie(y,fs,motor,trained_sound);
0192     end
0193 
0194     %-----------------------------------------------------------%
0195 
0196    case 'other',
0197     DIVA('GUI','other_weights',[]);
0198 
0199   end
0200 
0201 function produceAutoMovie(y,fs,motor,name)
0202 
0203   h=figure('position',[50 50 640 480],'menubar','none','doublebuffer','on');
0204   wh=waitbar(0,sprintf('%d%% complete',0),'position',[50 700 300 70]);
0205   figure(h);
0206   if(~exist(fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]),'dir'))
0207     mkdir(fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]));
0208   end
0209   pname = fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]);
0210   if(nargin==4)
0211     fname = [name,'.mov'];
0212   else
0213     fname ='lastheard.mov';
0214   end
0215   if(~isempty(fname))
0216     MakeQTMovie('start',[pname,filesep,fname]);
0217     MakeQTMovie('size',[640 480]);
0218     MakeQTMovie('quality',0.8);
0219     for n=1:5:length(motor),
0220       figure(h);
0221       if(size(motor,1)>DIVA('MotorCortex','nMotor'))
0222         DIVA('VocalTract','plot',motor(1:end-3,n)); axis equal; axis off;
0223       else
0224         DIVA('VocalTract','plot',motor(:,n)); axis equal; axis off;
0225       end
0226       MakeQTMovie('addaxes');
0227       waitbar(n/length(motor),wh,sprintf('%d%% complete',round(100*n/length(motor))));
0228     end
0229     MakeQTMovie('frameRate',200);
0230     MakeQTMovie('addsound',y,fs);
0231     MakeQTMovie('finish');
0232   end
0233   close(h);
0234   close(wh);
0235 
0236   %web(['file:///',pwd,filesep,'RESULTS',filesep,'movies',filesep,'lastheard.mov'],'-browser');
0237   web(['file:///',pwd,filesep,pname,filesep,fname],'-browser');
0238 
0239 %   im=ReadQTMovie('start',[pname,fname]);
0240 %   for n=1:length(im.frame_pos),
0241 %     mov(n)=im2frame(ReadQTMovie('getframe',n));
0242 %   end
0243 %   ReadQTMovie('close');
0244 %   soundview(y,fs);
0245 %   mplay(mov,200);
0246

Generated on Tue 27-Mar-2007 12:06:24 by m2html © 2003