-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheegplugin_vised_marks.m
More file actions
216 lines (184 loc) · 7.61 KB
/
eegplugin_vised_marks.m
File metadata and controls
216 lines (184 loc) · 7.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
% eegplugin_vised_marks() -Include the appopriate path to access plugin
%functions and add the relevant vised_marks callbacks to EEGLAB GUI menu
%items at EEGLAB start time.
%
%
% Usage:
% >> eegplugin_vised_marks(fig,try_strings,catch_strings);
%
% Graphical Interface:
%This function adds the following menu items to the EEGLAB GUI at start
%time:
% File >
% vised configuration
% Edit >
% Visually edit in scroll plot
% Tools >
% Marks >
% Epoch/concatenate data >
% Epoch data into regular intervals
% Concatenate epochs into continuous data
% Edit marks >
% Collect "reject" structure into "marks" structure
% Mark flag gaps
% Mark event gaps
% Combine flag types
% Add/remove/clear marks flag type
% Select data
%
% Required Inputs:
% fig = handle of the main EEGLAB window
% try_string = see: https://sccn.ucsd.edu/wiki/A07:_Contributing_to_EEGLAB#Creating_an_eegplugin_function
% catch_string = see: https://sccn.ucsd.edu/wiki/A07:_Contributing_to_EEGLAB#Creating_an_eegplugin_function
%
% Optional Inputs:
%
% Outputs:
%
% Notes: This file is only called by eeglab.m at start time.
%
% Typical use:
%
% See also: eeglab, pop_vised
% Copyright (C) 2017 Brock University Cognitive and Affective Neuroscience Lab
%
% Code written by James A. Desjardins, Allan Campopiano, and Andrew Lofts
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program (LICENSE.txt file in the root directory); if not,
% write to the Free Software Foundation, Inc., 59 Temple Place,
% Suite 330, Boston, MA 02111-1307 USA
function version = eegplugin_vised_marks(fig, try_strings, catch_strings)
% Warn for pathing issues if need be...
folders = dir('./plugins/');
for i=1:length(folders)
if strcmp(folders(i).name,'VisEd1.05')
warning('Potential conflicts in function calls. Both VisEd and VisedMarks installed.');
end
end
version = get_version('vised_marks', 'vised_marks1.0.0');
% Adding to path. Skip property grid if it is already found.
currentDir = fileparts(which(mfilename()));
pathPiece = genpath(currentDir);
if exist('PropertyGrid')
warning('PropertyGrid was already found. Skipping.');
rmStr = [currentDir '/vised/external/PropertyGrid:'];
pathPiece = strrep(pathPiece,rmStr,'');
end
addpath(pathPiece);
%% vised
% find EEGLAB tools menu.
% ---------------------
filemenu=findobj(fig,'label','File');
editmenu=findobj(fig,'label','Edit');
% Create "pop_vised" callback cmd.
%---------------------------------------
VisEd_cmd='[EEG,LASTCOM] = pop_vised(EEG,''pop_gui'',''on'');';
finalcmdVE=[try_strings.no_check VisEd_cmd catch_strings.add_to_hist];
%CONFIG
try
uimenu(filemenu, 'Label', 'Vised configuration','separator','off', ...
'callback','vised_config=pop_edit_vised_config;','position',length(filemenu.Children) - 2);
catch
uimenu(filemenu, 'Label', 'Vised configuration','separator','off', ...
'callback','vised_config=pop_edit_vised_config;');
end
% add "Visual edit" submenu to the "Edit" menu.
%--------------------------------------------------------------------
uimenu(editmenu, 'label', 'Visually edit in scroll plot', 'callback', finalcmdVE);
%%marks
%--------------------------------------------------------------------------
% Get File menu handle...
%--------------------------------------------------------------------------
toolsmenu=findobj(fig,'Label','Tools');
%--------------------------------------------------------------------------
% Create "Batch" menu.
% -------------------------------------------------------------------------
marksmenu = uimenu( toolsmenu, 'Label', 'Marks','separator','on');
% -------------------------------------------------------------------------
% Create submenus
%--------------------------------------------------------------------------
%
cmd='[EEG,LASTCOM] = pop_continuous2epochs(EEG);';
finalcmdC2E=[try_strings.no_check cmd catch_strings.new_and_hist];
cmd='[EEG,LASTCOM] = pop_epochs2continuous(EEG);';
finalcmdE2C=[try_strings.no_check cmd catch_strings.new_and_hist];
cmd='LASTCOM=''EEG=reject2marks(EEG);'';eval(LASTCOM);';
finalcmdR2M=[try_strings.no_check cmd catch_strings.new_and_hist];
cmd='[EEG,LASTCOM]=pop_marks_flag_gap(EEG);';
finalcmdMFG=[try_strings.no_check cmd catch_strings.new_and_hist];
cmd='[EEG,LASTCOM]=pop_marks_event_gap(EEG);';
finalcmdMEG=[try_strings.no_check cmd catch_strings.new_and_hist];
cmd=['if ~isfield(EEG,''marks'');', ...
' if isempty(EEG.icaweights);', ...
' EEG.marks=marks_init(size(EEG.data));', ...
' else;', ...
' EEG.marks=marks_init(size(EEG.data),min(size(EEG.icaweights)));', ...
' end;', ...
'end;', ...
'[EEG,LASTCOM]=pop_marks_merge_labels(EEG);'];
finalcmdCFM=[try_strings.no_check cmd catch_strings.new_and_hist];
cmd=['if ~isfield(EEG,''marks'');', ...
' if isempty(EEG.icaweights);', ...
' EEG.marks=marks_init(size(EEG.data));', ...
' else;', ...
' EEG.marks=marks_init(size(EEG.data),min(size(EEG.icaweights)));', ...
' end;', ...
'end;', ...
'[EEG.marks]=pop_marks_add_label(EEG.marks);'];
finalcmdARF=[try_strings.no_check cmd catch_strings.new_and_hist];
cmd=['if ~isfield(EEG,''marks'');', ...
' if isempty(EEG.icaweights);', ...
' EEG.marks=marks_init(size(EEG.data));', ...
' else;', ...
' EEG.marks=marks_init(size(EEG.data),min(size(EEG.icaweights)));', ...
' end;', ...
'end;', ...
'EEG=pop_marks_select_data(EEG);'];
finalcmdMPD=[try_strings.no_check cmd catch_strings.new_and_hist];
% Add submenus to the "marks" submenu.
%-------------------------------------
epochmenu=uimenu(marksmenu,'label','epoch/concatenate data');
editmenu=uimenu(marksmenu,'label','edit marks');
uimenu(epochmenu,'label','Epoch data into regular intervals', ...
'callback',finalcmdC2E, ...
'userdata', 'startup:off;epoch:off;continuous:on');
uimenu(epochmenu,'label','Concatenate epochs into continuous data', ...
'callback',finalcmdE2C, ...
'userdata','startup:off;epoch:on;continuous:off');
uimenu(editmenu,'label','Collect ''reject'' structure into ''marks'' structure','callback',finalcmdR2M);
uimenu(editmenu,'label','Mark flag gaps','callback',finalcmdMFG);
uimenu(editmenu,'label','Mark event gaps','callback',finalcmdMEG);
uimenu(editmenu,'label','Combine flag types','callback',finalcmdCFM);
uimenu(editmenu,'label','Add/remove/clear marks flag type','callback',finalcmdARF);
uimenu(marksmenu,'label','Select data','callback',finalcmdMPD);
end
function version = get_version(prefix, fallback)
version = fallback;
[curdir, ~, ~] = fileparts(which(mfilename()));
versionpath = fullfile(curdir, 'VERSION');
if ~exist(versionpath, 'file')
return;
end
fid = fopen(versionpath);
if fid == -1
return;
end
text = deblank(fread(fid, '*char')');
fclose(fid);
if text(1) == 'v'
version = [prefix text(2:end)];
else
version = [prefix text];
end
end