#!/usr/bin/env python # -*- coding: utf-8 -*- """ This experiment was created using PsychoPy3 Experiment Builder (v2021.2.3), on April 26, 2022, at 19:47 If you publish work using this script the most relevant publication is: Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019) PsychoPy2: Experiments in behavior made easy Behav Res 51: 195. https://doi.org/10.3758/s13428-018-01193-y """ from __future__ import absolute_import, division from psychopy import locale_setup from psychopy import prefs prefs.hardware['audioLib'] = 'ptb' from psychopy import sound, gui, visual, core, data, event, logging, clock, colors from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED, STOPPED, FINISHED, PRESSED, RELEASED, FOREVER) import numpy as np # whole numpy lib is available, prepend 'np.' from numpy import (sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray) from numpy.random import random, randint, normal, shuffle, choice as randchoice import os # handy system and path functions import sys # to get file system encoding from psychopy.hardware import keyboard # Ensure that relative paths start from the same directory as this script _thisDir = os.path.dirname(os.path.abspath(__file__)) os.chdir(_thisDir) # Store info about the experiment session psychopyVersion = '2021.2.3' expName = 'check-sounds' # from the Builder filename that created this script expInfo = {'participant': '', 'session': '001'} dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName expInfo['psychopyVersion'] = psychopyVersion # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date']) # An ExperimentHandler isn't essential but helps with data saving thisExp = data.ExperimentHandler(name=expName, version='', extraInfo=expInfo, runtimeInfo=None, originPath='C:\\Users\\p0071480\\Documents\\Pavlovia\\vespr\\check-sounds\\check-sounds_lastrun.py', savePickle=True, saveWideText=True, dataFileName=filename) # save a log file for detail verbose info logFile = logging.LogFile(filename+'.log', level=logging.EXP) logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file endExpNow = False # flag for 'escape' or other condition => quit the exp frameTolerance = 0.001 # how close to onset before 'same' frame # Start Code - component code to be run after the window creation # Setup the Window win = visual.Window( size=[1920, 1080], fullscr=True, screen=0, winType='pyglet', allowGUI=False, allowStencil=False, monitor='testMonitor', color=[0,0,0], colorSpace='rgb', blendMode='avg', useFBO=True, units='height') # store frame rate of monitor if we can measure it expInfo['frameRate'] = win.getActualFrameRate() if expInfo['frameRate'] != None: frameDur = 1.0 / round(expInfo['frameRate']) else: frameDur = 1.0 / 60.0 # could not measure, so guess # Setup eyetracking ioDevice = ioConfig = ioSession = ioServer = eyetracker = None # create a default keyboard (e.g. to check for escape) defaultKeyboard = keyboard.Keyboard() # Initialize components for Routine "create_sounds" create_soundsClock = core.Clock() version = 'p' sound_440 = sound.Sound('440', secs=1.0, stereo=True, hamming=True, name='sound_440') sound_440.setVolume(0.0) text = visual.TextStim(win=win, name='text', text='Creating sound_440', font='Arial', pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0, color='white', colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-2.0); # Initialize components for Routine "create_note" create_noteClock = core.Clock() sound_C = sound.Sound('C', secs=1.0, stereo=True, hamming=True, name='sound_C') sound_C.setVolume(0.0) text_4 = visual.TextStim(win=win, name='text_4', text='Creating sound_C', font='Arial', pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0, color='white', colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-1.0); # Initialize components for Routine "create_wav" create_wavClock = core.Clock() sound_wav = sound.Sound('578626main_sputnik-beep.wav', secs=1.0, stereo=True, hamming=True, name='sound_wav') sound_wav.setVolume(0.0) text_3 = visual.TextStim(win=win, name='text_3', text='Creating sound_wav', font='Arial', pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0, color='white', colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-1.0); # Initialize components for Routine "create_mp3" create_mp3Clock = core.Clock() sound_mp3 = sound.Sound('A', secs=1.0, stereo=True, hamming=True, name='sound_mp3') sound_mp3.setVolume(0.0) text_2 = visual.TextStim(win=win, name='text_2', text='Creating sound_mp3', font='Arial', pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0, color='white', colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-2.0); # Initialize components for Routine "set_volumes" set_volumesClock = core.Clock() # Initialize components for Routine "play_sounds" play_soundsClock = core.Clock() text_instruct = visual.TextStim(win=win, name='text_instruct', text='Select Sound\nNote N\nFrequency F\nMP3 M\nWAV W\n\nStop sounds S\nEnd space\n', font='Courier New', pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0, color='white', colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-1.0); key_resp = keyboard.Keyboard() text_playing = visual.TextStim(win=win, name='text_playing', text=None, font='Arial', pos=(0, -.3), height=0.05, wrapWidth=None, ori=0.0, color='white', colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-3.0); # Initialize components for Routine "end" endClock = core.Clock() text_end = visual.TextStim(win=win, name='text_end', text='Fin', font='Arial', pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0, color='white', colorSpace='rgb', opacity=None, languageStyle='LTR', depth=0.0); # Create some handy timers globalClock = core.Clock() # to track the time since experiment started routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine # ------Prepare to start Routine "create_sounds"------- continueRoutine = True routineTimer.add(1.000000) # update component parameters for each repeat text_instruct.alignText = 'left' sound_440.setSound('440', secs=1.0, hamming=True) sound_440.setVolume(0.0, log=False) # keep track of which components have finished create_soundsComponents = [sound_440, text] for thisComponent in create_soundsComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") create_soundsClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "create_sounds"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = create_soundsClock.getTime() tThisFlip = win.getFutureFlipTime(clock=create_soundsClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # start/stop sound_440 if sound_440.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later sound_440.frameNStart = frameN # exact frame index sound_440.tStart = t # local t and not account for scr refresh sound_440.tStartRefresh = tThisFlipGlobal # on global time sound_440.play(when=win) # sync with win flip if sound_440.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > sound_440.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later sound_440.tStop = t # not accounting for scr refresh sound_440.frameNStop = frameN # exact frame index win.timeOnFlip(sound_440, 'tStopRefresh') # time at next scr refresh sound_440.stop() # *text* updates if text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later text.frameNStart = frameN # exact frame index text.tStart = t # local t and not account for scr refresh text.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text, 'tStartRefresh') # time at next scr refresh text.setAutoDraw(True) if text.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > text.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later text.tStop = t # not accounting for scr refresh text.frameNStop = frameN # exact frame index win.timeOnFlip(text, 'tStopRefresh') # time at next scr refresh text.setAutoDraw(False) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in create_soundsComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "create_sounds"------- for thisComponent in create_soundsComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) sound_440.stop() # ensure sound has stopped at end of routine # ------Prepare to start Routine "create_note"------- continueRoutine = True routineTimer.add(1.000000) # update component parameters for each repeat sound_C.setSound('C', secs=1.0, hamming=True) sound_C.setVolume(0.0, log=False) # keep track of which components have finished create_noteComponents = [sound_C, text_4] for thisComponent in create_noteComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") create_noteClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "create_note"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = create_noteClock.getTime() tThisFlip = win.getFutureFlipTime(clock=create_noteClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # start/stop sound_C if sound_C.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later sound_C.frameNStart = frameN # exact frame index sound_C.tStart = t # local t and not account for scr refresh sound_C.tStartRefresh = tThisFlipGlobal # on global time sound_C.play(when=win) # sync with win flip if sound_C.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > sound_C.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later sound_C.tStop = t # not accounting for scr refresh sound_C.frameNStop = frameN # exact frame index win.timeOnFlip(sound_C, 'tStopRefresh') # time at next scr refresh sound_C.stop() # *text_4* updates if text_4.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later text_4.frameNStart = frameN # exact frame index text_4.tStart = t # local t and not account for scr refresh text_4.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text_4, 'tStartRefresh') # time at next scr refresh text_4.setAutoDraw(True) if text_4.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > text_4.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later text_4.tStop = t # not accounting for scr refresh text_4.frameNStop = frameN # exact frame index win.timeOnFlip(text_4, 'tStopRefresh') # time at next scr refresh text_4.setAutoDraw(False) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in create_noteComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "create_note"------- for thisComponent in create_noteComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) sound_C.stop() # ensure sound has stopped at end of routine # ------Prepare to start Routine "create_wav"------- continueRoutine = True routineTimer.add(1.000000) # update component parameters for each repeat sound_wav.setSound('578626main_sputnik-beep.wav', secs=1.0, hamming=True) sound_wav.setVolume(0.0, log=False) # keep track of which components have finished create_wavComponents = [sound_wav, text_3] for thisComponent in create_wavComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") create_wavClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "create_wav"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = create_wavClock.getTime() tThisFlip = win.getFutureFlipTime(clock=create_wavClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # start/stop sound_wav if sound_wav.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later sound_wav.frameNStart = frameN # exact frame index sound_wav.tStart = t # local t and not account for scr refresh sound_wav.tStartRefresh = tThisFlipGlobal # on global time sound_wav.play(when=win) # sync with win flip if sound_wav.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > sound_wav.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later sound_wav.tStop = t # not accounting for scr refresh sound_wav.frameNStop = frameN # exact frame index win.timeOnFlip(sound_wav, 'tStopRefresh') # time at next scr refresh sound_wav.stop() # *text_3* updates if text_3.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later text_3.frameNStart = frameN # exact frame index text_3.tStart = t # local t and not account for scr refresh text_3.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text_3, 'tStartRefresh') # time at next scr refresh text_3.setAutoDraw(True) if text_3.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > text_3.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later text_3.tStop = t # not accounting for scr refresh text_3.frameNStop = frameN # exact frame index win.timeOnFlip(text_3, 'tStopRefresh') # time at next scr refresh text_3.setAutoDraw(False) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in create_wavComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "create_wav"------- for thisComponent in create_wavComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) sound_wav.stop() # ensure sound has stopped at end of routine # ------Prepare to start Routine "create_mp3"------- continueRoutine = True routineTimer.add(1.000000) # update component parameters for each repeat if version == 'p': continueRoutine = False sound_mp3.setSound('578626main_sputnik-beep.mp3', secs=1.0, hamming=True) sound_mp3.setVolume(0.0, log=False) # keep track of which components have finished create_mp3Components = [sound_mp3, text_2] for thisComponent in create_mp3Components: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") create_mp3Clock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "create_mp3"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = create_mp3Clock.getTime() tThisFlip = win.getFutureFlipTime(clock=create_mp3Clock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # start/stop sound_mp3 if sound_mp3.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later sound_mp3.frameNStart = frameN # exact frame index sound_mp3.tStart = t # local t and not account for scr refresh sound_mp3.tStartRefresh = tThisFlipGlobal # on global time sound_mp3.play(when=win) # sync with win flip if sound_mp3.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > sound_mp3.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later sound_mp3.tStop = t # not accounting for scr refresh sound_mp3.frameNStop = frameN # exact frame index win.timeOnFlip(sound_mp3, 'tStopRefresh') # time at next scr refresh sound_mp3.stop() # *text_2* updates if text_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later text_2.frameNStart = frameN # exact frame index text_2.tStart = t # local t and not account for scr refresh text_2.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text_2, 'tStartRefresh') # time at next scr refresh text_2.setAutoDraw(True) if text_2.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > text_2.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later text_2.tStop = t # not accounting for scr refresh text_2.frameNStop = frameN # exact frame index win.timeOnFlip(text_2, 'tStopRefresh') # time at next scr refresh text_2.setAutoDraw(False) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in create_mp3Components: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "create_mp3"------- for thisComponent in create_mp3Components: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) sound_mp3.stop() # ensure sound has stopped at end of routine thisExp.addData('sound_mp3.started', sound_mp3.tStartRefresh) thisExp.addData('sound_mp3.stopped', sound_mp3.tStopRefresh) # ------Prepare to start Routine "set_volumes"------- continueRoutine = True # update component parameters for each repeat sound_C.setVolume(1) sound_440.setVolume(1) sound_wav.setVolume(1) if version == 'j': sound_mp3.setVolume(1) # MP3 fails offline # keep track of which components have finished set_volumesComponents = [] for thisComponent in set_volumesComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") set_volumesClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "set_volumes"------- while continueRoutine: # get current time t = set_volumesClock.getTime() tThisFlip = win.getFutureFlipTime(clock=set_volumesClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in set_volumesComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "set_volumes"------- for thisComponent in set_volumesComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # the Routine "set_volumes" was not non-slip safe, so reset the non-slip timer routineTimer.reset() # ------Prepare to start Routine "play_sounds"------- continueRoutine = True # update component parameters for each repeat nKeys = 0 key_resp.keys = [] key_resp.rt = [] _key_resp_allKeys = [] # keep track of which components have finished play_soundsComponents = [text_instruct, key_resp, text_playing] for thisComponent in play_soundsComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") play_soundsClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "play_sounds"------- while continueRoutine: # get current time t = play_soundsClock.getTime() tThisFlip = win.getFutureFlipTime(clock=play_soundsClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame if key_resp.keys: if len(key_resp.keys) > nKeys: # Stop current sound if key_resp.keys[-1] == 's': if text_playing.text == 'MP3': sound_mp3.stop() elif text_playing.text == 'Frequency (440Hz)': sound_440.stop() elif text_playing.text == 'WAV': sound_wav.stop() elif text_playing.text == 'Note (C)': sound_C.stop() text_playing.text = '' # Start new sound elif key_resp.keys[-1] == 'm' and version == 'j': sound_mp3.play() text_playing.text = 'MP3' elif key_resp.keys[-1] == 'f': sound_440.play() text_playing.text = 'Frequency (440Hz)' elif key_resp.keys[-1] == 'w': sound_wav.play() text_playing.text = 'WAV' elif key_resp.keys[-1] == 'n': sound_C.play() text_playing.text = 'Note (C)' elif key_resp.keys[-1] == 'space': continueRoutine = False nKeys = len(key_resp.keys) # *text_instruct* updates if text_instruct.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later text_instruct.frameNStart = frameN # exact frame index text_instruct.tStart = t # local t and not account for scr refresh text_instruct.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text_instruct, 'tStartRefresh') # time at next scr refresh text_instruct.setAutoDraw(True) # *key_resp* updates waitOnFlip = False if key_resp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later key_resp.frameNStart = frameN # exact frame index key_resp.tStart = t # local t and not account for scr refresh key_resp.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(key_resp, 'tStartRefresh') # time at next scr refresh key_resp.status = STARTED # keyboard checking is just starting waitOnFlip = True win.callOnFlip(key_resp.clock.reset) # t=0 on next screen flip win.callOnFlip(key_resp.clearEvents, eventType='keyboard') # clear events on next screen flip if key_resp.status == STARTED and not waitOnFlip: theseKeys = key_resp.getKeys(keyList=['m', 'f', 'w', 'n', 'space', 's'], waitRelease=False) _key_resp_allKeys.extend(theseKeys) if len(_key_resp_allKeys): key_resp.keys = [key.name for key in _key_resp_allKeys] # storing all keys key_resp.rt = [key.rt for key in _key_resp_allKeys] # *text_playing* updates if text_playing.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later text_playing.frameNStart = frameN # exact frame index text_playing.tStart = t # local t and not account for scr refresh text_playing.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text_playing, 'tStartRefresh') # time at next scr refresh text_playing.setAutoDraw(True) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in play_soundsComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "play_sounds"------- for thisComponent in play_soundsComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # check responses if key_resp.keys in ['', [], None]: # No response was made key_resp.keys = None thisExp.addData('key_resp.keys',key_resp.keys) if key_resp.keys != None: # we had a response thisExp.addData('key_resp.rt', key_resp.rt) thisExp.addData('key_resp.started', key_resp.tStartRefresh) thisExp.addData('key_resp.stopped', key_resp.tStopRefresh) thisExp.nextEntry() # the Routine "play_sounds" was not non-slip safe, so reset the non-slip timer routineTimer.reset() # ------Prepare to start Routine "end"------- continueRoutine = True routineTimer.add(1.000000) # update component parameters for each repeat # keep track of which components have finished endComponents = [text_end] for thisComponent in endComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") endClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "end"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = endClock.getTime() tThisFlip = win.getFutureFlipTime(clock=endClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *text_end* updates if text_end.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later text_end.frameNStart = frameN # exact frame index text_end.tStart = t # local t and not account for scr refresh text_end.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text_end, 'tStartRefresh') # time at next scr refresh text_end.setAutoDraw(True) if text_end.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > text_end.tStartRefresh + 1.0-frameTolerance: # keep track of stop time/frame for later text_end.tStop = t # not accounting for scr refresh text_end.frameNStop = frameN # exact frame index win.timeOnFlip(text_end, 'tStopRefresh') # time at next scr refresh text_end.setAutoDraw(False) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in endComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "end"------- for thisComponent in endComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # Flip one final time so any remaining win.callOnFlip() # and win.timeOnFlip() tasks get executed before quitting win.flip() # these shouldn't be strictly necessary (should auto-save) thisExp.saveAsWideText(filename+'.csv', delim='auto') thisExp.saveAsPickle(filename) logging.flush() # make sure everything is closed down thisExp.abort() # or data files will save again on exit win.close() core.quit()