Skip to content

Commit e6c59c1

Browse files
committed
Added backgrounds to epochs only when a stimulus or background is missing
1 parent df42162 commit e6c59c1

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/main/matlab/+symphonyui/+core/Controller.m

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,29 +314,31 @@ function processLoop(obj)
314314
function e = nextEpoch(obj)
315315
e = symphonyui.core.Epoch(class(obj.currentProtocol));
316316

317-
for i = 1:numel(obj.rig.devices)
318-
d = obj.rig.devices{i};
319-
if ~isempty(d.outputStreams)
317+
obj.currentProtocol.prepareEpoch(e);
318+
319+
devices = obj.rig.getOutputDevices();
320+
for i = 1:numel(devices)
321+
d = devices{i};
322+
if ~e.hasStimulus(d) && ~e.hasBackground(d)
320323
e.setBackground(d, d.background);
321324
end
322325
end
323-
324-
obj.currentProtocol.prepareEpoch(e);
325326
end
326327

327-
function i = nextInterval(obj)
328-
i = symphonyui.core.Epoch(class(obj.currentProtocol));
329-
i.shouldBePersisted = false;
330-
i.addKeyword(obj.INTERVAL_KEYWORD);
331-
332-
for k = 1:numel(obj.rig.devices)
333-
d = obj.rig.devices{k};
334-
if ~isempty(d.outputStreams)
335-
i.setBackground(d, d.background);
328+
function e = nextInterval(obj)
329+
e = symphonyui.core.Epoch(class(obj.currentProtocol));
330+
e.shouldBePersisted = false;
331+
e.addKeyword(obj.INTERVAL_KEYWORD);
332+
333+
obj.currentProtocol.prepareInterval(e);
334+
335+
devices = obj.rig.getOutputDevices();
336+
for i = 1:numel(devices)
337+
d = devices{i};
338+
if ~e.hasStimulus(d) && ~e.hasBackground(d)
339+
e.setBackground(d, d.background);
336340
end
337341
end
338-
339-
obj.currentProtocol.prepareInterval(i);
340342
end
341343

342344
function enqueueEpoch(obj, epoch)

src/main/matlab/+symphonyui/+core/Epoch.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function addStimulus(obj, device, stimulus)
3131
cstim = obj.tryCoreWithReturn(@()obj.cobj.Stimuli.Item(device.cobj));
3232
s = symphonyui.core.Stimulus(cstim);
3333
end
34+
35+
function tf = hasStimulus(obj, device)
36+
tf = obj.tryCoreWithReturn(@()obj.cobj.Stimuli.ContainsKey(device.cobj));
37+
end
3438

3539
function addDirectCurrentStimulus(obj, device, measurement, duration, sampleRate)
3640
g = symphonyui.builtin.stimuli.DirectCurrentGenerator();
@@ -77,6 +81,10 @@ function addKeyword(obj, keyword)
7781
function setBackground(obj, device, background)
7882
obj.tryCore(@()obj.cobj.SetBackground(device.cobj, background.cobj, device.cobj.OutputSampleRate));
7983
end
84+
85+
function tf = hasBackground(obj, device)
86+
tf = obj.tryCoreWithReturn(@()obj.cobj.Backgrounds.ContainsKey(device.cobj));
87+
end
8088

8189
function tf = get.shouldWaitForTrigger(obj)
8290
tf = obj.cobj.ShouldWaitForTrigger;

0 commit comments

Comments
 (0)