Skip to content

Commit 62e3bcf

Browse files
committed
make it work with submodules
1 parent e4d48da commit 62e3bcf

File tree

10 files changed

+333
-556
lines changed

10 files changed

+333
-556
lines changed

audioLocTranslational.m

Lines changed: 52 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -5,133 +5,88 @@
55
% adapted by M.Rezk to localize MT/MST (Huk,2002)
66
% re-adapted by MarcoB and RemiG 2020
77

8-
%%
9-
108
% Clear all the previous stuff
119
% clc; clear;
1210
if ~ismac
13-
close all;
14-
clear Screen;
11+
close all;
12+
clear Screen;
1513
end
1614

17-
% make sure we got access to all the required functions and inputs
18-
addpath(genpath(fullfile(pwd, 'subfun')))
15+
getOnlyPress = 1;
1916

20-
[expParameters, cfg] = setParameters;
17+
more off;
2118

22-
% set and load all the parameters to run the experiment
23-
expParameters = userInputs(cfg, expParameters);
19+
% make sure we got access to all the required functions and inputs
20+
initEnv();
2421

25-
expParameters = createFilename(cfg, expParameters);
22+
cfg = setParameters;
23+
cfg = userInputs(cfg);
24+
cfg = createFilename(cfg);
2625

27-
expParameters %#ok<NOPTS>
2826

2927
%% Experiment
3028

3129
% Safety loop: close the screen if code crashes
3230
try
3331

32+
% % % REFACTOR THIS FUNCTION
33+
[cfg] = loadAudioFiles(cfg);
34+
3435
%% Init the experiment
3536
[cfg] = initPTB(cfg);
3637

3738
% % Convert some values from degrees to pixels
3839
% cfg = deg2Pix('diameterAperture', cfg, cfg);
3940
% expParameters = deg2Pix('dotSize', expParameters, cfg);
4041

41-
42-
[el] = eyeTracker('Calibration', cfg, expParameters);
42+
[el] = eyeTracker('Calibration', cfg);
4343

4444
% % % REFACTOR THIS FUNCTION
45-
[expParameters] = expDesign(expParameters);
46-
% % %
45+
[cfg] = expDesign(cfg);
4746

4847
% Prepare for the output logfiles with all
49-
logFile = saveEventsFile('open', expParameters, [], ...
48+
logFile = saveEventsFile('open', cfg, [], ...
5049
'direction', 'speed', 'target', 'event', 'block');
51-
52-
logFile
53-
54-
% % % REFACTOR THIS FUNCTION
55-
[expParameters] = loadAudioFiles(cfg, expParameters);
56-
phandle = PsychPortAudio('Open',[],[],1,expParameters.freq,2);
57-
% % %
58-
59-
% Prepare for fixation Cross
60-
if expParameters.Task1
61-
62-
cfg.xCoords = [-expParameters.fixCrossDimPix expParameters.fixCrossDimPix 0 0] ...
63-
+ expParameters.xDisplacementFixCross;
64-
65-
cfg.yCoords = [0 0 -expParameters.fixCrossDimPix expParameters.fixCrossDimPix] ...
66-
+ expParameters.yDisplacementFixCross;
67-
68-
cfg.allCoords = [cfg.xCoords; cfg.yCoords];
69-
70-
end
71-
72-
% Wait for space key to be pressed
73-
pressSpace4me
74-
50+
51+
% disp(cfg);
52+
53+
standByScreen(cfg);
54+
7555
% prepare the KbQueue to collect responses
76-
getResponse('init', cfg, expParameters, 1);
77-
getResponse('start', cfg, expParameters, 1);
78-
79-
% Show instructions
80-
if expParameters.Task1
81-
DrawFormattedText(cfg.win,expParameters.TaskInstruction,...
82-
'center', 'center', cfg.textColor);
83-
Screen('Flip', cfg.win);
84-
end
85-
56+
getResponse('init', cfg.keyboard.responseBox, cfg);
57+
8658
% Wait for Trigger from Scanner
87-
wait4Trigger(cfg)
88-
89-
% Show the fixation cross
90-
if expParameters.Task1
91-
drawFixationCross(cfg, expParameters, expParameters.fixationCrossColor)
92-
Screen('Flip',cfg.win);
93-
end
94-
59+
waitForTrigger(cfg);
60+
9561
%% Experiment Start
96-
cfg.experimentStart = GetSecs;
97-
98-
WaitSecs(expParameters.onsetDelay);
62+
cfg = getExperimentStart(cfg);
63+
64+
getResponse('start', cfg.keyboard.responseBox);
65+
66+
WaitSecs(cfg.onsetDelay);
9967

10068
%% For Each Block
10169

102-
stopEverything = 0;
103-
104-
for iBlock = 1:expParameters.numBlocks
105-
106-
if stopEverything
107-
break;
108-
end
70+
for iBlock = 1:cfg.numBlocks
10971

11072
fprintf('\n - Running Block %.0f \n',iBlock)
11173

112-
eyeTracker('StartRecording', cfg, expParameters);
74+
eyeTracker('StartRecording', cfg);
11375

11476
% For each event in the block
115-
for iEvent = 1:expParameters.numEventsPerBlock
116-
117-
77+
for iEvent = 1:cfg.numEventsPerBlock
78+
11879
% Check for experiment abortion from operator
119-
[keyIsDown, ~, keyCode] = KbCheck(cfg.keyboard);
120-
if keyIsDown && keyCode(KbName(cfg.escapeKey))
121-
stopEverything = 1;
122-
warning('OK let us get out of here')
123-
break;
124-
end
125-
80+
checkAbort(cfg, cfg.keyboard.keyboard);
12681

12782
% set direction, speed of that event and if it is a target
12883
thisEvent.trial_type = 'dummy';
129-
thisEvent.direction = expParameters.designDirections(iBlock,iEvent);
130-
thisEvent.speed = expParameters.designSpeeds(iBlock,iEvent);
131-
thisEvent.target = expParameters.designFixationTargets(iBlock,iEvent);
84+
thisEvent.direction = cfg.designDirections(iBlock,iEvent);
85+
thisEvent.speed = cfg.designSpeeds(iBlock,iEvent);
86+
thisEvent.target = cfg.designFixationTargets(iBlock,iEvent);
13287

13388
% play the sounds and collect onset and duration of the event
134-
[onset, duration] = doAudMot(cfg, expParameters, thisEvent, phandle);
89+
[onset, duration] = doAudMot(cfg, thisEvent, cfg.audio.pahandle);
13590

13691
thisEvent.event = iEvent;
13792
thisEvent.block = iBlock;
@@ -142,59 +97,46 @@
14297
% we save event by event so we clear this variable every loop
14398
thisEvent.fileID = logFile.fileID;
14499

145-
saveEventsFile('save', expParameters, thisEvent, ...
100+
saveEventsFile('save', cfg, thisEvent, ...
146101
'direction', 'speed', 'target', 'event', 'block');
147102

148103
clear thisEvent
149104

150105

151106
% collect the responses and appends to the event structure for
152107
% saving in the tsv file
153-
responseEvents = getResponse('check', cfg, expParameters);
108+
responseEvents = getResponse('check', cfg.keyboard.responseBox, cfg, ...
109+
getOnlyPress);
154110

155-
if ~isempty(responseEvents(1).onset)
156-
157-
responseEvents.fileID = logFile.fileID;
158-
159-
for iResp = 1:size(responseEvents, 1)
160-
responseEvents(iResp).onset = ...
161-
responseEvents(iResp).onset - cfg.experimentStart;
162-
responseEvents(iResp).target = expParameters.designFixationTargets(iBlock,iEvent);
163-
responseEvents(iResp).event = iEvent;
164-
responseEvents(iResp).block = iBlock;
165-
end
166-
167-
saveEventsFile('save', expParameters, responseEvents, ...
168-
'direction', 'speed', 'target', 'event', 'block');
169-
end
111+
triggerString = ['trigger'];
112+
saveResponsesAndTriggers(responseEvents, cfg, logFile, triggerString);
170113

171114
% wait for the inter-stimulus interval
172-
WaitSecs(expParameters.ISI);
173-
174-
getResponse('flush', cfg, expParameters);
115+
WaitSecs(cfg.ISI);
175116

176117
end
177118

178-
eyeTracker('StopRecordings', cfg, expParameters);
119+
eyeTracker('StopRecordings', cfg);
179120

180-
WaitSecs(expParameters.IBI);
121+
WaitSecs(cfg.IBI);
181122

182123
end
183124

184125
% End of the run for the BOLD to go down
185-
WaitSecs(expParameters.endDelay);
126+
WaitSecs(cfg.endDelay);
186127

187128
% Close the logfiles
188-
saveEventsFile('close', expParameters, logFile);
129+
saveEventsFile('close', cfg, logFile);
189130

190-
getResponse('stop', cfg, expParameters, 1);
131+
getResponse('stop', cfg.keyboard.responseBox);
132+
getResponse('release', cfg.keyboard.responseBox);
191133

192134
totalExperimentTime = GetSecs-cfg.experimentStart;
193135

194-
eyeTracker('Shutdown', cfg, expParameters);
136+
eyeTracker('Shutdown', cfg);
195137

196138
% save the whole workspace
197-
matFile = fullfile(expParameters.outputDir, strrep(expParameters.fileName.events,'tsv', 'mat'));
139+
matFile = fullfile(cfg.dir.output, strrep(cfg.fileName.events,'tsv', 'mat'));
198140
if IsOctave
199141
save(matFile, '-mat7-binary');
200142
else

initEnv.m

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
%
2+
% 1 - Check if version requirements
3+
% are satisfied and the packages are
4+
% are installed/loaded:
5+
% Octave > 4
6+
% - image
7+
% - optim
8+
% - struct
9+
% - statistics
10+
%
11+
% MATLAB > R2017a
12+
%
13+
% 2 - Add project to the O/M path
14+
15+
function initEnv
16+
17+
octaveVersion = '4.0.3';
18+
matlabVersion = '9.2.0';
19+
20+
if isOctave
21+
22+
% Exit if min version is not satisfied
23+
if ~compare_versions(OCTAVE_VERSION, octaveVersion, '>=')
24+
error('Minimum required Octave version: %s', octaveVersion);
25+
end
26+
27+
installlist = {'statistics', 'image'};
28+
for ii = 1:length(installlist)
29+
try
30+
% Try loading Octave packages
31+
disp(['loading ' installlist{ii}]);
32+
pkg('load', installlist{ii});
33+
34+
catch
35+
errorcount = 1;
36+
while errorcount % Attempt twice in case installation fails
37+
try
38+
pkg('install', '-forge', installlist{ii});
39+
pkg('load', installlist{ii});
40+
errorcount = 0;
41+
catch err
42+
errorcount = errorcount + 1;
43+
if errorcount > 2
44+
error(err.message);
45+
end
46+
end
47+
end
48+
end
49+
end
50+
51+
else % MATLAB ----------------------------
52+
53+
if verLessThan('matlab', matlabVersion)
54+
error('Sorry, minimum required version is R2017b. :(');
55+
end
56+
57+
end
58+
59+
% If external dir is empty throw an exception
60+
% and ask user to update submodules.
61+
if numel(dir('lib')) <= 2 % Means that the external is empty
62+
error(['Git submodules are not cloned!', ...
63+
'Try this in your terminal:', ...
64+
' git submodule update --recursive ']);
65+
else
66+
addDependencies();
67+
end
68+
69+
disp('Correct matlab/octave verions and added to the path!');
70+
71+
end
72+
73+
%%
74+
%% Return: true if the environment is Octave.
75+
%%
76+
function retval = isOctave
77+
persistent cacheval % speeds up repeated calls
78+
79+
if isempty (cacheval)
80+
cacheval = (exist ("OCTAVE_VERSION", "builtin") > 0);
81+
end
82+
83+
retval = cacheval;
84+
end
85+
86+
function addDependencies()
87+
88+
pth = fileparts(mfilename('fullpath'));
89+
addpath(fullfile(pth, 'lib', 'CPP_BIDS', 'src'));
90+
addpath(fullfile(pth, 'lib', 'CPP_PTB'));
91+
addpath(genpath(fullfile(pth, 'lib', 'CPP_PTB', 'src')));
92+
addpath(fullfile(pth, 'subfun'));
93+
94+
end

miss_hit.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
line_length: 100
2+
regex_function_name: "[a-z]+(([A-Z]){1}[A-Za-z]+)*"
3+
suppress_rule: "copyright_notice"
4+
exclude_dir: "lib"
5+
exclude_dir: "Visual-loc_radial"

0 commit comments

Comments
 (0)