Repository navigation
Expand file tree
/
Copy pathinitIOStruct.m
More file actions
213 lines (191 loc) · 11.4 KB
/
Copy pathinitIOStruct.m
File metadata and controls
213 lines (191 loc) · 11.4 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
function ioStruct = initIOStruct(taskStruct)
% hide input to prevent participant from over-writing into the script
% HideCursor();
ListenChar(2);
Screen('Preference', 'SkipSyncTests', 1);
KbName('UnifyKeyNames');
Screen('Preference', 'ConserveVRAM', 64);
% set up the screen
ioStruct = struct();
ioStruct.bgColor = [0 0 0];
ioStruct.textColor = [200 200 200];
debugWinSize = [0,0,1000,800];
fullWinSize = [];
% run full-screen task
[ioStruct.wPtr, ioStruct.wPtrRect] = Screen('OpenWindow', 2, ioStruct.bgColor, debugWinSize);
% activate for alpha blending
Screen('BlendFunction', ioStruct.wPtr, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% Extract vertical and horizontal center of screen
ioStruct.centerX = round(ioStruct.wPtrRect(3)/2);
ioStruct.centerY = round(ioStruct.wPtrRect(4)/2);
% show loading prompt
Screen('TextFont', ioStruct.wPtr, 'Courier');
% show the loading screen
Screen('TextSize', ioStruct.wPtr, 45);
Screen('TextColor', ioStruct.wPtr, ioStruct.textColor);
DrawFormattedText(ioStruct.wPtr, 'Loading...', 'center', 'center', [], 70, false, false, 1.1);
Screen(ioStruct.wPtr, 'Flip');
% build list of jittered duration
jit_iti = [randperm(76)' repmat((1:4)',19,1)];
jit_iti = sortrows(jit_iti,1);
jit_fixobs = [randperm(56)' repmat((1:4)',14,1)];
jit_fixobs = sortrows(jit_fixobs,1);
% stimulus durations
ioStruct.SLOW = -1;
ioStruct.MAX_RT = 4;
ioStruct.FIX_DURATION = jit_iti(:,2);
ioStruct.OBSPLAY_DURATION = 1;
ioStruct.SM_OBS_DURATION = 2;
ioStruct.FIXOBS_DURATION = jit_fixobs(:,2);
ioStruct.CHOICE_FB_DURATION = 0.5;
ioStruct.TOKEN_DURATION = 1;
ioStruct.MISSED_DURATION = 1.5;
% response keys
if taskStruct.session == 1 || taskStruct.session == 3
ioStruct.respKey_1 = KbName('LeftArrow');
ioStruct.respKey_2 = KbName('DownArrow');
ioStruct.respKey_3 = KbName('RightArrow');
elseif taskStruct.session == 2 %MRI
ioStruct.respKey_1 = KbName('1');
ioStruct.respKey_2 = KbName('2');
ioStruct.respKey_3 = KbName('3');
end
% task control keys
ioStruct.respKey_Quit = KbName('Q');
ioStruct.respKeyName_Quit = 'Q';
ioStruct.respKey_Proceed = KbName('P');
ioStruct.respKeyName_Proceed = 'P';
%%%%%%%%%%%%%%%%%%%%%
% Define stimuli
% top box
width = 700;
height = 400;
rect = [0, 0, width, height];
leftX = ioStruct.centerX - width/2;
topY = ioStruct.centerY - 130 - height/2;
ioStruct.TopBox = rect + [leftX, topY, leftX, topY];
% bottom box
width = 303;
height = 230;
rect = [0, 0, width, height];
leftX = ioStruct.centerX - round(width/2);
topY = ioStruct.centerY + 230 - height/2;
ioStruct.BottomBox = rect + [leftX, topY, leftX, topY];
% slot machines OBS
width = 161;
height = 334;
rect = [0, 0, width, height];
topY = ioStruct.centerY - 120 - height/2;
leftX = ioStruct.centerX - 250 - round(width/2);
ioStruct.LeftSMObs = rect + [leftX, topY, leftX, topY];
leftX = ioStruct.centerX - round(width/2);
ioStruct.MidSMObs = rect + [leftX, topY, leftX, topY];
leftX = ioStruct.centerX + 250 - round(width/2);
ioStruct.RightSMObs = rect + [leftX, topY, leftX, topY];
% movie rectangle
width = 293;
height = 220;
rect = [0, 0, width, height];
leftX = ioStruct.centerX - round(width/2);
topY = ioStruct.centerY + 230 - height/2;
ioStruct.MovieBox = rect + [leftX, topY, leftX, topY];
% slot machines PLAY
width = 161;
height = 334;
rect = [0, 0, width, height];
topY = ioStruct.centerY - height/2;
leftX = ioStruct.centerX - 250 - round(width/2);
ioStruct.LeftSMPlay = rect + [leftX, topY, leftX, topY];
leftX = ioStruct.centerX - round(width/2);
ioStruct.MidSMPlay = rect + [leftX, topY, leftX, topY];
leftX = ioStruct.centerX + 250 - round(width/2);
ioStruct.RightSMPlay = rect + [leftX, topY, leftX, topY];
%token display box
width = 120;
height = 120;
rect = [0, 0, width, height];
leftX = ioStruct.centerX - width/2;
topY = ioStruct.centerY - height/2;
ioStruct.TokenBox = rect + [leftX, topY, leftX, topY];
% load all the images
imageDir = fullfile('.', 'stimuli');
% token images
ioStruct.token(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'green.jpg')));
ioStruct.token(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'red.jpg')));
ioStruct.token(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'blue.jpg')));
% available slot machine images
ioStruct.SM.AV.LU.VO1(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G1_lbu_a.jpg')));
ioStruct.SM.AV.LU.VO1(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R1_lbu_a.jpg')));
ioStruct.SM.AV.LU.VO1(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B1_lbu_a.jpg')));
ioStruct.SM.AV.LU.VO2(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G2_lbu_a.jpg')));
ioStruct.SM.AV.LU.VO2(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R2_lbu_a.jpg')));
ioStruct.SM.AV.LU.VO2(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B2_lbu_a.jpg')));
ioStruct.SM.AV.LU.VO3(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G3_lbu_a.jpg')));
ioStruct.SM.AV.LU.VO3(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R3_lbu_a.jpg')));
ioStruct.SM.AV.LU.VO3(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B3_lbu_a.jpg')));
ioStruct.SM.AV.HU.VO1(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G1_hbu_a.jpg')));
ioStruct.SM.AV.HU.VO1(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R1_hbu_a.jpg')));
ioStruct.SM.AV.HU.VO1(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B1_hbu_a.jpg')));
ioStruct.SM.AV.HU.VO2(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G2_hbu_a.jpg')));
ioStruct.SM.AV.HU.VO2(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R2_hbu_a.jpg')));
ioStruct.SM.AV.HU.VO2(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B2_hbu_a.jpg')));
ioStruct.SM.AV.HU.VO3(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G3_hbu_a.jpg')));
ioStruct.SM.AV.HU.VO3(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R3_hbu_a.jpg')));
ioStruct.SM.AV.HU.VO3(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B3_hbu_a.jpg')));
% unavailable slot machine images
ioStruct.SM.UA.LU.VO1(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G1_lbu_ua.jpg')));
ioStruct.SM.UA.LU.VO1(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R1_lbu_ua.jpg')));
ioStruct.SM.UA.LU.VO1(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B1_lbu_ua.jpg')));
ioStruct.SM.UA.LU.VO2(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G2_lbu_ua.jpg')));
ioStruct.SM.UA.LU.VO2(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R2_lbu_ua.jpg')));
ioStruct.SM.UA.LU.VO2(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B2_lbu_ua.jpg')));
ioStruct.SM.UA.LU.VO3(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G3_lbu_ua.jpg')));
ioStruct.SM.UA.LU.VO3(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R3_lbu_ua.jpg')));
ioStruct.SM.UA.LU.VO3(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B3_lbu_ua.jpg')));
ioStruct.SM.UA.HU.VO1(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G1_hbu_ua.jpg')));
ioStruct.SM.UA.HU.VO1(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R1_hbu_ua.jpg')));
ioStruct.SM.UA.HU.VO1(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B1_hbu_ua.jpg')));
ioStruct.SM.UA.HU.VO2(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G2_hbu_ua.jpg')));
ioStruct.SM.UA.HU.VO2(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R2_hbu_ua.jpg')));
ioStruct.SM.UA.HU.VO2(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B2_hbu_ua.jpg')));
ioStruct.SM.UA.HU.VO3(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G3_hbu_ua.jpg')));
ioStruct.SM.UA.HU.VO3(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R3_hbu_ua.jpg')));
ioStruct.SM.UA.HU.VO3(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B3_hbu_ua.jpg')));
% chosen slot machine images
ioStruct.SM.CH.LU.VO1(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G1_lbu_p.jpg')));
ioStruct.SM.CH.LU.VO1(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R1_lbu_p.jpg')));
ioStruct.SM.CH.LU.VO1(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B1_lbu_p.jpg')));
ioStruct.SM.CH.LU.VO2(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G2_lbu_p.jpg')));
ioStruct.SM.CH.LU.VO2(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R2_lbu_p.jpg')));
ioStruct.SM.CH.LU.VO2(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B2_lbu_p.jpg')));
ioStruct.SM.CH.LU.VO3(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G3_lbu_p.jpg')));
ioStruct.SM.CH.LU.VO3(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R3_lbu_p.jpg')));
ioStruct.SM.CH.LU.VO3(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B3_lbu_p.jpg')));
ioStruct.SM.CH.HU.VO1(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G1_hbu_p.jpg')));
ioStruct.SM.CH.HU.VO1(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R1_hbu_p.jpg')));
ioStruct.SM.CH.HU.VO1(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B1_hbu_p.jpg')));
ioStruct.SM.CH.HU.VO2(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G2_hbu_p.jpg')));
ioStruct.SM.CH.HU.VO2(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R2_hbu_p.jpg')));
ioStruct.SM.CH.HU.VO2(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B2_hbu_p.jpg')));
ioStruct.SM.CH.HU.VO3(1) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'G3_hbu_p.jpg')));
ioStruct.SM.CH.HU.VO3(2) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'R3_hbu_p.jpg')));
ioStruct.SM.CH.HU.VO3(3) = Screen('MakeTexture', ioStruct.wPtr, imread(fullfile(imageDir, 'B3_hbu_p.jpg')));
% read video files
videoDir = fullfile('.', 'videos');
vidFiles = dir(fullfile(videoDir, '*.mp4'));
ioStruct.video = struct('vname',cell(length(vidFiles),1),'vdata',cell(length(vidFiles),1));
for v=1:length(vidFiles)
vidname = vidFiles(v).name;
vobj = VideoReader(fullfile(videoDir, vidname));
nFrames = floor(vobj.Duration * vobj.FrameRate);
testmov = cell(nFrames,1);
k = 1; % cmpt
while hasFrame(vobj)
tmp = readFrame(vobj);
testmov{k} = tmp(:,:,:);
k = k+1;
end
ioStruct.video(v).vname = vidname;
ioStruct.video(v).vdata = testmov;
end
end