annotate aim-mat/gui/aim_set_current_slider.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % procedure for 'aim-mat'
tomwalters@0 2 %
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 %
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 %
tomwalters@0 7 %
tomwalters@0 8 % helping function, that sets the sliders to their current values. This is
tomwalters@0 9 % a little bit preliminary, since I unfortunatly hadnt time to do this
tomwalters@0 10 % properly. Mercy!! If anyone has a few hours, he can fix this. Otherwise
tomwalters@0 11 % it works in most circumstances, however not very elegant...
tomwalters@0 12 %
tomwalters@0 13 %
bleeck@3 14 %
tomwalters@0 15 % (c) 2011, University of Southampton
bleeck@3 16 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 17 % download of current version is on the soundsoftware site:
bleeck@3 18 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 19 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 20
tomwalters@0 21
tomwalters@0 22
tomwalters@0 23 function handles=aim_set_current_slider(handles)
tomwalters@0 24 % sets the slider values and range according to the settings in handles
tomwalters@0 25
tomwalters@0 26
tomwalters@0 27 sig=handles.data.signal;
tomwalters@0 28 len=getlength(sig);
tomwalters@0 29 % if we switched from pre-sai to sai the slider has to change from time to
tomwalters@0 30 % frame number
tomwalters@0 31 if handles.info.old_current_plot<6 & handles.info.current_plot>=6 && handles.info.old_current_plot~=0
tomwalters@0 32 % fiddle with the sliders % the frame number is the default
tomwalters@0 33 handles.slideredit_start=handles.currentslidereditcombi; % save for later
tomwalters@0 34 handles.currentslidereditcombi=handles.slideredit_frames;
tomwalters@0 35 nr_frames=length(handles.data.sai);
tomwalters@0 36
tomwalters@0 37 handles.currentslidereditcombi.maxvalue=nr_frames;
tomwalters@0 38 handles.currentslidereditcombi.minvalue=1;
tomwalters@0 39 handles.currentslidereditcombi.nreditdigits=0;
tomwalters@0 40 handles.currentslidereditcombi.editscaler=1;
tomwalters@0 41
tomwalters@0 42 % calculate the current frame number:
tomwalters@0 43 current_start_time=slidereditcontrol_get_value(handles.slideredit_start);
tomwalters@0 44 framelen=getcurrentframestarttime(handles.data.sai{2})-getcurrentframestarttime(handles.data.sai{1});
tomwalters@0 45 current_frame_nr=round((current_start_time-getminimumtime(sig))/framelen)+1;
tomwalters@0 46 current_frame_nr=min(nr_frames,current_frame_nr);
tomwalters@0 47 current_frame_nr=max(1,current_frame_nr);
tomwalters@0 48
tomwalters@0 49 handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,current_frame_nr);
tomwalters@0 50 handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration
tomwalters@0 51 handles.info.old_current_plot=handles.info.current_plot;
tomwalters@0 52
tomwalters@0 53 % and set the duration slider to a start time slider
tomwalters@0 54 handles.info.oldduration=slidereditcontrol_get_value(handles.slideredit_duration); % save for later
tomwalters@0 55 handles.slideredit_duration.minvalue=0;
tomwalters@0 56 handles.slideredit_duration.maxvalue=framelen*(nr_frames-1)+getminimumtime(sig);
tomwalters@0 57 handles.slideredit_duration.current_value=getcurrentframestarttime(handles.data.sai{current_frame_nr});
tomwalters@0 58 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,current_frame_nr*framelen);
tomwalters@0 59 end
tomwalters@0 60 % other way: if switched from to sai pre-sai : go from frame number to time
tomwalters@0 61 if handles.info.old_current_plot>=6 & handles.info.current_plot<6
tomwalters@0 62 % the start time is the default
tomwalters@0 63 handles.slideredit_frames=handles.currentslidereditcombi; % save for later
tomwalters@0 64 if isfield(handles.info,'oldduration')
tomwalters@0 65 dur=handles.info.oldduration;
tomwalters@0 66 else
tomwalters@0 67 dur=0.04;
tomwalters@0 68 end
tomwalters@0 69 dur=min(dur,handles.slideredit_duration.maxvalue);
tomwalters@0 70
tomwalters@0 71 siglen=getlength(sig);
tomwalters@0 72 start_time=handles.all_options.signal.start_time;
tomwalters@0 73 duration=handles.all_options.signal.duration;
tomwalters@0 74 curdur=slidereditcontrol_get_value(handles.slideredit_duration);
tomwalters@0 75 current_start_time=slidereditcontrol_get_value(handles.slideredit_start);
tomwalters@0 76 handles.slideredit_start.minvalue=start_time;
tomwalters@0 77 handles.slideredit_start.maxvalue=start_time+siglen-curdur;
tomwalters@0 78 % handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,curstart);
tomwalters@0 79 % handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,curdur);
tomwalters@0 80
tomwalters@0 81
tomwalters@0 82 handles.slideredit_duration.minvalue=0.001;
tomwalters@0 83 handles.slideredit_duration.maxvalue=siglen;
tomwalters@0 84 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,curdur);
tomwalters@0 85 handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,duration/10);
tomwalters@0 86
tomwalters@0 87
tomwalters@0 88 % dur=slidereditcontrol_get_value(handles.slideredit_duration); % thats the starttime at the moment
tomwalters@0 89 % current_frame_number=round(handles.currentslidereditcombi.current_value);
tomwalters@0 90 % current_start_time=getcurrentframestarttime(handles.data.sai{current_frame_number});
tomwalters@0 91 % set the new control to the floating control
tomwalters@0 92 handles.currentslidereditcombi=handles.slideredit_start;
tomwalters@0 93
tomwalters@0 94 % handles.currentslidereditcombi.maxvalue=len;
tomwalters@0 95 % handles.currentslidereditcombi.minvalue=0;
tomwalters@0 96 % handles.currentslidereditcombi.nreditdigits=1;
tomwalters@0 97 % handles.currentslidereditcombi.editscaler=1000;
tomwalters@0 98
tomwalters@0 99 handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,dur); % the duration
tomwalters@0 100 current_start_time=min(current_start_time,len-dur);
tomwalters@0 101 current_start_time=max(current_start_time,0);
tomwalters@0 102 handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,current_start_time);
tomwalters@0 103
tomwalters@0 104 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,dur);
tomwalters@0 105 handles.info.old_current_plot=handles.info.current_plot;
tomwalters@0 106
tomwalters@0 107 % and set the duration slider back to the duration
tomwalters@0 108 handles.slideredit_duration.minvalue=0.001;
tomwalters@0 109 handles.slideredit_duration.maxvalue=len;
tomwalters@0 110 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,dur);
tomwalters@0 111
tomwalters@0 112 end
tomwalters@0 113
tomwalters@0 114 % second run
tomwalters@0 115 if handles.info.old_current_plot==0
tomwalters@0 116 cstart=slidereditcontrol_get_value(handles.currentslidereditcombi);
tomwalters@0 117 handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,cstart);
tomwalters@0 118 cdur=slidereditcontrol_get_value(handles.slideredit_duration);
tomwalters@0 119 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,cdur);
tomwalters@0 120 cscale=slidereditcontrol_get_value(handles.slideredit_scale);
tomwalters@0 121 handles.slideredit_scale=slidereditcontrol_set_value(handles.slideredit_scale,cscale);
tomwalters@0 122 if handles.info.current_plot>=6
tomwalters@0 123 handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration
tomwalters@0 124 else
tomwalters@0 125 handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,cdur); % the duration
tomwalters@0 126 end
tomwalters@0 127 end
tomwalters@0 128
tomwalters@0 129
tomwalters@0 130 % checking for unforseen errors. Can happen in unlucky circumstances:
tomwalters@0 131 if handles.info.current_plot>=6 % this should be in frame mode: check limits
tomwalters@0 132 nr_frames=length(handles.data.sai);
tomwalters@0 133 cur_nr=slidereditcontrol_get_value(handles.currentslidereditcombi);
tomwalters@0 134 if cur_nr > nr_frames
tomwalters@0 135 handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,nr_frames);
tomwalters@0 136 handles.currentslidereditcombi=slidereditcontrol_set_range(handles.currentslidereditcombi,10); % the duration
tomwalters@0 137 framelen=getcurrentframestarttime(handles.data.sai{2})-getcurrentframestarttime(handles.data.sai{1});
tomwalters@0 138 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,nr_frames*framelen);
tomwalters@0 139 end
tomwalters@0 140 handles.currentslidereditcombi.maxvalue=nr_frames;
tomwalters@0 141 handles.currentslidereditcombi.minvalue=1;
tomwalters@0 142
tomwalters@0 143 else
tomwalters@0 144 stval=slidereditcontrol_get_value(handles.currentslidereditcombi);
tomwalters@0 145 if stval<getminimumtime(sig);
tomwalters@0 146 handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,getminimumtime(sig));
tomwalters@0 147 end
tomwalters@0 148 if stval>getmaximumtime(sig)-0.001;
tomwalters@0 149 handles.currentslidereditcombi=slidereditcontrol_set_value(handles.currentslidereditcombi,getmaximumtime(sig)-0.04);
tomwalters@0 150 end
tomwalters@0 151 handles.slideredit_duration.minvalue=0;
tomwalters@0 152 handles.slideredit_duration.maxvalue=getlength(sig);
tomwalters@0 153
tomwalters@0 154 durval=slidereditcontrol_get_value(handles.slideredit_duration);
tomwalters@0 155 if durval<0.001
tomwalters@0 156 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,0.001);
tomwalters@0 157 end
tomwalters@0 158 if durval>getlength(sig);
tomwalters@0 159 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,getlength(sig)-stval);
tomwalters@0 160 end
tomwalters@0 161
tomwalters@0 162
tomwalters@0 163 end
tomwalters@0 164
tomwalters@0 165
tomwalters@0 166 % set the text over the sliders accordingly
tomwalters@0 167
tomwalters@0 168 duration=handles.all_options.signal.duration;
tomwalters@0 169 start_time=handles.all_options.signal.start_time;
tomwalters@0 170 sr=handles.all_options.signal.samplerate;
tomwalters@0 171
tomwalters@0 172 if duration>1
tomwalters@0 173 set(handles.displayduration,'String',num2str(fround(duration,2)));
tomwalters@0 174 set(handles.text20,'String','sec');
tomwalters@0 175 else
tomwalters@0 176 set(handles.displayduration,'String',num2str(fround(duration*1000,0)));
tomwalters@0 177 set(handles.text20,'String','ms');
tomwalters@0 178 end
tomwalters@0 179 % samplerate
tomwalters@0 180 set(handles.text25,'String',num2str(fround(sr/1000,1)));
tomwalters@0 181 % offset
tomwalters@0 182 if start_time>0
tomwalters@0 183 set(handles.text29,'String',num2str(fround(start_time*1000,1)));
tomwalters@0 184 set(handles.text28,'Visible','on');
tomwalters@0 185 set(handles.text29,'Visible','on');
tomwalters@0 186 set(handles.text30,'Visible','on');
tomwalters@0 187 else
tomwalters@0 188 set(handles.text28,'Visible','off');
tomwalters@0 189 set(handles.text29,'Visible','off');
tomwalters@0 190 set(handles.text30,'Visible','off');
tomwalters@0 191 end
tomwalters@0 192
tomwalters@0 193
tomwalters@0 194
tomwalters@0 195 % if handles.info.current_plot>=6
tomwalters@0 196
tomwalters@0 197
tomwalters@0 198 % handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,start_time);
tomwalters@0 199 % handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,duration/10);
tomwalters@0 200 %
tomwalters@0 201 % handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,0.04);
tomwalters@0 202 % handles.slideredit_duration.maxvalue=duration;
tomwalters@0 203 % handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,duration/10);
tomwalters@0 204 %
tomwalters@0 205 % handles.currentslidereditcombi=handles.slideredit_start;
tomwalters@0 206
tomwalters@0 207
tomwalters@0 208