-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRFXTController.m
More file actions
executable file
·296 lines (231 loc) · 9.5 KB
/
GRFXTController.m
File metadata and controls
executable file
·296 lines (231 loc) · 9.5 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
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
//
// GRFXTController.m
// Experiment
//
// Window with summary information trial events.
//
// Copyright (c) 2006. All rights reserved.
//
#define NoGlobals
#import "GRF.h"
#import "GRFXTController.h"
#define kPlotBinsDefault 10
#define kXTickSpacing 100
NSString *trialWindowVisibleKey = @"Trial Window Visible";
NSString *trialWindowZoomKey = @"Trial Window Zoom";
NSString *GRFXTAutosaveKey = @"GRFXTAutosave";
@implementation GRFXTController
- (IBAction)changeFreeze:(id)sender {
[xtView setFreeze:[sender intValue]];
[sender setTitle:([sender intValue]) ? @"Unfreeze" : @"Freeze"];
}
- (IBAction)changeZoom:(id)sender {
long zoomValue;
zoomValue = [[sender selectedCell] tag];
[self setScaleFactor:zoomValue / 100.0];
[[task defaults] setObject:[NSNumber numberWithInt:zoomValue]
forKey:trialWindowZoomKey];
}
- (id)init {
if ((self = [super initWithWindowNibName:@"GRFXTController"]) != nil) {
[self setShouldCascadeWindows:NO];
[self setWindowFrameAutosaveName:GRFXTAutosaveKey];
[self window]; // Force the window to load now
}
return self;
}
- (void) positionZoomButton {
NSRect scrollerRect, buttonRect;
scrollerRect = [[scrollView horizontalScroller] frame];
scrollerRect.size.width = [scrollView frame].size.width - scrollerRect.size.height - 8;
NSDivideRect(scrollerRect, &buttonRect, &scrollerRect, 60.0, NSMaxXEdge);
[[scrollView horizontalScroller] setFrame:scrollerRect];
[[scrollView horizontalScroller] setNeedsDisplay:YES];
buttonRect.origin.y += buttonRect.size.height; // Offset because the clipRect is flipped
buttonRect.origin = [[[self window] contentView] convertPoint:buttonRect.origin fromView:scrollView];
[zoomButton setFrame:NSInsetRect(buttonRect, 1.0, 1.0)];
[zoomButton setNeedsDisplay:YES];
}
- (void)processSampleData:(NSData *)data channel:(long)channel;
{
short *pSamples;
long sample, samples;
samples = [data length] / (sizeof(short));
pSamples = (short *)[data bytes];
for (sample = 0; sample < samples; sample++) {
[xtView sampleChannel:channel value:*pSamples++];
}
}
- (void)setScaleFactor:(float)newFactor;
{
float delta;
NSWindow *window;
NSSize baseViewSize, maxSize;
NSRect frame;
float scaleFactor;
// Calculate the current scaling. We can derive it from the current bounds and frame width relative to their
// original widths (which were the same (originally): baseContentViewWidthPix)
scaleFactor = (baseContentViewWidthPix / [[scrollView contentView] bounds].size.width) /
(baseContentViewWidthPix / [[scrollView contentView] frame].size.width);
if (scaleFactor != newFactor) {
delta = newFactor / scaleFactor;
[[scrollView contentView] scaleUnitSquareToSize:NSMakeSize(delta, delta)];
[self positionZoomButton];
[scrollView display];
}
// Always set the maxSize, because this is called at initialization
baseViewSize = [xtView sizePix];
window = [self window];
[window setMaxSize:NSMakeSize(baseViewSize.width * newFactor + staticWindowFrame.width,
baseViewSize.height * newFactor + staticWindowFrame.height)];
frame = [window frame];
maxSize = [window maxSize];
if (maxSize.width < frame.size.width || maxSize.height < frame.size.height) {
[window setFrame:NSMakeRect(frame.origin.x, frame.origin.y, maxSize.width, maxSize.height)
display:YES];
}
}
- (void)windowDidBecomeKey:(NSNotification *)aNotification;
{
[[task defaults] setObject:[NSNumber numberWithBool:YES] forKey:trialWindowVisibleKey];
}
- (void)windowDidLoad;
{
long index, defaultZoom, deltaHeight, deltaWidth;
NSSize baseScrollFrameSize, windowFrameSize, baseViewSize;
// [xtView setSamplePeriodMS:kSamplePeriodMS spikeChannels:kSpikeChannels spikeTickPerMS:kTimestampTickMS];
[xtView setDurationS:5.0]; // ?? This should be controlled by a dialog and saved in preferences.
// Calculate the base (1x scaling) content size for the window. We will use this for
// setting the maximum zoom size when the scale changes.
baseViewSize = [xtView sizePix]; // native size of the LLXTView
baseScrollFrameSize = [NSScrollView frameSizeForContentSize:baseViewSize // native size of frame for LLXTView
hasHorizontalScroller:YES hasVerticalScroller:YES borderType:[scrollView borderType]];
deltaWidth = baseScrollFrameSize.width - [scrollView frame].size.width; // allow for frame's current size
deltaHeight = baseScrollFrameSize.height - [scrollView frame].size.height;
windowFrameSize = [[self window] frame].size;
staticWindowFrame = NSMakeSize(windowFrameSize.width + deltaWidth - baseViewSize.width,
windowFrameSize.height + deltaHeight - baseViewSize.height);
[[zoomButton cell] setBordered:NO];
[[zoomButton cell] setBezeled:YES];
[[zoomButton cell] setFont:[NSFont labelFontOfSize:10.0]];
baseContentViewWidthPix = [[scrollView contentView] bounds].size.width;
defaultZoom = [[task defaults] integerForKey:trialWindowZoomKey];
for (index = 0; index < [[zoomButton itemArray] count]; index++) {
if ([[zoomButton itemAtIndex:index] tag] == defaultZoom) {
[zoomButton selectItemAtIndex:index];
[self setScaleFactor:defaultZoom / 100.0];
break;
}
}
[[self window] setFrameUsingName:GRFXTAutosaveKey]; // Needed when opened a second time
if ([[task defaults] boolForKey:trialWindowVisibleKey]) {
[[self window] makeKeyAndOrderFront:self];
}
else {
[NSApp addWindowsItem:[self window] title:[[self window] title] filename:NO];
}
[self positionZoomButton]; // position zoom must be after visible
[super windowDidLoad];
}
// We use a delegate method to detect when the window has resized, and
// adjust the postion of the zoom button when it does.
- (void) windowDidResize:(NSNotification *)aNotification {
[self positionZoomButton];
}
- (BOOL) windowShouldClose:(NSNotification *)aNotification {
[[self window] orderOut:self];
[[task defaults] setObject:[NSNumber numberWithBool:NO]
forKey:trialWindowVisibleKey];
[NSApp addWindowsItem:[self window] title:[[self window] title] filename:NO];
return NO;
}
// Methods related to data events follow:
/*
- (void)cueOn:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
[xtView stimulusBarColor:[NSColor yellowColor] eventTime:eventTime];
[xtView eventName:@"Cue" eventTime:eventTime];
}
*/
- (void)dataParam:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
DataParam *pParam = (DataParam *)[eventData bytes];
if (strcmp((char *)&pParam->dataName, "eyeRXData") == 0) {
[xtView setSamplePeriodMS:pParam->timing];
}
if (strcmp((char *)&pParam->dataName, "eyeRYData") == 0) {
[xtView setSamplePeriodMS:pParam->timing];
}
if (strcmp((char *)&pParam->dataName, "spike0") == 0) {
[xtView setSpikePeriodMS:pParam->timing];
}
}
- (void)eyeRXData:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
[self processSampleData:eventData channel:0];
}
- (void)eyeRYData:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
[self processSampleData:eventData channel:1];
}
- (void)eyeWindow:(NSData *)eventData eventTime:(NSNumber *)eventTime {
FixWindowData fixWindowData;
[eventData getBytes:&fixWindowData];
[xtView eyeRect:fixWindowData.windowUnits time:[eventTime longValue]];
}
- (void)fixate:(NSData *)eventData eventTime:(NSNumber *)eventTime {
[xtView eventName:@"Fixate" eventTime:eventTime];
}
- (void)leverDown:(NSData *)eventData eventTime:(NSNumber *)eventTime {
[xtView eventName:@"Lever" eventTime:eventTime];
}
- (void)preStimuli:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
[xtView stimulusBarColor:[NSColor whiteColor] eventTime:eventTime];
}
- (void)reset:(NSData *)eventData eventTime:(NSNumber *)eventTime {
[xtView reset:[eventTime longValue]];
}
- (void)sampleZero:(NSData *)eventData eventTime:(NSNumber *)eventTime {
[xtView sampleZeroTimeMS:[eventTime longValue]];
}
- (void)spike:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
long spike, spikes;
TimestampData *pSpikes;
pSpikes = (TimestampData *)[eventData bytes];
spikes = [eventData length] / sizeof(TimestampData);
for (spike = 0; spike < spikes; spike++, pSpikes++) {
[xtView spikeChannel:pSpikes->channel time:pSpikes->time];
}
}
- (void) spikeZero:(NSData *)eventData eventTime:(NSNumber *)eventTime {
[xtView spikeZeroTimeMS:[eventTime longValue]];
}
- (void)stimulus:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
StimDesc stimDesc;
[eventData getBytes:&stimDesc];
[xtView stimulusBarColor:[NSColor grayColor] eventTime:eventTime];
if (stimDesc.stimType == kTargetStim) {
[xtView eventName:[NSString stringWithFormat:@"Valid %.0f deg", stimDesc.directionDeg]
eventTime:eventTime];
}
else if (stimDesc.stimType == kTargetStim) {
[xtView eventName:[NSString stringWithFormat:@"Invalid %.0f deg", stimDesc.directionDeg]
eventTime:eventTime];
}
}
- (void)stimulusOff:(NSData *)eventData eventTime:(NSNumber *)eventTime {
[xtView stimulusBarColor:[NSColor whiteColor] eventTime:eventTime];
}
- (void) trialEnd:(NSData *)eventData eventTime:(NSNumber *)eventTime {
long eotCode;
[eventData getBytes:&eotCode];
[xtView eventName:[LLStandardDataEvents trialEndName:eotCode] eventTime:eventTime];
[xtView stimulusBarColor:[NSColor whiteColor] eventTime:eventTime];
}
- (void) trialStart:(NSData *)eventData eventTime:(NSNumber *)eventTime {
[xtView eventName:@"Trial start" eventTime:eventTime];
}
@end