-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathet_compare.m
2334 lines (2065 loc) · 95.3 KB
/
et_compare.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [cfg,expParam] = et_compare(w,cfg,expParam,logFile,sesName,phaseName,phaseCount)
% function [cfg,expParam] = et_compare(w,cfg,expParam,logFile,sesName,phaseName,phaseCount)
%
% Description:
% This function runs the comparison task. There are no blocks, only short
% (blink) breaks.
% TODO: Maybe add a longer break in the middle and tell subjects that this
% is the middle of the experiment.
%
% The stimuli for the comparison task must already be in presentation
% order. They are stored in
% expParam.session.(sesName).(phaseName).viewStims, btSpeciesStims, and
% wiSpeciesStims as structs.
%
%
% Inputs:
%
%
% Outputs:
%
%
%
% NB:
% Once agian, stimuli must already be sorted in presentation order!
%
% NB:
% Field 'compStimNum' denotes whether a stimulus is stim1 or stim2.
% Field 'compPairNum' denotes which two stimuli are paired.
%
% NB:
% to find the corresponding pair member, search for the same compPairNum
% and the opposite compStimNum (1 or 2).
% % keys
% cfg.keys.compareKeyNames, encoded as:
% cfg.keys.c01
% cfg.keys.c02
% cfg.keys.c03
% cfg.keys.c04
% cfg.keys.c05
fprintf('Running %s %s (compare) (%d)...\n',sesName,phaseName,phaseCount);
phaseNameForParticipant = 'comparison';
%% set the starting date and time for this phase
thisDate = date;
startTime = fix(clock);
startTime = sprintf('%.2d:%.2d:%.2d',startTime(4),startTime(5),startTime(6));
%% main phase progress file
% set up progress file, to resume this phase in case of a crash, etc.
mainPhaseProgressFile = fullfile(cfg.files.sesSaveDir,sprintf('phaseProgress_%s_%s_comp_%d.mat',sesName,phaseName,phaseCount));
if exist(mainPhaseProgressFile,'file')
load(mainPhaseProgressFile);
else
phaseComplete = false; %#ok<NASGU>
save(mainPhaseProgressFile,'thisDate','startTime','phaseComplete');
end
%% start the log file for this phase
phaseLogFile = fullfile(cfg.files.sesSaveDir,sprintf('phaseLog_%s_%s_comp_%d.txt',sesName,phaseName,phaseCount));
phLFile = fopen(phaseLogFile,'at');
%% record the starting date and time for this phase
expParam.session.(sesName).(phaseName)(phaseCount).date = thisDate;
expParam.session.(sesName).(phaseName)(phaseCount).startTime = startTime;
% put it in the log file
fprintf(logFile,'!!! Start of %s %s (%d) (%s) %s %s\n',sesName,phaseName,phaseCount,mfilename,thisDate,startTime);
fprintf(phLFile,'!!! Start of %s %s (%d) (%s) %s %s\n',sesName,phaseName,phaseCount,mfilename,thisDate,startTime);
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',...
thisGetSecs,...
expParam.subject,...
sesName,...
phaseName,...
phaseCount,...
cfg.stim.(sesName).(phaseName)(phaseCount).isExp,...
'PHASE_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',...
thisGetSecs,...
expParam.subject,...
sesName,...
phaseName,...
phaseCount,...
cfg.stim.(sesName).(phaseName)(phaseCount).isExp,...
'PHASE_START');
%% preparation
phaseCfg = cfg.stim.(sesName).(phaseName)(phaseCount);
if phaseCfg.isExp
stimDir = cfg.files.stimDir;
else
stimDir = cfg.files.stimDir_prac;
end
% default is to preload the images
if ~isfield(cfg.stim,'preloadImages')
cfg.stim.preloadImages = false;
end
% default is to not print out trial details
if ~isfield(cfg.text,'printTrialInfo') || isempty(cfg.text.printTrialInfo)
cfg.text.printTrialInfo = false;
end
% default is to not play sounds
if ~isfield(phaseCfg,'playSound') || isempty(phaseCfg.playSound)
phaseCfg.playSound = false;
end
% initialize beep player if needed
if phaseCfg.playSound
Beeper(1,0);
if ~isfield(phaseCfg,'correctSound')
phaseCfg.correctSound = 1000;
end
if ~isfield(phaseCfg,'incorrectSound')
phaseCfg.incorrectSound = 300;
end
if ~isfield(phaseCfg,'correctVol')
phaseCfg.correctVol = 0.4;
end
if ~isfield(phaseCfg,'incorrectVol')
phaseCfg.incorrectVol = 0.6;
end
end
% are they allowed to respond while the stimulus is on the screen?
if ~isfield(phaseCfg,'respDuringStim')
phaseCfg.respDuringStim = true;
end
% default is to show fixation during ISI
if ~isfield(phaseCfg,'fixDuringISI')
phaseCfg.fixDuringISI = true;
end
% default is to show fixation during preStim
if ~isfield(phaseCfg,'fixDuringPreStim')
phaseCfg.fixDuringPreStim = true;
end
% default is to show fixation with the stimulus
if ~isfield(phaseCfg,'fixDuringStim')
phaseCfg.fixDuringStim = true;
end
if ~isfield(cfg.text,'respReminder')
cfg.text.respReminder = true;
end
% whether to ask the participant if they have any questions; only continues
% with experimenter's secret key
if ~isfield(phaseCfg.instruct,'questions')
phaseCfg.instruct.questions = true;
end
% whether to present a white square during the stimulus and a black square
% at all other times
if ~isfield(cfg.stim,'photoCell')
cfg.stim.photoCell = false;
end
%% set up text rectangles
% create a rectangle for placing fixation symbol using Screen('DrawText')
Screen('TextSize', w, cfg.text.fixSize);
fixRect = Screen('TextBounds', w, cfg.text.fixSymbol);
% center it in the middle of the screen
fixRect = CenterRect(fixRect, cfg.screen.wRect);
% get the X and Y coordinates
fixRectX = fixRect(1);
fixRectY = fixRect(2);
% create a rectangle for placing response symbol using Screen('DrawText')
Screen('TextSize', w, cfg.text.fixSize);
respRect = Screen('TextBounds', w, cfg.text.respSymbol);
% center it in the middle of the screen
respRect = CenterRect(respRect, cfg.screen.wRect);
% get the X and Y coordinates
respRectX = respRect(1);
respRectY = respRect(2);
if cfg.text.respReminder
% create a rectangle for placing response reminder using Screen('DrawText')
Screen('TextSize', w, cfg.text.instructTextSize);
respReminderRect = Screen('TextBounds', w, cfg.text.respReminderText);
% center it in the bottom middle of the screen
respReminderRect = AlignRect(respReminderRect,cfg.screen.wRect,'center','bottom');
% get the X and Y coordinates
respReminderRectX = respReminderRect(1);
respReminderRectY = respReminderRect(2);
%respReminderRectY = cfg.screen.wRect(RectBottom) - (cfg.screen.wRect(RectBottom) * 0.05);
end
%% do an impedance check before the phase begins, if desired
if ~isfield(phaseCfg,'impedanceBeforePhase')
phaseCfg.impedanceBeforePhase = false;
end
if ~expParam.photoCellTest && expParam.useNS && phaseCfg.impedanceBeforePhase
% run the impedance break
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
thisGetSecs = et_impedanceCheck(w, cfg, false, phaseName);
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
end
%% start NS recording, if desired
% put a message on the screen as experiment phase begins
message = sprintf('Starting %s phase...',phaseNameForParticipant);
if expParam.useNS
% start recording
[NSStopStatus, NSStopError] = NetStation('StartRecording'); %#ok<NASGU,ASGLU>
% synchronize
[NSSyncStatus, NSSyncError] = NetStation('Synchronize'); %#ok<NASGU,ASGLU>
message = sprintf('Starting data acquisition for %s phase...',phaseNameForParticipant);
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'NS_REC_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'NS_REC_START');
end
Screen('TextSize', w, cfg.text.basicTextSize);
% draw message to screen
DrawFormattedText(w, message, 'center', 'center', cfg.text.basicTextColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
% put it on
Screen('Flip', w);
% Wait before starting trial
WaitSecs(5.000);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
% Clear screen to background color (our 'bgColor' as set at the beginning):
Screen('Flip', w);
%% determine the starting trial, useful for resuming - viewing
% set up progress file, to resume this phase in case of a crash, etc.
phaseProgressFile = fullfile(cfg.files.sesSaveDir,sprintf('phaseProgress_%s_%s_comp_view_%d.mat',sesName,phaseName,phaseCount));
if exist(phaseProgressFile,'file')
load(phaseProgressFile);
else
trialComplete = false(1,length(expParam.session.(sesName).(phaseName)(phaseCount).viewStims));
phaseComplete = false; %#ok<NASGU>
save(phaseProgressFile,'thisDate','startTime','trialComplete','phaseComplete');
end
% find the starting trial
incompleteTrials = find(~trialComplete);
if ~isempty(incompleteTrials)
trialNum = incompleteTrials(1);
runView = true;
else
fprintf('All trials for %s %s (comp) (%d) have been completed. Moving on to next phase...\n',sesName,phaseName,phaseCount);
% release any remaining textures
Screen('Close');
runView = false;
end
if runView
%% preload viewing stimuli for presentation
viewStims = expParam.session.(sesName).(phaseName)(phaseCount).viewStims;
if cfg.stim.preloadImages
message = sprintf('Preparing part 1 images, please wait...');
Screen('TextSize', w, cfg.text.basicTextSize);
% put the "preparing" message on the screen
DrawFormattedText(w, message, 'center', 'center', cfg.text.instructColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
% Update the display to show the message:
Screen('Flip', w);
% initialize
vStimTex = nan(1,length(viewStims));
for i = 1:length(viewStims)
% make sure this stimulus exists
vStimImgFile = fullfile(stimDir,viewStims(i).familyStr,viewStims(i).fileName);
if exist(vStimImgFile,'file')
if cfg.stim.preloadImages
% load up this stim's texture
vStimImg = imread(vStimImgFile);
vStimTex(i) = Screen('MakeTexture',w,vStimImg);
% TODO: optimized?
%vStimTex(i) = Screen('MakeTexture',w,vStimImg,[],1);
elseif ~cfg.stim.preloadImages && i == length(viewStims)
% still need to load the last image to set the rectangle
vStimImg = imread(fullfile(stimDir,viewStims(i).familyStr,viewStims(i).fileName));
end
else
error('Study stimulus %s does not exist!',vStimImgFile);
end
end
% get the width and height of the final stimulus image
stimImgHeight = size(vStimImg,1) * cfg.stim.stimScale;
stimImgWidth = size(vStimImg,2) * cfg.stim.stimScale;
stimImgRect = [0 0 stimImgWidth stimImgHeight];
stimImgRect = CenterRect(stimImgRect,cfg.screen.wRect);
%% show the instructions - view
if ~expParam.photoCellTest
for i = 1:length(phaseCfg.instruct.compView)
WaitSecs(1.000);
et_showTextInstruct(w,cfg,phaseCfg.instruct.compView(i),cfg.keys.instructContKey,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
end
% Wait a second before starting trial
WaitSecs(1.000);
end
%% questions? only during practice. continues with experimenter's key.
if ~expParam.photoCellTest && ~phaseCfg.isExp && phaseCfg.instruct.questions
questionsMsg.text = sprintf('If you have any questions about the %s phase (part 1), please ask the experimenter now.\n\nPlease tell the experimenter when you are ready to begin the task.',phaseNameForParticipant);
et_showTextInstruct(w,cfg,questionsMsg,cfg.keys.expContinue,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
% Wait a second before continuing
WaitSecs(1.000);
end
%% let them start when they're ready
if ~expParam.photoCellTest
if phaseCfg.isExp
expStr = '';
else
expStr = ' practice';
end
readyMsg.text = sprintf('Ready to begin%s %s phase (part 1).\nPress "%s" to start.',expStr,phaseNameForParticipant,cfg.keys.instructContKey);
et_showTextInstruct(w,cfg,readyMsg,cfg.keys.instructContKey,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
% Wait a second before starting trial
WaitSecs(1.000);
end
%% run the comparison - view task
% start the blink break timer
if phaseCfg.isExp && cfg.stim.secUntilBlinkBreak > 0
blinkTimerStart = GetSecs;
end
for i = trialNum:length(viewStims)
% do an impedance check after a certain number of blocks or trials
if ~expParam.photoCellTest && expParam.useNS && phaseCfg.isExp && i > 1 && i < length(viewStims) && mod((i - 1),phaseCfg.impedanceAfter_nTrials) == 0
% run the impedance break
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
thisGetSecs = et_impedanceCheck(w, cfg, true, phaseName);
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
% show preparation text
DrawFormattedText(w, 'Get ready...', 'center', 'center', cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
WaitSecs(2.0);
if (phaseCfg.comp_view_isi > 0 && phaseCfg.fixDuringISI) || (phaseCfg.comp_view_isi == 0 && phaseCfg.fixDuringPreStim)
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
WaitSecs(1.0);
% reset the blink timer
if cfg.stim.secUntilBlinkBreak > 0
blinkTimerStart = GetSecs;
end
end
% Do a blink break if specified time has passed
if ~expParam.photoCellTest && phaseCfg.isExp && cfg.stim.secUntilBlinkBreak > 0 && (GetSecs - blinkTimerStart) >= cfg.stim.secUntilBlinkBreak && i > 3 && i < (length(viewStims) - 3)
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_START');
Screen('TextSize', w, cfg.text.basicTextSize);
if expParam.useNS
pauseMsg = 'Blink now.\n\n';
else
pauseMsg = '';
end
pauseMsg = sprintf('%sReady for trial %d of %d.\nPress any key to continue.', pauseMsg, i, length(viewStims));
% just draw straight into the main window since we don't need speed here
DrawFormattedText(w, pauseMsg, 'center', 'center', cfg.text.instructColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
thisGetSecs = KbWait(-1,2);
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_END');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_END');
% show preparation text
DrawFormattedText(w, 'Get ready...', 'center', 'center', cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
WaitSecs(2.0);
if (phaseCfg.comp_view_isi > 0 && phaseCfg.fixDuringISI) || (phaseCfg.comp_view_isi == 0 && phaseCfg.fixDuringPreStim)
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
WaitSecs(1.0);
% reset the timer
blinkTimerStart = GetSecs;
end
% load the stimulus now if we didn't load it earlier
if ~cfg.stim.preloadImages
vStimImg = imread(fullfile(stimDir,viewStims(i).familyStr,viewStims(i).fileName));
vStimTex(i) = Screen('MakeTexture',w,vStimImg);
end
% resynchronize netstation before the start of drawing
if expParam.useNS
[NSSyncStatus, NSSyncError] = NetStation('Synchronize'); %#ok<NASGU,ASGLU>
end
fNum = int32(viewStims(i).familyNum);
specNum = int32(viewStims(i).speciesNum);
% ISI between trials
if phaseCfg.comp_view_isi > 0
if phaseCfg.fixDuringISI
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
end
WaitSecs(phaseCfg.comp_view_isi);
end
% preStimulus period, with fixation if desired
if length(phaseCfg.comp_view_preStim) == 1
if phaseCfg.comp_view_preStim > 0
if phaseCfg.fixDuringPreStim
% draw fixation
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
[preStimFixOn] = Screen('Flip',w);
else
preStimFixOn = NaN;
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
end
WaitSecs(phaseCfg.comp_view_preStim);
end
elseif length(phaseCfg.comp_view_preStim) == 2
if ~all(phaseCfg.comp_view_preStim == 0)
if phaseCfg.fixDuringPreStim
% draw fixation
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
[preStimFixOn] = Screen('Flip',w);
else
preStimFixOn = NaN;
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
end
% fixation on screen before stim for a random amount of time
WaitSecs(phaseCfg.comp_view_preStim(1) + ((phaseCfg.comp_view_preStim(2) - phaseCfg.comp_view_preStim(1)).*rand(1,1)));
end
end
% draw the stimulus
Screen('DrawTexture', w, vStimTex(i), [], stimImgRect);
if phaseCfg.fixDuringStim
% and fixation on top of it
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
% photocell rect with stim
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellRectColor, cfg.stim.photoCellRect);
end
% Show stimulus on screen at next possible display refresh cycle,
% and record stimulus onset time in 'stimOnset':
[imgOn, stimOnset] = Screen('Flip', w);
if cfg.text.printTrialInfo
fprintf('Trial %d of %d: %s, species num: %d.\n',i,length(viewStims),viewStims(i).fileName,specNum);
end
% while loop to show stimulus until "duration" seconds elapse.
while (GetSecs - stimOnset) <= phaseCfg.comp_view_stim
% Wait <1 ms before checking the keyboard again to prevent
% overload of the machine at elevated Priority():
WaitSecs(0.0001);
end
% Clear screen to background color, with fixation if desired
if (phaseCfg.comp_view_isi > 0 && phaseCfg.fixDuringISI) || (phaseCfg.comp_view_isi == 0 && phaseCfg.fixDuringPreStim)
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
% Close this stimulus before next trial
Screen('Close', vStimTex(i));
%% session log file
% Write stimulus presentation to file:
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\t%d\t%s\t%s\t%d\t%d\t%d\n',...
imgOn,...
expParam.subject,...
sesName,...
phaseName,...
phaseCount,...
phaseCfg.isExp,...
'COMP_VIEW_STIM',...
i,...
viewStims(i).familyStr,...
viewStims(i).speciesStr,...
viewStims(i).exemplarName,...
fNum,...
specNum);
%% phase log file
% Write stimulus presentation to file:
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\t%d\t%s\t%s\t%d\t%d\t%d\n',...
imgOn,...
expParam.subject,...
sesName,...
phaseName,...
phaseCount,...
phaseCfg.isExp,...
'COMP_VIEW_STIM',...
i,...
viewStims(i).familyStr,...
viewStims(i).speciesStr,...
viewStims(i).exemplarName,...
fNum,...
specNum);
%% Write netstation logs
if expParam.useNS
% Write trial info to et_NetStation
% mark every event with the following key code/value pairs
% 'subn', subject number
% 'sess', session type
% 'phas', session phase name
% 'pcou', phase count
% 'expt', whether this is the experiment (1) or practice (0)
% 'part', which part of the experiment we're in
% 'trln', trial number
% 'stmn', stimulus name (family, species, exemplar)
% 'famn', family number
% 'spcn', species number (corresponds to keyboard)
% write out the stimulus name
stimName = sprintf('%s%s%d',...
viewStims(i).familyStr,...
viewStims(i).speciesStr,...
viewStims(i).exemplarName);
if ~isnan(preStimFixOn)
% pretrial fixation
[NSEventStatus, NSEventError] = NetStation('Event', 'FIXT', preStimFixOn, .001,...
'subn', expParam.subject, 'sess', sesName, 'phas', phaseName, 'pcou', int32(phaseCount),...
'expt',phaseCfg.isExp, 'part', 'view', 'trln', int32(i),...
'stmn', stimName, 'famn', fNum, 'spcn', specNum); %#ok<NASGU,ASGLU>
end
% img presentation
[NSEventStatus, NSEventError] = NetStation('Event', 'STIM', imgOn, .001,...
'subn', expParam.subject, 'sess', sesName, 'phas', phaseName, 'pcou', int32(phaseCount),...
'expt',phaseCfg.isExp, 'part', 'view', 'trln', int32(i),...
'stmn', stimName, 'famn', fNum, 'spcn', specNum); %#ok<NASGU,ASGLU>
end % useNS
% mark that we finished this trial
trialComplete(i) = true;
% save progress after each trial
save(phaseProgressFile,'thisDate','startTime','trialComplete','phaseComplete');
end
% cleanup
endTime = fix(clock);
endTime = sprintf('%.2d:%.2d:%.2d',endTime(4),endTime(5),endTime(6)); %#ok<NASGU>
% save progress after finishing phase
phaseComplete = true; %#ok<NASGU>
save(phaseProgressFile,'thisDate','startTime','trialComplete','phaseComplete','endTime');
end
%% determine the starting trial, useful for resuming - between species
% set up progress file, to resume this phase in case of a crash, etc.
phaseProgressFile = fullfile(cfg.files.sesSaveDir,sprintf('phaseProgress_%s_%s_comp_bt_%d.mat',sesName,phaseName,phaseCount));
if exist(phaseProgressFile,'file')
load(phaseProgressFile);
else
trialComplete = false(1,length(expParam.session.(sesName).(phaseName)(phaseCount).btSpeciesStims([expParam.session.(sesName).(phaseName)(phaseCount).btSpeciesStims.compStimNum] == 2)));
phaseComplete = false; %#ok<NASGU>
save(phaseProgressFile,'thisDate','startTime','trialComplete','phaseComplete');
end
% find the starting trial
incompleteTrials = find(~trialComplete);
if ~isempty(incompleteTrials)
trialNum = incompleteTrials(1);
runBt = true;
else
fprintf('All trials for %s %s (comp between) (%d) have been completed. Moving on to next phase...\n',sesName,phaseName,phaseCount);
% release any remaining textures
Screen('Close');
runBt = false;
end
if runBt
%% preload between stimuli for presentation
btSpeciesStims = expParam.session.(sesName).(phaseName)(phaseCount).btSpeciesStims;
% get the stimulus 2s
btStim2 = btSpeciesStims([btSpeciesStims.compStimNum] == 2);
% initialize for storing stimulus 1s
btStim1 = struct([]);
fn = fieldnames(btStim2);
for i = 1:length(fn)
btStim1(1).(fn{i}) = [];
end
btStim1Tex = nan(1,length(btStim2));
btStim2Tex = nan(1,length(btStim2));
if cfg.stim.preloadImages
message = sprintf('Preparing part 2 images, please wait...');
Screen('TextSize', w, cfg.text.basicTextSize);
% put the "preparing" message on the screen
DrawFormattedText(w, message, 'center', 'center', cfg.text.instructColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
% Update the display to show the message:
Screen('Flip', w);
for i = 1:length(btStim2)
% find btStim2's corresponding pair
btStim1(i) = btSpeciesStims(...
([btSpeciesStims.compPairNum] == btStim2(i).compPairNum) &...
([btSpeciesStims.compStimNum] ~= btStim2(i).compStimNum));
% make sure btStim2 exists
btStim2ImgFile = fullfile(stimDir,btStim2(i).familyStr,btStim2(i).fileName);
if exist(btStim2ImgFile,'file')
if cfg.stim.preloadImages
% load up btStim2's texture
btStim2Img = imread(btStim2ImgFile);
btStim2Tex(i) = Screen('MakeTexture',w,btStim2Img);
% TODO: optimized?
%btStim2Tex(i) = Screen('MakeTexture',w,btStim2Img,[],1);
end
else
error('Study stimulus %s does not exist!',btStim2ImgFile);
end
% make sure btStim1 exists
btStim1ImgFile = fullfile(stimDir,btStim1(i).familyStr,btStim1(i).fileName);
if exist(btStim1ImgFile,'file')
if cfg.stim.preloadImages
% load up btStim1's texture
btStim1Img = imread(btStim1ImgFile);
btStim1Tex(i) = Screen('MakeTexture',w,btStim1Img);
% TODO: optimized?
%btStim1Tex(i) = Screen('MakeTexture',w,btStim1Img,[],1);
elseif ~cfg.stim.preloadImages && i == length(btStim2)
% still need to load the last image to set the rectangle
btStim1Img = imread(fullfile(stimDir,btStim1(i).familyStr,btStim1(i).fileName));
end
else
error('Study stimulus %s does not exist!',btStim1ImgFile);
end
end
% get the width and height of the final stimulus image
stimImgHeight = size(btStim1Img,1) * cfg.stim.stimScale;
stimImgWidth = size(btStim1Img,2) * cfg.stim.stimScale;
% set the stimulus image rectangle
stimImgRect = [0 0 stimImgWidth stimImgHeight];
stimImgRect = CenterRect(stimImgRect, cfg.screen.wRect);
% Stimulus rectangles shifted to left and right by 60% of image width
stim1ImgRect = OffsetRect(stimImgRect,RectWidth(stimImgRect) * 0.6,0);
stim2ImgRect = OffsetRect(stimImgRect,RectWidth(stimImgRect) * 0.6 * -1,0);
% text location for error (e.g., "too fast") text
[~,errorTextY] = RectCenter(cfg.screen.wRect);
errorTextY = errorTextY + (stimImgHeight / 2);
%% show the instructions - between
if ~expParam.photoCellTest
for i = 1:length(phaseCfg.instruct.compBt)
WaitSecs(1.000);
et_showTextInstruct(w,cfg,phaseCfg.instruct.compBt(i),cfg.keys.instructContKey,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
end
% Wait a second before starting trial
WaitSecs(1.000);
end
%% questions? only during practice. continues with experimenter's key.
if ~expParam.photoCellTest && ~phaseCfg.isExp && phaseCfg.instruct.questions
questionsMsg.text = sprintf('If you have any questions about the %s phase (part 2), please ask the experimenter now.\n\nPlease tell the experimenter when you are ready to begin the task.',phaseNameForParticipant);
et_showTextInstruct(w,cfg,questionsMsg,cfg.keys.expContinue,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
% Wait a second before continuing
WaitSecs(1.000);
end
%% let them start when they're ready
if ~expParam.photoCellTest
if phaseCfg.isExp
expStr = '';
else
expStr = ' practice';
end
readyMsg.text = sprintf('Ready to begin%s %s phase (part 2).\nPress "%s" to start.',expStr,phaseNameForParticipant,cfg.keys.instructContKey);
et_showTextInstruct(w,cfg,readyMsg,cfg.keys.instructContKey,...
cfg.text.instructColor,cfg.text.instructTextSize,cfg.text.instructCharWidth);
% Wait a second before starting trial
WaitSecs(1.000);
end
%% run the comparison - between task
% only check these keys
RestrictKeysForKbCheck([cfg.keys.c01, cfg.keys.c02, cfg.keys.c03, cfg.keys.c04, cfg.keys.c05]);
% start the blink break timer
if phaseCfg.isExp && cfg.stim.secUntilBlinkBreak > 0
blinkTimerStart = GetSecs;
end
for i = trialNum:length(btStim2)
% do an impedance check after a certain number of trials
if ~expParam.photoCellTest && expParam.useNS && phaseCfg.isExp && i > 1 && i < length(btStim2) && mod((i - 1),phaseCfg.impedanceAfter_nTrials) == 0
% run the impedance break
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_START');
thisGetSecs = et_impedanceCheck(w, cfg, true, phaseName);
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'IMPEDANCE_END');
% only check these keys
RestrictKeysForKbCheck([cfg.keys.c01, cfg.keys.c02, cfg.keys.c03, cfg.keys.c04, cfg.keys.c05]);
% show preparation text
DrawFormattedText(w, 'Get ready...', 'center', 'center', cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
WaitSecs(2.0);
if (phaseCfg.comp_bt_isi > 0 && phaseCfg.fixDuringISI) || (phaseCfg.comp_bt_isi == 0 && phaseCfg.fixDuringPreStim)
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.text.respReminder
Screen('TextSize', w, cfg.text.instructTextSize);
Screen('DrawText', w, cfg.text.respReminderText, respReminderRectX, respReminderRectY, cfg.text.instructColor);
%DrawFormattedText(w, cfg.text.respReminderText, 'center', respReminderRectY, cfg.text.instructColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
WaitSecs(1.0);
% reset the blink timer
if cfg.stim.secUntilBlinkBreak > 0
blinkTimerStart = GetSecs;
end
end
% Do a blink break if specified time has passed
if ~expParam.photoCellTest && phaseCfg.isExp && cfg.stim.secUntilBlinkBreak > 0 && (GetSecs - blinkTimerStart) >= cfg.stim.secUntilBlinkBreak && i > 3 && i < (length(btStim2) - 3)
thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_START');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_START');
Screen('TextSize', w, cfg.text.basicTextSize);
if expParam.useNS
pauseMsg = 'Blink now.\n\n';
else
pauseMsg = '';
end
pauseMsg = sprintf('%sReady for trial %d of %d.\nPress any key to continue.', pauseMsg, i, length(btStim2));
% just draw straight into the main window since we don't need speed here
DrawFormattedText(w, pauseMsg, 'center', 'center', cfg.text.instructColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
% listen for any keypress on any keyboard
RestrictKeysForKbCheck([]);
thisGetSecs = KbWait(-1,2);
%thisGetSecs = GetSecs;
fprintf(logFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_END');
fprintf(phLFile,'%f\t%s\t%s\t%s\t%d\t%d\t%s\n',thisGetSecs,expParam.subject,sesName,phaseName,phaseCount,phaseCfg.isExp,'BLINK_END');
% only check these keys
RestrictKeysForKbCheck([cfg.keys.c01, cfg.keys.c02, cfg.keys.c03, cfg.keys.c04, cfg.keys.c05]);
% show preparation text
DrawFormattedText(w, 'Get ready...', 'center', 'center', cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip', w);
WaitSecs(2.0);
if (phaseCfg.comp_bt_isi > 0 && phaseCfg.fixDuringISI) || (phaseCfg.comp_bt_isi == 0 && phaseCfg.fixDuringPreStim)
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.text.respReminder
Screen('TextSize', w, cfg.text.instructTextSize);
Screen('DrawText', w, cfg.text.respReminderText, respReminderRectX, respReminderRectY, cfg.text.instructColor);
%DrawFormattedText(w, cfg.text.respReminderText, 'center', respReminderRectY, cfg.text.instructColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
WaitSecs(1.0);
% reset the timer
blinkTimerStart = GetSecs;
end
% load the stimuli now if we didn't load them earlier
if ~cfg.stim.preloadImages
btStim1Img = imread(fullfile(stimDir,btStim1(i).familyStr,btStim1(i).fileName));
btStim2Img = imread(fullfile(stimDir,btStim2(i).familyStr,btStim2(i).fileName));
btStim1Tex(i) = Screen('MakeTexture',w,btStim1Img);
btStim2Tex(i) = Screen('MakeTexture',w,btStim2Img);
end
% resynchronize netstation before the start of drawing
if expParam.useNS
[NSSyncStatus, NSSyncError] = NetStation('Synchronize'); %#ok<NASGU,ASGLU>
end
% ISI between trials
if phaseCfg.comp_bt_isi > 0
if phaseCfg.fixDuringISI
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.text.respReminder
Screen('TextSize', w, cfg.text.instructTextSize);
Screen('DrawText', w, cfg.text.respReminderText, respReminderRectX, respReminderRectY, cfg.text.instructColor);
%DrawFormattedText(w, cfg.text.respReminderText, 'center', respReminderRectY, cfg.text.instructColor, cfg.text.instructCharWidth);
end
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
WaitSecs(phaseCfg.comp_bt_isi);
end
% preStimulus period, with fixation if desired
if cfg.text.respReminder
Screen('TextSize', w, cfg.text.instructTextSize);
Screen('DrawText', w, cfg.text.respReminderText, respReminderRectX, respReminderRectY, cfg.text.instructColor);
%DrawFormattedText(w, cfg.text.respReminderText, 'center', respReminderRectY, cfg.text.instructColor, cfg.text.instructCharWidth);
end
if length(phaseCfg.comp_bt_preStim) == 1
if phaseCfg.comp_bt_preStim > 0
if phaseCfg.fixDuringPreStim
% draw fixation
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
[preStimFixOn] = Screen('Flip',w);
else
preStimFixOn = NaN;
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
end
WaitSecs(phaseCfg.comp_bt_preStim);
end
elseif length(phaseCfg.comp_bt_preStim) == 2
if ~all(phaseCfg.comp_bt_preStim == 0)
if phaseCfg.fixDuringPreStim
% draw fixation
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
[preStimFixOn] = Screen('Flip',w);
else
preStimFixOn = NaN;
if cfg.stim.photoCell
Screen('FillRect', w, cfg.stim.photoCellAntiRectColor, cfg.stim.photoCellRect);
end
Screen('Flip',w);
end
% fixation on screen before stim for a random amount of time
WaitSecs(phaseCfg.comp_bt_preStim(1) + ((phaseCfg.comp_bt_preStim(2) - phaseCfg.comp_bt_preStim(1)).*rand(1,1)));
end
end
% draw the stimuli
Screen('DrawTexture', w, btStim1Tex(i), [], stim1ImgRect);
Screen('DrawTexture', w, btStim2Tex(i), [], stim2ImgRect);
if phaseCfg.fixDuringStim
% and fixation
Screen('TextSize', w, cfg.text.fixSize);
Screen('DrawText', w, cfg.text.fixSymbol, fixRectX, fixRectY, cfg.text.fixationColor);
%DrawFormattedText(w,cfg.text.fixSymbol,'center','center',cfg.text.fixationColor, cfg.text.instructCharWidth);
end
if cfg.text.respReminder
Screen('TextSize', w, cfg.text.instructTextSize);
Screen('DrawText', w, cfg.text.respReminderText, respReminderRectX, respReminderRectY, cfg.text.instructColor);
%DrawFormattedText(w, cfg.text.respReminderText, 'center', respReminderRectY, cfg.text.instructColor, cfg.text.instructCharWidth);
end
% photocell rect with stim
if cfg.stim.photoCell