-
Notifications
You must be signed in to change notification settings - Fork 2
/
SpokeController.m
382 lines (272 loc) · 13 KB
/
SpokeController.m
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
classdef SpokeController < most.Controller;
%SPIKEGRIDCONTROLLER Controller class for Spoke application, managing the GUI and configuration file interfaces
%% ABSTRACT PROPERTY REALIZATIONS (most.Controller)
properties (SetAccess=protected)
propBindings = lclInitPropBindings();
end
%% VISIBLE PROPERTIES
properties (AbortSet)
filterEnable; %Logical specifying whether
filterWindowSpec = [300 8e3]; %Specification of filterWindow to use when filterEnable=true. When filterEnable=false, property is unchanged, while model filterWindow = [0 inf].
end
properties (SetAccess=protected)
stimEventClassifyFcnPath = ''; %Path of stimEventClassifyFcn last-specified via changeStimEventClassifyFcn
end
%% HIDDEN PROPERTIES
properties (Hidden,Dependent)
stimEventDisplayTypes; %Same as model stimEventTypes with 'all' appended to end
stimEventDisplayAllTypes;
end
%% CONSTRUCTOR/DESTRUCTOR
methods
function obj = SpokeController(hModel)
obj = [email protected](hModel,{'SpikeGrid'},{});
set(obj.hGUIs.SpikeGrid,'Name','Spoke Grid Control');
end
function initialize(obj)
[email protected](obj);
figure(obj.hGUIs.SpikeGrid);
end
end
%% PROPERTY ACCESS
methods
function set.filterEnable(obj,val)
validateattributes(val,{'logical'},{'scalar'});
obj.filterEnable = val;
%Side-effects
obj.changeFilterSpec();
end
function set.filterWindowSpec(obj,val)
validateattributes(val,{'numeric'},{'nonnegative' 'numel' 2});
assert(val(2) > val(1), 'Property filterWindowSpec of class %s must be a 2 element array arranged in ascending order',mfilename('class'));
obj.filterWindowSpec = val;
%Side-effects
obj.changeFilterSpec();
end
function val = get.stimEventDisplayTypes(obj)
if isempty(obj.hModel.stimEventTypes)
val = {};
else
val = [obj.hModel.stimEventTypes {'all'}];
end
end
function val = get.stimEventDisplayAllTypes(obj)
val = iscell(obj.hModel.stimEventTypesDisplayed) && length(obj.hModel.stimEventTypesDisplayed) == length(obj.hModel.stimEventTypes);
end
end
%% HIDDEN METHODS
methods (Hidden)
function changedDisplayMode(obj,~,~)
rasterControls = {'pbStimClassify' 'pmStimEventTypeDisplayed'};
switch obj.hModel.displayMode
case 'waveform'
set(obj.hGUIData.SpikeGrid.rbWaveformDisplay,'Value',1);
set(obj.hGUIData.SpikeGrid.rbRasterDisplay,'Value',0);
set(obj.hGUIData.SpikeGrid.pmSpikeDisplayUnits,'Enable','on');
set(obj.hGUIData.SpikeGrid.pmStimEventTypeDisplayed,'Enable','off');
case 'raster'
set(obj.hGUIData.SpikeGrid.rbWaveformDisplay,'Value',0);
set(obj.hGUIData.SpikeGrid.rbRasterDisplay,'Value',1);
set(obj.hGUIData.SpikeGrid.pmSpikeDisplayUnits,'Enable','off');
%Enable StimEvenTypeDisplayed menu based on whether event types are being used or not
obj.changedStimEventClassifyFcn();
end
%Update pbStimClassify state
obj.pbStimClassifyUpdate();
end
function changeFilterSpec(obj)
if obj.filterEnable
obj.hModel.filterWindow = obj.filterWindowSpec;
else
obj.hModel.filterWindow = [0 inf];
end
set(obj.hGUIData.SpikeGrid.etFilterWindow,'String',mat2str(obj.filterWindowSpec));
set(obj.hGUIData.SpikeGrid.cbFilterData,'Value',obj.filterEnable);
end
function changedFilterWindow(obj,~,~)
if isequal(obj.hModel.filterWindow(:),[0;inf])
obj.filterEnable = false;
else
obj.filterWindowSpec = obj.hModel.filterWindow;
obj.filterEnable = true;
end
end
function changedMaxNumWaveformsApplied(obj,~,~)
if obj.hModel.maxNumWaveformsApplied
set(obj.hGUIData.SpikeGrid.etThresholdVal,'ForegroundColor',[.8 0 0]);
else
set(obj.hGUIData.SpikeGrid.etThresholdVal,'ForegroundColor',[0 0 0]);
end
end
function changeTabDisplayed(obj,newVal)
try
obj.hModel.tabDisplayed = newVal;
catch ME
obj.changedTabDisplayed();
end
end
function changedTabDisplayed(obj,~,~)
for i=1:obj.hModel.MAX_NUM_TABS
if i == obj.hModel.tabDisplayed
set(obj.hGUIData.SpikeGrid.(sprintf('tbTab%d',i)),'Value',1);
else
set(obj.hGUIData.SpikeGrid.(sprintf('tbTab%d',i)),'Value',0);
end
end
end
function changeRunning(obj)
if obj.hModel.running
obj.hModel.stop();
else
obj.hModel.start();
end
end
function changedRunning(obj,~,~)
if obj.hModel.running
set(obj.hGUIData.SpikeGrid.pbStartOrStop,'String','Stop','BackgroundColor',[.8 0 0]);
else
set(obj.hGUIData.SpikeGrid.pbStartOrStop,'String','Start','BackgroundColor',[0 .8 0]);
end
obj.pbStimClassifyUpdate();
end
function changeStimEventTypesDisplayed(obj,src)
assert(~isempty(obj.hModel.stimEventClassifyFcn));
idx = get(src,'Value');
eventType = obj.stimEventDisplayTypes{idx};
if strcmpi(eventType,'all')
obj.hModel.stimEventTypesDisplayed = obj.hModel.stimEventTypes;
else
obj.hModel.stimEventTypesDisplayed = eventType;
end
%Update pbStimClassify state
obj.pbStimClassifyUpdate();
end
function changedStimEventTypesDisplayed(obj,~,~)
if isempty(obj.hModel.stimEventTypesDisplayed)
assert(isempty(obj.hModel.stimEventTypes));
set(obj.hGUIData.SpikeGrid.pmStimEventTypeDisplayed,'Value',1); %should already be the case, but do it here anyway
else
[tf,loc] = ismember(obj.hModel.stimEventTypesDisplayed,obj.stimEventDisplayTypes);
assert(all(tf),'Unexpected value for SpikeGrid ''stimEventTypesDisplayed'' property'); %Not really needed, but done anyway...
if isscalar(tf)
set(obj.hGUIData.SpikeGrid.pmStimEventTypeDisplayed,'Value',loc);
else
numEventTypes = length(obj.hModel.stimEventTypes);
assert(length(tf) == numEventTypes); %Not really needed, but done anyway..
set(obj.hGUIData.SpikeGrid.pmStimEventTypeDisplayed,'Value',numEventTypes + 1); %Select 'all' option
end
end
end
function pbStimClassifyPressed(obj)
%If button is available while running, must be in rastergram display-all-types mode
if obj.hModel.running
obj.hModel.sortRastergram();
else
%Update model's stimEventClassifyFcn
[f,p] = uigetfile('*.m','Select Stim Classification Function',obj.stimEventClassifyFcnPath);
if isnumeric(f) && f==0
obj.hModel.stimEventClassifyFcn = [];
obj.stimEventClassifyFcnPath = '';
else
currDir = cd();
exception = [];
try
cd(p);
[~,f] = fileparts(f);
obj.hModel.stimEventClassifyFcn = str2func(f);
obj.stimEventClassifyFcnPath = p;
catch ME
exception = ME;
end
cd(currDir);
if ~isempty(exception)
obj.hModel.stimEventClassifyFcn = [];
obj.stimEventClassifyFcnPath = '';
throw(exception);
end
end
end
end
function pbStimClassifyUpdate(obj)
rasterMode = strcmpi(obj.hModel.displayMode,'raster');
hButton = obj.hGUIData.SpikeGrid.pbStimClassify;
if obj.hModel.running
if rasterMode
if obj.stimEventDisplayAllTypes
set(hButton,'String','Stim Sort','Enable','on');
else
set(hButton,'String','Stim Classify...','Enable','off');
end
end
else
set(hButton,'String','Stim Classify...');
if rasterMode
set(hButton,'Enable','on');
else
set(hButton,'Enable','off');
end
end
end
function changedStimEventClassifyFcn(obj,~,~)
if isempty(obj.hModel.stimEventTypes)
set(obj.hGUIData.SpikeGrid.pmStimEventTypeDisplayed,'Enable','off','String',' ','Value',1);
else
set(obj.hGUIData.SpikeGrid.pmStimEventTypeDisplayed,'Enable','on','String',obj.stimEventDisplayTypes);
end
obj.stimEventClassifyFcnPath = ''; %Don't store path generally -- only when stimEventClassifyFcn is set via this Controller class
end
function stepThresholdVal(obj,direction)
%Direction: 1 to increment, -1 to decrement
switch obj.hModel.thresholdType
case 'volts' %step in millivolts
if direction == 1
obj.hModel.thresholdVal = obj.hModel.thresholdVal + .001;
else
obj.hModel.thresholdVal = obj.hModel.thresholdVal - .001;
end
case 'rmsMultiple' %stop in multiple units
if direction == 1
obj.hModel.thresholdVal = obj.hModel.thresholdVal + 1;
else
obj.hModel.thresholdVal = obj.hModel.thresholdVal - 1;
end
end
end
end
end
function s = lclInitPropBindings()
s = struct();
s.thresholdVal = struct('GuiIDs',{{'SpikeGrid','etThresholdVal'}});
s.globalMeanSubtraction = struct('GuiIDs',{{'SpikeGrid','cbGlobalMeanSubtract'}});
s.displayMode = struct('Callback','changedDisplayMode');
s.filterWindow = struct('Callback','changedFilterWindow');
s.maxNumWaveformsApplied = struct('Callback','changedMaxNumWaveformsApplied');
s.tabDisplayed = struct('Callback','changedTabDisplayed');
s.running = struct('Callback','changedRunning');
s.stimEventClassifyFcn = struct('Callback','changedStimEventClassifyFcn');
s.stimEventTypesDisplayed = struct('Callback','changedStimEventTypesDisplayed');
s.thresholdType = struct('GuiIDs',{{'SpikeGrid','pmThresholdUnits'}});
s.waveformAmpUnits = struct('GuiIDs',{{'SpikeGrid','pmSpikeDisplayUnits'}});
s.psthTimeBin = struct('GuiIDs',{{'SpikeGrid','etTimeBinMs'}},'ViewScaling',1000);
s.psthAmpRange = struct('GuiIDs',{{'SpikeGrid','etPSTHAmpRange'}});
%frequently-adjusted property table bindings
s.verticalRange = struct('GuiIDs',{{'SpikeGrid','pcFreqAdjustProps'}},'PropControlData',struct('format','char'));
s.horizontalRange = struct('GuiIDs',{{'SpikeGrid','pcFreqAdjustProps'}},'PropControlData',struct('format','char'));
s.waveformsPerPlot = struct('GuiIDs',{{'SpikeGrid','pcFreqAdjustProps'}},'PropControlData',struct('format','numeric'));
s.verticalRangeRaster = struct('GuiIDs',{{'SpikeGrid','pcFreqAdjustProps'}},'PropControlData',struct('format','numeric'));
s.refreshPeriodMaxWaveformRate = struct('GuiIDs',{{'SpikeGrid','pcFreqAdjustProps'}},'PropControlData',struct('format','numeric'));
s.refreshRate = struct('GuiIDs',{{'SpikeGrid','pcFreqAdjustProps'}},'PropControlData',struct('format','numeric'));
%rarely-adjusted property table bindings
%s.numAuxChans = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','numeric'));
s.stimStartChannel = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','numeric'));
s.stimStartThreshold = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','numeric'));
s.horizontalRangeRaster = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','numeric'));
s.verticalRangeRasterInfIncrement = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','numeric'));
s.waveformsPerPlotClearMode = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','char'));
s.baselineStatsRefreshPeriod = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','numeric'));
%s.baselineStatsRefreshOnRetrigger = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','numeric'));
s.thresholdAbsolute = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','logical'));
s.psthTimerPeriod = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','numeric'));
%s.spikeAmpUnits = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','char'));
%s.stimEventTypeDisplayed = struct('GuiIDs',{{'SpikeGrid','pcRareAdjustProps'}},'PropControlData',struct('format','char'));
end