tomwalters@0: % procedure for 'aim-mat' tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % tomwalters@0: % tomwalters@0: % helping function, that sets the sliders to their current values. This is tomwalters@0: % a little bit preliminary, since I unfortunatly hadnt time to do this tomwalters@0: % properly. Mercy!! If anyone has a few hours, he can fix this. Otherwise tomwalters@0: % it works in most circumstances, however not very elegant... tomwalters@0: % tomwalters@0: % bleeck@3: % tomwalters@0: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: function handles=aim_set_current_slider(handles) tomwalters@0: % sets the slider values and range according to the settings in handles tomwalters@0: tomwalters@0: tomwalters@0: sig=handles.data.signal; tomwalters@0: len=getlength(sig); tomwalters@0: % if we switched from pre-sai to sai the slider has to change from time to tomwalters@0: % frame number tomwalters@0: if handles.info.old_current_plot<6 & handles.info.current_plot>=6 && handles.info.old_current_plot~=0 tomwalters@0: % fiddle with the sliders % the frame number is the default tomwalters@0: handles.slideredit_start=handles.currentslidereditcombi; % save for later tomwalters@0: handles.currentslidereditcombi=handles.slideredit_frames; tomwalters@0: nr_frames=length(handles.data.sai); tomwalters@0: tomwalters@0: handles.currentslidereditcombi.maxvalue=nr_frames; tomwalters@0: handles.currentslidereditcombi.minvalue=1; tomwalters@0: handles.currentslidereditcombi.nreditdigits=0; tomwalters@0: handles.currentslidereditcombi.editscaler=1; tomwalters@0: tomwalters@0: % calculate the current frame number: tomwalters@0: current_start_time=slidereditcontrol_get_value(handles.slideredit_start); tomwalters@0: framelen=getcurrentframestarttime(handles.data.sai{2})-getcurrentframestarttime(handles.data.sai{1}); tomwalters@0: current_frame_nr=round((current_start_time-getminimumtime(sig))/framelen)+1; tomwalters@0: current_frame_nr=min(nr_frames,current_frame_nr); tomwalters@0: current_frame_nr=max(1,current_frame_nr); tomwalters@0: tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,current_frame_nr); tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration tomwalters@0: handles.info.old_current_plot=handles.info.current_plot; tomwalters@0: tomwalters@0: % and set the duration slider to a start time slider tomwalters@0: handles.info.oldduration=slidereditcontrol_get_value(handles.slideredit_duration); % save for later tomwalters@0: handles.slideredit_duration.minvalue=0; tomwalters@0: handles.slideredit_duration.maxvalue=framelen*(nr_frames-1)+getminimumtime(sig); tomwalters@0: handles.slideredit_duration.current_value=getcurrentframestarttime(handles.data.sai{current_frame_nr}); tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,current_frame_nr*framelen); tomwalters@0: end tomwalters@0: % other way: if switched from to sai pre-sai : go from frame number to time tomwalters@0: if handles.info.old_current_plot>=6 & handles.info.current_plot<6 tomwalters@0: % the start time is the default tomwalters@0: handles.slideredit_frames=handles.currentslidereditcombi; % save for later tomwalters@0: if isfield(handles.info,'oldduration') tomwalters@0: dur=handles.info.oldduration; tomwalters@0: else tomwalters@0: dur=0.04; tomwalters@0: end tomwalters@0: dur=min(dur,handles.slideredit_duration.maxvalue); tomwalters@0: tomwalters@0: siglen=getlength(sig); tomwalters@0: start_time=handles.all_options.signal.start_time; tomwalters@0: duration=handles.all_options.signal.duration; tomwalters@0: curdur=slidereditcontrol_get_value(handles.slideredit_duration); tomwalters@0: current_start_time=slidereditcontrol_get_value(handles.slideredit_start); tomwalters@0: handles.slideredit_start.minvalue=start_time; tomwalters@0: handles.slideredit_start.maxvalue=start_time+siglen-curdur; tomwalters@0: % handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,curstart); tomwalters@0: % handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,curdur); tomwalters@0: tomwalters@0: tomwalters@0: handles.slideredit_duration.minvalue=0.001; tomwalters@0: handles.slideredit_duration.maxvalue=siglen; tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,curdur); tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,duration/10); tomwalters@0: tomwalters@0: tomwalters@0: % dur=slidereditcontrol_get_value(handles.slideredit_duration); % thats the starttime at the moment tomwalters@0: % current_frame_number=round(handles.currentslidereditcombi.current_value); tomwalters@0: % current_start_time=getcurrentframestarttime(handles.data.sai{current_frame_number}); tomwalters@0: % set the new control to the floating control tomwalters@0: handles.currentslidereditcombi=handles.slideredit_start; tomwalters@0: tomwalters@0: % handles.currentslidereditcombi.maxvalue=len; tomwalters@0: % handles.currentslidereditcombi.minvalue=0; tomwalters@0: % handles.currentslidereditcombi.nreditdigits=1; tomwalters@0: % handles.currentslidereditcombi.editscaler=1000; tomwalters@0: tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,dur); % the duration tomwalters@0: current_start_time=min(current_start_time,len-dur); tomwalters@0: current_start_time=max(current_start_time,0); tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,current_start_time); tomwalters@0: tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,dur); tomwalters@0: handles.info.old_current_plot=handles.info.current_plot; tomwalters@0: tomwalters@0: % and set the duration slider back to the duration tomwalters@0: handles.slideredit_duration.minvalue=0.001; tomwalters@0: handles.slideredit_duration.maxvalue=len; tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,dur); tomwalters@0: tomwalters@0: end tomwalters@0: tomwalters@0: % second run tomwalters@0: if handles.info.old_current_plot==0 tomwalters@0: cstart=slidereditcontrol_get_value(handles.currentslidereditcombi); tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,cstart); tomwalters@0: cdur=slidereditcontrol_get_value(handles.slideredit_duration); tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,cdur); tomwalters@0: cscale=slidereditcontrol_get_value(handles.slideredit_scale); tomwalters@0: handles.slideredit_scale=slidereditcontrol_set_value(handles.slideredit_scale,cscale); tomwalters@0: if handles.info.current_plot>=6 tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration tomwalters@0: else tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,cdur); % the duration tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % checking for unforseen errors. Can happen in unlucky circumstances: tomwalters@0: if handles.info.current_plot>=6 % this should be in frame mode: check limits tomwalters@0: nr_frames=length(handles.data.sai); tomwalters@0: cur_nr=slidereditcontrol_get_value(handles.currentslidereditcombi); tomwalters@0: if cur_nr > nr_frames tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,nr_frames); tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration tomwalters@0: framelen=getcurrentframestarttime(handles.data.sai{2})-getcurrentframestarttime(handles.data.sai{1}); tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,nr_frames*framelen); tomwalters@0: end tomwalters@0: handles.currentslidereditcombi.maxvalue=nr_frames; tomwalters@0: handles.currentslidereditcombi.minvalue=1; tomwalters@0: tomwalters@0: else tomwalters@0: stval=slidereditcontrol_get_value(handles.currentslidereditcombi); tomwalters@0: if stvalgetmaximumtime(sig)-0.001; tomwalters@0: handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,getmaximumtime(sig)-0.04); tomwalters@0: end tomwalters@0: handles.slideredit_duration.minvalue=0; tomwalters@0: handles.slideredit_duration.maxvalue=getlength(sig); tomwalters@0: tomwalters@0: durval=slidereditcontrol_get_value(handles.slideredit_duration); tomwalters@0: if durval<0.001 tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,0.001); tomwalters@0: end tomwalters@0: if durval>getlength(sig); tomwalters@0: handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,getlength(sig)-stval); tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % set the text over the sliders accordingly tomwalters@0: tomwalters@0: duration=handles.all_options.signal.duration; tomwalters@0: start_time=handles.all_options.signal.start_time; tomwalters@0: sr=handles.all_options.signal.samplerate; tomwalters@0: tomwalters@0: if duration>1 tomwalters@0: set(handles.displayduration,'String',num2str(fround(duration,2))); tomwalters@0: set(handles.text20,'String','sec'); tomwalters@0: else tomwalters@0: set(handles.displayduration,'String',num2str(fround(duration*1000,0))); tomwalters@0: set(handles.text20,'String','ms'); tomwalters@0: end tomwalters@0: % samplerate tomwalters@0: set(handles.text25,'String',num2str(fround(sr/1000,1))); tomwalters@0: % offset tomwalters@0: if start_time>0 tomwalters@0: set(handles.text29,'String',num2str(fround(start_time*1000,1))); tomwalters@0: set(handles.text28,'Visible','on'); tomwalters@0: set(handles.text29,'Visible','on'); tomwalters@0: set(handles.text30,'Visible','on'); tomwalters@0: else tomwalters@0: set(handles.text28,'Visible','off'); tomwalters@0: set(handles.text29,'Visible','off'); tomwalters@0: set(handles.text30,'Visible','off'); tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % if handles.info.current_plot>=6 tomwalters@0: tomwalters@0: tomwalters@0: % handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,start_time); tomwalters@0: % handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,duration/10); tomwalters@0: % tomwalters@0: % handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,0.04); tomwalters@0: % handles.slideredit_duration.maxvalue=duration; tomwalters@0: % handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,duration/10); tomwalters@0: % tomwalters@0: % handles.currentslidereditcombi=handles.slideredit_start; tomwalters@0: tomwalters@0: tomwalters@0: