Skip to content

Commit 83d83f4

Browse files
authored
Merge pull request #16 from Remi-Gau/remi-update_to_other_CPP_repos
Update to new cfg structure
2 parents 7fb6d6c + d24611f commit 83d83f4

File tree

6 files changed

+153
-152
lines changed

6 files changed

+153
-152
lines changed

lib/CPP_BIDS

lib/CPP_PTB

setParameters.m

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,95 @@
1-
function [cfg, expParameters] = setParameters();
1+
function [cfg] = setParameters()
22

33
% Initialize the parameters and general configuration variables
4-
expParameters = struct();
54
cfg = struct();
65

7-
8-
96
% by default the data will be stored in an output folder created where the
107
% setParamters.m file is
118
% change that if you want the data to be saved somewhere else
12-
expParameters.outputDir = fullfile( ...
9+
cfg.dir.output = fullfile( ...
1310
fileparts(mfilename('fullpath')), '..', ...
1411
'output');
1512

1613
%% Debug mode settings
17-
cfg.debug = true; % To test the script out of the scanner, skip PTB sync
18-
cfg.testingSmallScreen = false; % To test on a part of the screen, change to 1
19-
cfg.testingTranspScreen = true; % To test with trasparent full size screen
14+
cfg.debug.do = true; % To test the script out of the scanner, skip PTB sync
15+
cfg.debug.smallWin = false; % To test on a part of the screen, change to 1
16+
cfg.debug.transpWin = true; % To test with trasparent full size screen
2017

21-
expParameters.verbose = true;
18+
cfg.verbose = false;
2219

2320
%% Engine parameters
2421

2522
cfg.testingDevice = 'pc';
26-
cfg.eyeTracker = false;
27-
cfg.initAudio = false;
23+
cfg.eyeTracker.do = false;
24+
cfg.audio.do = false;
2825

29-
[cfg, expParameters] = setMonitor(cfg, expParameters);
26+
cfg = setMonitor(cfg, cfg);
3027

3128
% Keyboards
32-
[cfg, expParameters] = setKeyboards(cfg, expParameters);
29+
cfg = setKeyboards(cfg, cfg);
3330

3431
% MRI settings
35-
[cfg, expParameters] = setMRI(cfg, expParameters);
32+
cfg = setMRI(cfg, cfg);
3633

3734
%% Experiment Design
38-
expParameters.names = {'static', 'motion'};
39-
expParameters.possibleDirections = [-1 1]; % 1 motion , -1 static
40-
expParameters.numBlocks = size(expParameters.possibleDirections, 2);
41-
expParameters.numRepetitions = 1; % AT THE MOMENT IT IS NOT SET IN THE MAIN SCRIPT
42-
expParameters.IBI = 0; % 8;
35+
cfg.names = {'static', 'motion'};
36+
cfg.possibleDirections = [-1 1]; % 1 motion , -1 static
37+
cfg.numBlocks = size(cfg.possibleDirections, 2);
38+
cfg.numRepetitions = 1; % AT THE MOMENT IT IS NOT SET IN THE MAIN SCRIPT
39+
cfg.IBI = 0; % 8;
4340
% Time between events in secs
44-
expParameters.ISI = 0.1;
41+
cfg.ISI = 0.1;
4542
% Number of seconds before the motion stimuli are presented
46-
expParameters.onsetDelay = 5;
43+
cfg.onsetDelay = 5;
4744
% Number of seconds after the end all the stimuli before ending the run
48-
expParameters.endDelay = 1;
45+
cfg.endDelay = 1;
4946

5047
%% Visual Stimulation
51-
% speed in visual angles
52-
expParameters.speedEvent = 8;
48+
5349
% Number of events per block (should not be changed)
54-
expParameters.numEventsPerBlock = 12;
55-
expParameters.eventDuration = 1;
50+
cfg.numEventsPerBlock = 12;
51+
cfg.eventDuration = 1; % second
52+
53+
% speed in visual angles
54+
cfg.dot.speed = 8;
5655
% Coherence Level (0-1)
57-
expParameters.coh = 1;
56+
cfg.dot.coh = 1;
5857
% Maximum number dots per frame
59-
expParameters.maxDotsPerFrame = 300;
58+
cfg.dot.maxNbPerFrame = 300;
6059
% Dot life time in seconds
61-
expParameters.dotLifeTime = 1;
60+
cfg.dot.lifeTime = 1;
6261
% Dot Size (dot width) in visual angles.
63-
expParameters.dotSize = 0.1;
64-
expParameters.dotColor = cfg.white;
65-
expParameters.dontClear = 0;
62+
cfg.dot.size = 0.1;
63+
cfg.dot.color = cfg.color.white;
64+
cfg.dot.dontClear = 0;
65+
6666
% Diameter/length of side of aperture in Visual angles
6767
cfg.diameterAperture = 8;
6868

6969
%% Task(s)
70-
71-
expParameters.task = 'visualLocalizer';
70+
71+
cfg.task.name = 'visual localizer';
7272

7373
% Instruction
74-
expParameters.taskInstruction = '1-Detect the RED fixation cross\n \n\n';
74+
cfg.task.instruction = '1-Detect the RED fixation cross\n \n\n';
7575

7676
% Fixation cross (in pixels)
7777
% Set the length of the lines of the fixation cross
78-
expParameters.fixCrossDimPix = 10;
78+
cfg.fixation.dimensionPix = 10;
7979
% Set the line width for our fixation cross
80-
expParameters.lineWidthPix = 4;
81-
expParameters.maxNumFixationTargetPerBlock = 2;
82-
expParameters.targetDuration = 0.15; % In secs
83-
84-
expParameters.xDisplacementFixCross = 0; % Manual displacement of the fixation cross
85-
expParameters.yDisplacementFixCross = 0; % Manual displacement of the fixation cross
86-
expParameters.fixationCrossColor = cfg.white;
87-
expParameters.fixationCrossColorTarget = cfg.red;
88-
89-
expParameters.extraColumns = {'direction', 'speed', 'target', 'event', 'block'};
80+
cfg.fixation.lineWidthPix = 4;
81+
cfg.fixation.xDisplacement = 0; % Manual displacement of the fixation cross
82+
cfg.fixation.yDisplacement = 0; % Manual displacement of the fixation cross
83+
cfg.fixation.color = cfg.color.white;
84+
cfg.fixation.colorTarget = cfg.color.red;
85+
86+
cfg.target.maxNbPerBlock = 2;
87+
cfg.target.duration = 0.15; % In secs
88+
89+
cfg.extraColumns = {'direction', 'speed', 'target', 'event', 'block'};
9090
end
9191

92-
function [cfg, expParameters] = setKeyboards(cfg, expParameters)
92+
function cfg = setKeyboards(cfg)
9393
cfg.keyboard.escapeKey = 'ESCAPE';
9494
cfg.keyboard.responseKey = {'space'};
9595
cfg.keyboard.keyboard = [];
@@ -101,34 +101,34 @@
101101
end
102102
end
103103

104-
function [cfg, expParameters] = setMRI(cfg, expParameters)
104+
function cfg = setMRI(cfg)
105105
% letter sent by the trigger to sync stimulation and volume acquisition
106-
cfg.triggerKey = 't';
107-
cfg.numTriggers = 4;
106+
cfg.mri.triggerKey = 't';
107+
cfg.mri.triggerNb = 4;
108108

109-
expParameters.bids.MRI.RepetitionTime = 2;
109+
cfg.mri.repetitionTime = 2;
110110

111-
expParameters.bids.MRI.Instructions = 'Detect the RED fixation cross';
112-
expParameters.bids.MRI.TaskDescription = [];
111+
cfg.bids.MRI.Instructions = 'Detect the RED fixation cross';
112+
cfg.bids.MRI.TaskDescription = [];
113113

114114
end
115115

116-
function [cfg, expParameters] = setMonitor(cfg, expParameters)
116+
function cfg = setMonitor(cfg)
117117

118118
% Monitor parameters for PTB
119-
cfg.white = [255 255 255];
120-
cfg.black = [0 0 0];
121-
cfg.red = [255 0 0];
122-
cfg.grey = mean([cfg.black; cfg.white]);
123-
cfg.backgroundColor = cfg.black;
124-
cfg.textColor = cfg.white;
119+
cfg.color.white = [255 255 255];
120+
cfg.color.black = [0 0 0];
121+
cfg.color.red = [255 0 0];
122+
cfg.color.grey = mean([cfg.color.black; cfg.color.white]);
123+
cfg.color.background = cfg.color.black;
124+
cfg.text.color = cfg.color.white;
125125

126126
% Monitor parameters
127-
cfg.monitorWidth = 42; % in cm
128-
cfg.screenDistance = 134; % distance from the screen in cm
127+
cfg.screen.monitorWidth = 42; % in cm
128+
cfg.screen.monitorDistance = 134; % distance from the screen in cm
129129

130130
if strcmpi(cfg.testingDevice, 'mri')
131-
cfg.monitorWidth = 42;
132-
cfg.screenDistance = 134;
131+
cfg.screen.monitorWidth = 42;
132+
cfg.screen.monitorDistance = 134;
133133
end
134134
end

subfun/doDotMo.m

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [onset, duration] = doDotMo(cfg, expParameters, thisEvent)
1+
function [onset, duration] = doDotMo(cfg, thisEvent)
22
% Draws the stimulation of static/moving in 4 directions dots or static
33
%
44
% DIRECTIONS
@@ -18,19 +18,19 @@
1818
% smaller number (nDots / Area of aperture) on average.
1919

2020
%% Get parameters
21-
dontClear = expParameters.dontClear;
21+
dontClear = cfg.dot.dontClear;
2222

2323
direction = thisEvent.direction(1);
2424
isTarget = thisEvent.target(1);
2525
speed = thisEvent.speed(1);
2626

27-
coh = expParameters.coh;
28-
ndots = expParameters.maxDotsPerFrame;
29-
dotSizePix = expParameters.dotSizePix;
30-
dotLifeTime = expParameters.dotLifeTime;
31-
dotColor = expParameters.dotColor;
27+
coh = cfg.dot.coh;
28+
ndots = cfg.dot.maxNbPerFrame;
29+
dotSizePix = cfg.dot.sizePix;
30+
dotLifeTime = cfg.dot.lifeTime;
31+
dotColor = cfg.dot.color;
3232

33-
targetDuration = expParameters.targetDuration;
33+
targetDuration = cfg.target.duration;
3434

3535
% thisEvent = deg2Pix('speed', thisEvent, cfg);
3636
% dotSpeedPix = logFile.iEventSpeedPix;
@@ -45,7 +45,7 @@
4545

4646
speed = 0;
4747

48-
dotLifeTime = expParameters.eventDuration;
48+
dotLifeTime = cfg.eventDuration;
4949
end
5050

5151
%% initialize variables
@@ -59,7 +59,7 @@
5959
% Set a N x 2 matrix that gives jump size in pixels
6060
% pix/sec * sec/frame = pix / frame
6161
dxdy = repmat( ...
62-
speed * 10 / (diamAperture * 10) * (3 / cfg.monRefresh) * ...
62+
speed * 10 / (diamAperture * 10) * (3 / cfg.screen.monitorRefresh) * ...
6363
[cos(pi * direction / 180.0) -sin(pi * direction / 180.0)], ndots, 1);
6464

6565
% dxdy = repmat(...
@@ -71,13 +71,13 @@
7171
dotTime = ones(size(xy, 1), 1);
7272

7373
% Set for how many frames to show the dots
74-
continueShow = floor(expParameters.eventDuration / cfg.ifi);
74+
continueShow = floor(cfg.eventDuration / cfg.screen.ifi);
7575

7676
% Covert the dotLifeTime from seconds to frames
77-
dotLifeTime = ceil(dotLifeTime / cfg.ifi);
77+
dotLifeTime = ceil(dotLifeTime / cfg.screen.ifi);
7878

7979
%% Start the dots presentation
80-
vbl = Screen('Flip', cfg.win, 0, dontClear);
80+
vbl = Screen('Flip', cfg.screen.win, 0, dontClear);
8181
onset = vbl;
8282

8383
while continueShow
@@ -124,19 +124,19 @@
124124
%% PTB draws the dots stimulation
125125

126126
% Draw the fixation cross
127-
color = expParameters.fixationCrossColor;
127+
color = cfg.fixation.color;
128128
% If this frame shows a target we change the color
129129
if GetSecs < (onset + targetDuration) && isTarget == 1
130-
color = expParameters.fixationCrossColorTarget;
130+
color = cfg.fixation.colorTarget;
131131
end
132-
drawFixationCross(cfg, expParameters, color);
132+
drawFixationCross(cfg, color);
133133

134134
% Draw the dots
135-
Screen('DrawDots', cfg.win, xy_pix, dotSizePix, dotColor, cfg.center, 2);
135+
Screen('DrawDots', cfg.screen.win, xy_pix, dotSizePix, dotColor, cfg.screen.center, 2);
136136

137-
Screen('DrawingFinished', cfg.win, dontClear);
137+
Screen('DrawingFinished', cfg.screen.win, dontClear);
138138

139-
vbl = Screen('Flip', cfg.win, vbl + cfg.ifi, dontClear);
139+
vbl = Screen('Flip', cfg.screen.win, vbl + cfg.screen.ifi, dontClear);
140140

141141
%% Update counters
142142

@@ -150,11 +150,11 @@
150150

151151
%% Erase last dots
152152

153-
drawFixationCross(cfg, expParameters, expParameters.fixationCrossColor);
153+
drawFixationCross(cfg, cfg.fixation.color);
154154

155-
Screen('DrawingFinished', cfg.win, dontClear);
155+
Screen('DrawingFinished', cfg.screen.win, dontClear);
156156

157-
vbl = Screen('Flip', cfg.win, vbl + cfg.ifi, dontClear);
157+
vbl = Screen('Flip', cfg.screen.win, vbl + cfg.screen.ifi, dontClear);
158158

159159
duration = vbl - onset;
160160

0 commit comments

Comments
 (0)