Skip to content

Commit

Permalink
removed saving frame from displaystimulus
Browse files Browse the repository at this point in the history
  • Loading branch information
heimel committed Jun 14, 2018
1 parent b5ab360 commit dbfcc9d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 69 deletions.
10 changes: 5 additions & 5 deletions Configuration/NewStimConfiguration_default.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
Remote_Comm_method = 'filesystem'; % 'sockets' or 'filesystem'

% settings for Remote_Comm_method = 'filesystem'
Remote_Comm_dir = '/home/data/stims'; % the local name of folder in which to write
% Remote_Comm_dir = '\\vs01.herseninstituut.knaw.nl\MVP\Shared\InVivo\'; % the local name of folder in which to write
Remote_Comm_dir = 'C:\Windows\Temp'; % the local name of folder in which to write
% files for communication

% settings for Remote_Comm_method = 'sockets'
Expand All @@ -41,7 +42,7 @@
Remote_Comm_remotearchitecture = 'unix'; % options are 'PC', 'Mac' (MacOS9), or 'unix' (Linux, MacOSX)
% the computer type of the remote machine you are talking to (not of THIS computer, necessarily)

Remote_Comm_localprefix = '/home/data/'; % for example, 'Z:', 'z:', '/Users/Shared/myexperimentdir'
Remote_Comm_localprefix = 'C:\Data'; % for example, 'Z:', 'z:', '/Users/Shared/myexperimentdir'
% the prefix to the shared directory on THIS computer

Remote_Comm_remoteprefix = '/mnt/THISHOSTNAME/data';
Expand Down Expand Up @@ -75,15 +76,15 @@
MonitorComputer = 0; % does this computer have a monitor window?


if StimComputer&&haspsychtbox==2, % set up timing and monitor settings
if StimComputer&&haspsychtbox==2 % set up timing and monitor settings
Screen('Preference','SecondsMultiplier',1.0);
Screen('Preference','Backgrounding',1);
else
% set the current monitor dimensions for remote comm
StimWindowRefresh = 60;
StimWindowDepth = 8;
StimWindowRect = [ 0 0 800 600 ];
end;
end

% pixels_per_cm of the monitor in use
pixels_per_cm = 200/9.5;
Expand All @@ -102,7 +103,6 @@
LoadGammaCorrectionTable('gct_linear.txt');
%LoadGammaCorrectionTable('gct_HOSTNAME.txt');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Triggering/stimulus reporting settings
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
118 changes: 62 additions & 56 deletions NewStim3/NewStimDisplayProcs/DisplayStimulus.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
stim = []; %#ok<NASGU>
else
stim = thestim; %#ok<NASGU>
end;
end
if nargin<3
trigger = [];
end
Expand All @@ -27,25 +27,27 @@
startStopTimes = MTI.startStopTimes;
frameTimes = MTI.frameTimes;

if NS_PTBv<3,
if NS_PTBv<3
Screen(StimWindow,'FillRect',0);
else
show_background(StimWindow,MTI,[],2);
end

masktexture = -1;

if MTI.ds.makeClip, % make a clipping region
if NS_PTBv<3, %use clipping region, can call routine directly
if MTI.ds.makeClip % make a clipping region
if NS_PTBv<3 %use clipping region, can call routine directly
Screen(StimWindow,'SetDrawingRegion',MTI.ds.clipRect,MTI.ds.makeClip-1);
else % make a clipping region or use the one provided
if MTI.ds.makeClip==4||MTI.ds.makeClip==5,
if MTI.ds.makeClip==4||MTI.ds.makeClip==5
masktexture = MTI.ds.clipRect;
end;
end;
end;
end
end
end

if strcmp(MTI.ds.displayType,'Sound'), Snd('Open'); end;
if strcmp(MTI.ds.displayType,'Sound')
Snd('Open');
end

if trigger
% Levelt lab trigger hard coded. Should use StimTriggerAct structure
Expand All @@ -66,8 +68,8 @@
StimSerial('rts',StimSerialStim,0);
end

if MTI.preBGframes>0,
if NS_PTBv<3,
if MTI.preBGframes>0
if NS_PTBv<3
Screen(StimWindow,'SetClut',MTI.ds.clut_bg); % also does waitblanking
startStopTimes(1) = StimTriggerAct('Stim_BGpre_trigger',MTI.stimid);
Screen(StimWindow,'WaitBlanking',MTI.preBGframes);
Expand All @@ -76,26 +78,26 @@
startStopTimes(1) = StimTriggerAct('Stim_BGpre_trigger',MTI.stimid);
show_background(StimWindow,MTI,vbl + (MTI.preBGframes-1)/StimWindowRefresh);
if capture_movie; Screen('AddFrameToMovie', StimWindow,[],[],[],MTI.preBGframes); end
end;
end
else
startStopTimes(1) = StimTriggerAct('Stim_BGpre_trigger',MTI.stimid);
end;
end


if strcmp(MTI.ds.displayType,'CLUTanim')&&strcmp(MTI.ds.displayProc,'standard'),
if strcmp(MTI.ds.displayType,'CLUTanim')&&strcmp(MTI.ds.displayProc,'standard')
s0 = GetSecs();
startStopTimes(2) = StimTriggerAct('Stim_ONSET_trigger',MTI.stimid);
rect = Screen(MTI.ds.offscreen(1),'Rect');
if NS_PTBv<3,
if NS_PTBv<3
Screen('CopyWindow',MTI.ds.offscreen(1),StimWindow,rect,MTI.df.rect,'srcCopy');
Screen(StimWindow, 'SetClut', MTI.ds.clut{MTI.df.frames(1)}); % does waitblanking
frameTimes(1) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,1);
for frameNum=2:length(MTI.df.frames),
for frameNum=2:length(MTI.df.frames)
Screen(StimWindow,'WaitBlanking',MTI.pauseRefresh(frameNum-1));
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,frameNum);
Screen(StimWindow,'SetClut',MTI.ds.clut{MTI.df.frames(frameNum)});
frameTimes(frameNum) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,frameNum);
end;
end
Screen(StimWindow,'WaitBlanking',MTI.pauseRefresh(end));
else
Screen('DrawTexture',StimWindow,MTI.ds.offscreen(1),rect,MTI.df.rect);
Expand All @@ -108,30 +110,30 @@
Screen('DrawTexture',StimWindow,MTI.ds.offscreen(1),rect,MTI.df.rect); % draw in the 2nd buffer
%if MTI.ds.makeClip==4, Screen('DrawTexture',StimWindow,masktexture); elseif MTI.ds.makeClip==5, screen('DrawTexture',StimWindow,masktexture,[],MTI.df.rect); end;
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,1);
for frameNum=2:length(MTI.df.frames),
for frameNum=2:length(MTI.df.frames)
% this should really be measured from each interval for most accurate "local" display
Screen('LoadNormalizedGammaTable',StimWindow, MTI.ds.clut{MTI.df.frames(frameNum)},1);
vbl=Screen('Flip',StimWindow,vbl+(MTI.pauseRefresh(frameNum-1)+0.5)/StimWindowRefresh,2);
%Screen('Flip',StimWindow,vbl+(sum(1+MTI.pauseRefresh(1:frameNum-1))-0.5)/StimWindowRefresh,2);
frameTimes(frameNum)=StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,frameNum);
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,frameNum);
end;
end
Screen('Flip',StimWindow,vbl+(MTI.pauseRefresh(end)+0.5)/StimWindowRefresh); % the +0.5 is here because these pause times for CLUTanims can range from -1 due to backward compatibility
end;
end

elseif strcmp(MTI.ds.displayType,'Movie') && strcmp(MTI.ds.displayProc,'standard'),
elseif strcmp(MTI.ds.displayType,'Movie') && strcmp(MTI.ds.displayProc,'standard')
startStopTimes(2) = StimTriggerAct('Stim_ONSET_trigger',MTI.stimid);
if NS_PTBv<3,
if NS_PTBv<3
Screen(StimWindow,'SetClut',MTI.ds.clut); % does waitblanking
Screen('CopyWindow',MTI.ds.offscreen(MTI.df.frames(1)),StimWindow,MTI.MovieParams.Movie_sourcerect(1,:), MTI.df.rect,'srcCopyQuickly');
frameTimes(1) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,1);
for frameNum=2:length(MTI.df.frames);
for frameNum=2:length(MTI.df.frames)
Screen(StimWindow,'WaitBlanking',MTI.pauseRefresh(frameNum-1));
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,frameNum);
rectnum = 1+mod(MTI.df.frames(frameNum),length(MTI.ds.offscreen));
Screen('CopyWindow',MTI.ds.offscreen(MTI.df.frames(frameNum)),StimWindow,MTI.MovieParams.Movie_sourcerect(frameNum,:), MTI.df.rect,'srcCopyQuickly');
frameTimes(frameNum) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,frameNum);
end;
end
Screen(StimWindow,'WaitBlanking',MTI.pauseRefresh(end));
else
Screen('LoadNormalizedGammaTable',StimWindow,MTI.ds.clut,1); % this seems to be no longer necessary or correct, the textures already have colors
Expand All @@ -151,16 +153,16 @@
vbl = Screen('Flip',StimWindow,0);
frameTimes(1) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,1);

capture_image = true;
if capture_image;
capture_image = false;
if capture_image
imageArray = Screen('GetImage', StimWindow);
imwrite(imageArray,fullfile(getdesktopfolder,'stimulus_frame.png'),'png')
end

if capture_movie; Screen('AddFrameToMovie', StimWindow); end
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,1);

for frameNum=2:length(MTI.df.frames);
for frameNum=2:length(MTI.df.frames)
textures = MTI.MovieParams.Movie_textures{frameNum};
Screen('DrawTextures',StimWindow,MTI.ds.offscreen(textures),...
squeeze(MTI.MovieParams.Movie_sourcerects(:,frameNum,textures)),... % sourceRects
Expand All @@ -176,7 +178,7 @@
frameTimes(frameNum) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,frameNum);
WaitSecs(1/10000);
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,frameNum);
end;
end
if StimWindowUseCLUTMapping, Screen('LoadNormalizedGammaTable',StimWindow,linspace(0,1,256)' * ones(1,3),1); end;
switch host
% case 'barney'
Expand All @@ -187,41 +189,43 @@
if capture_movie; Screen('AddFrameToMovie', StimWindow); end
end

elseif strcmp(MTI.ds.displayType,'custom'),
elseif strcmp(MTI.ds.displayType,'custom')
done=0; stamp=0; info=[]; stampNum=1; %#ok<NASGU>
startStopTimes(2) = StimTriggerAct('Stim_ONSET_trigger',MTI.stimid);
while(done==0),
while(done==0)
eval(['[done,stamp,info]=' MTI.ds.displayProc '(info,StimWindow,MTI.ds,MTI.df);']);
if stamp==1, % make a time stamp
if stamp==1 % make a time stamp
frameTimes(stampNum) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,stampNum);
stampNum = stampNum + 1;
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,stampNum);
end;
end;
end
end

elseif strcmp(MTI.ds.displayProc,'customdraw'), % calls the stim's 'customdraw' function
elseif strcmp(MTI.ds.displayProc,'customdraw') % calls the stim's 'customdraw' function
done=0; stamp=0; info=[]; stampNum=1; %#ok<NASGU>
startStopTimes(2) = StimTriggerAct('Stim_ONSET_trigger',MTI.stimid);
while(done==0),
while(done==0)
eval('[done,stamp,info]=customdraw(stim,info,MTI);');
if stamp==1, % make a time stamp
if stamp==1 % make a time stamp
frameTimes(stampNum) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,stampNum);
stampNum = stampNum + 1;
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,stampNum);
end
end
frameTimes
elseif strcmpi(MTI.ds.displayType,'QUICKTIME'), % note, quicktime play only supported in PTB-3
%frameTimes
elseif strcmpi(MTI.ds.displayType,'QUICKTIME') % note, quicktime play only supported in PTB-3
Screen('LoadNormalizedGammaTable',StimWindow,StimWindowPreviousCLUT);
Screen('SetMovieTimeIndex', MTI.ds.userfield.movie, 0); % play from beginning, regardless of where we played last time
done = 0;
frameNum = 0;
startStopTimes(2) = StimTriggerAct('Stim_ONSET_trigger',MTI.stimid);
Screen('PlayMovie',MTI.ds.userfield.movie,1);
while ~done,
if frameNum>0, StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,frameNum); end;
while ~done
if frameNum>0
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,frameNum);
end
tex = Screen('GetMovieImage',StimWindow,MTI.ds.userfield.movie);
if tex<=0,
if tex<=0
done = 1;
break; % detect hitting the end of the movie
else
Expand All @@ -231,30 +235,29 @@
Screen('Flip',StimWindow);
frameTimes(frameNum) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,frameNum);
Screen('Close',tex);
end;
end;
end
end
Screen('PlayMovie',MTI.ds.userfield.movie,0); % stop the movie from playing

elseif strcmp(MTI.ds.displayType,'Sound'),
elseif strcmp(MTI.ds.displayType,'Sound')
startStopTimes(2) = StimTriggerAct('Stim_ONSET_trigger',MTI.stimid);
Snd('Play',MTI.ds.userfield.sound,MTI.ds.userfield.rate);
StimTriggerAct('Stim_beforeframe_trigger',MTI.stimid,1);
Snd('Wait');
frameTimes(1) = StimTriggerAct('Stim_afterframe_trigger',MTI.stimid,1);
end;

end

if MTI.postBGframes>0,
if NS_PTBv<3,
if MTI.postBGframes>0
if NS_PTBv<3
Screen(StimWindow,'SetClut',MTI.ds.clut_bg);
startStopTimes(3) = StimTriggerAct('Stim_OFFSET_trigger',MTI.stimid);
Screen(StimWindow,'WaitBlanking',MTI.postBGframes);
else
if 1,
if 1
vbl = show_background(StimWindow,MTI,[]);
show_background(StimWindow,MTI, vbl + (MTI.preBGframes-0.5)/StimWindowRefresh);
if capture_movie; Screen('AddFrameToMovie', StimWindow); end
elseif strcmpi(MTI.ds.displayType,'CLUTanim'),
elseif strcmpi(MTI.ds.displayType,'CLUTanim')
Screen(StimWindow,'FillRect',round(255*MTI.ds.clut_bg(1,:,:))); % make sure background is in 2nd buffer
vbl = Screen('Flip', StimWindow, 0); % wait for blanking
Screen(StimWindow,'FillRect',round(255*MTI.ds.clut_bg(1,:,:))); % make sure background is in 2nd buffer
Expand All @@ -264,8 +267,10 @@
vbl = Screen('Flip', StimWindow, 0); % wait for blanking
Screen('FillRect',StimWindow,round(255*MTI.ds.clut_bg(1,:,:))); % make sure background is installed
WaitSecs(0.2);
if StimWindowUseCLUTMapping, Screen('LoadNormalizedGammaTable',StimWindow,linspace(0,1,256)' * ones(1,3),1); end;
end;
if StimWindowUseCLUTMapping
Screen('LoadNormalizedGammaTable',StimWindow,linspace(0,1,256)' * ones(1,3),1);
end
end
startStopTimes(3) = StimTriggerAct('Stim_OFFSET_trigger',MTI.stimid);
Screen('Flip', StimWindow, vbl + (MTI.postBGframes+0.5)/StimWindowRefresh);
if capture_movie; Screen('AddFrameToMovie', StimWindow,[],[],[],MTI.postBGframes); end
Expand All @@ -282,13 +287,14 @@

startStopTimes(4) = StimTriggerAct('Stim_BGpost_trigger',MTI.stimid);

if strcmp(MTI.ds.displayType,'Sound'), Snd('Close'); end;
if strcmp(MTI.ds.displayType,'Sound')
Snd('Close');
end


if MTI.ds.makeClip && NS_PTBv<3, % clear the clipping region
if MTI.ds.makeClip && NS_PTBv<3 % clear the clipping region
Screen(StimWindow,'SetDrawingRegion',StimWindowRect);
end;

end


function vbl = show_background(StimWindow,MTI,when,dontsync)
Expand Down
4 changes: 2 additions & 2 deletions NewStim3/NewStimInit.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
if exist('NewStimConfiguration','file')
NewStimConfiguration;
%eval(['NewStimConfiguration;']);
end;
end

if isempty(which('NewStimConfiguration')) || ~VerifyNewStimConfiguration
vhlabtoolspath = fileparts(fileparts(pwd)); % 2 levels up
Expand All @@ -53,7 +53,7 @@
'analysis only, then no action is needed, you should be all set.']);
zz = which('NewStimConfiguration'); % force it to look again
eval('NewStimConfiguration;');
end;
end

if exist('PsychtoolboxVersion','file')
b = PsychtoolboxVersion;
Expand Down
Loading

0 comments on commit dbfcc9d

Please sign in to comment.