0001 function [obj] = vb_timeseries_viewer_callback(obj, hObj)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 if ~exist('obj', 'var')
0018 error('obj is a required parameter.');
0019 end
0020 if ~exist('hObj', 'var')
0021 error('hObj is a required parameter.');
0022 end
0023
0024
0025
0026
0027 get(hObj, 'Tag');
0028
0029 obj.event_number = obj.event_number + 1;
0030
0031 H = obj.H;
0032
0033 Nsample = obj.Nsample;
0034 freq = obj.freq;
0035
0036 switch(hObj)
0037 case H.timeseries_slider
0038 obj = vb_timeseries_viewer_update_display_time_range(obj);
0039 case H.timepoint_current_text
0040 obj = vb_timeseries_viewer_specify_display_time(obj);
0041 case H.Yscale_slider
0042
0043 val = 1-get(hObj, 'Value');
0044 window_len = val * 100;
0045 if window_len >= obj.total_time_sec
0046 window_len = obj.total_time_sec;
0047 end
0048 obj.window_len = window_len;
0049
0050 obj = vb_timeseries_viewer_specify_display_time(obj);
0051 case H.make_preview_file_push
0052
0053 h = msgbox('Now creating preview file....', 'Please wait');
0054 bh = findall(h, 'Style', 'pushbutton');
0055 set(bh, 'Visible', 'off'); drawnow; pause(0.1);
0056
0057 MEGinfo = vb_continuous_file_get_meg_info(obj.org_file);
0058 measurement = vb_info_get_measurement(MEGinfo);
0059
0060
0061 if strcmpi(measurement, 'MEG')
0062 ext = '.meg.mat';
0063 func_name = 'vb_megfile_filter_ch_data';
0064 elseif strcmpi(measurement, 'EEG')
0065 ext = '.eeg.mat';
0066 func_name = 'vb_eegfile_filter_ch_data';
0067 end
0068
0069 org_file = vb_continuous_file_get_filename(obj.org_file);
0070 [base_path, base_filename] = vb_get_file_parts(strrep(org_file, ext, ''));
0071
0072 preview_file = fullfile(base_path, [base_filename, '_50Hz', ext]);
0073 proc_spec.parm.fsamp = 50;
0074 try
0075 feval(func_name, org_file, proc_spec, preview_file);
0076 catch
0077 errordlg(...
0078 ['Failed to make preview file: ' preview_file, ...
0079 sprintf(...
0080 '\nCheck directory permission.')], ...
0081 'Preview file');
0082 end
0083 if ishandle(h), delete(h); end
0084
0085 if exist(preview_file, 'file') == 2
0086 obj.preview_file = vb_continuous_file_new(preview_file, obj.data_ch_list);
0087 obj = vb_timeseries_viewer_plot_measurement_data(obj);
0088
0089 obj = vb_timeseries_viewer_update_display_time_range(obj);
0090 end
0091 case {H.ylimit_high_edit, H.ylimit_low_edit}
0092 if isnan(str2double(get(hObj, 'String')))
0093 errordlg('Invalid value was specified(Not a number). please input again.', 'Range');
0094 set(hObj, 'String', '');
0095 return;
0096 end
0097 high = str2double(get(H.ylimit_high_edit, 'String'));
0098 low = str2double(get(H.ylimit_low_edit, 'String'));
0099 if ~isnan(high) && ~isnan(low)
0100 ylim(H.data_axes, [low, high]);
0101 range = ylim(H.data_axes);
0102 Ydata = [range(1), range(2)];
0103 for k=1:length(obj.trial_onset_handles)
0104 set(obj.trial_onset_handles(k), 'Ydata', Ydata);
0105 end
0106 end
0107 case H.data_channel_push
0108 [selected_ch_list, cancel] = ...
0109 vb_te_channel_selector_new(obj.data_ch_list, ...
0110 obj.data_ch_list(obj.data_ch_list_plot_ix));
0111 if ~cancel
0112 obj.data_ch_list_plot_ix = [];
0113 for k=1:length(selected_ch_list)
0114 ix = strmatch(selected_ch_list{k}, obj.data_ch_list, 'exact');
0115 obj.data_ch_list_plot_ix = [obj.data_ch_list_plot_ix; ix];
0116 end
0117 obj = vb_timeseries_viewer_update_display_time_range(obj);
0118 end
0119 case H.trigger_channel_push
0120 [selected_ch_list, cancel] = ...
0121 vb_te_channel_selector_new(obj.trig_ch_list, ...
0122 obj.trig_ch_list(obj.trig_ch_list_plot_ix));
0123 if ~cancel
0124 obj.trig_ch_list_plot_ix = [];
0125 for k=1:length(selected_ch_list)
0126 ix = strmatch(selected_ch_list{k}, obj.trig_ch_list);
0127 obj.trig_ch_list_plot_ix = [obj.trig_ch_list_plot_ix; ix];
0128 end
0129 obj = vb_timeseries_viewer_update_display_time_range(obj);
0130 end
0131 case {H.ylimit_trigger_high_edit, H.ylimit_trigger_low_edit}
0132 if isnan(str2double(get(hObj, 'String')))
0133 errordlg('Invalid value was specified(Not a number). please input again.', 'Range');
0134 set(hObj, 'String', '');
0135 return;
0136 end
0137 high = str2double(get(H.ylimit_trigger_high_edit, 'String'));
0138 low = str2double(get(H.ylimit_trigger_low_edit, 'String'));
0139 ylim(H.trigger_axes, [low, high]);
0140 if ~isnan(high) && ~isnan(low)
0141 range = ylim(H.trigger_axes);
0142 Ydata = [range(1), range(2)];
0143 for k=1:length(obj.ext_onset_handles)
0144 set(obj.ext_onset_handles(k), 'Ydata', Ydata);
0145 end
0146 end
0147 case {H.scale_minus_push, H.scale_plus_push}
0148 val = get(H.Yscale_slider, 'Value');
0149 step = get(H.Yscale_slider, 'SliderStep');
0150 max_val = get(H.Yscale_slider, 'Max');
0151 min_val = get(H.Yscale_slider, 'Min');
0152 if hObj == H.scale_minus_push
0153 val = val - step(1);
0154 if val < min_val, val = min_val; end
0155 else
0156 val = val + step(1);
0157 if val > max_val, val = max_val; end
0158 end
0159 set(H.Yscale_slider, 'Value', val);
0160
0161
0162 obj = vb_timeseries_viewer_callback(obj, H.Yscale_slider);
0163 case H.trigger_yrange_fix_check
0164 if get(hObj, 'Value')
0165
0166 high = str2double(get(H.ylimit_trigger_high_edit, 'String'));
0167 low = str2double(get(H.ylimit_trigger_low_edit, 'String'));
0168
0169 if isnan(high) || isnan(low)
0170 range = ylim(H.trigger_axes);
0171 set(H.ylimit_trigger_low_edit, 'String', num2str(range(1)));
0172 set(H.ylimit_trigger_high_edit, 'String', num2str(range(2)));
0173 end
0174 set(H.trigger_axes, 'YLimMode', 'manual');
0175 else
0176 set(H.trigger_axes, 'YLimMode', 'auto');
0177 end
0178 case H.trigger_min_max_value_push
0179 parm.min_value = obj.trigger_min;
0180 parm.max_value = obj.trigger_max;
0181 vb_edit_struct(parm, 'min/max value of trigger data');
0182 case H.trigger_axes
0183 point = get(hObj, 'currentpoint');
0184 vb_text_area('Y value', num2str(point(1,2)));
0185 case H.save_trigger_file
0186 [f, p] = uiputfile({'*.trig.mat'}, 'Save trigger As', obj.trigger_file);
0187 if isequal(f, 0) || isequal(p, 0)
0188
0189 else
0190 save_file = fullfile(p, f);
0191 vb_timeseries_viewer_save_trigger_file(obj, save_file);
0192 msgbox(['Saved:' save_file], 'notice');
0193 end
0194 case H.load_trigger_file
0195 [f, p] = uigetfile({'*.trig.mat'}, 'Load trigger file', obj.trigger_file);
0196 if isequal(f, 0)
0197
0198 else
0199 load_file = fullfile(p, f);
0200 [trial_list, trig_ch_list] = ...
0201 vb_timeseries_viewer_load_trigger_file(obj.trigger_obj, load_file);
0202 if ~isempty(trial_list) && ~isempty(trig_ch_list)
0203 obj = vb_timeseries_viewer_set_trial(obj, trial_list);
0204 obj.trig_ch_list = trig_ch_list;
0205
0206 obj = vb_timeseries_viewer_update_display_time_range(obj);
0207 msgbox('Triggers are loaded.', 'notice');
0208 end
0209 end
0210 otherwise
0211 if strcmp(get(hObj, 'Tag'), 'ext_trig_line')
0212
0213 point = get(H.trigger_axes, 'currentpoint');
0214 h = vb_text_area('Y value', num2str(point(1,2)));
0215 end
0216
0217 end
0218
0219
0220 if ~ishandle(obj.figure), return; end
0221
0222 pre = guidata(obj.figure);
0223 if pre.event_number < obj.event_number
0224 guidata(obj.figure, obj);
0225 else
0226 obj = pre;
0227 end