check-sounds_lastrun.py 33 KB
Newer Older
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
1 2 3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
4 5
This experiment was created using PsychoPy3 Experiment Builder (v2021.2.3),
    on April 26, 2022, at 19:47
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
6 7 8 9 10 11 12 13
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

"""

14 15
from __future__ import absolute_import, division

Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
16 17 18
from psychopy import locale_setup
from psychopy import prefs
prefs.hardware['audioLib'] = 'ptb'
19
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
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)
37

Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
38
# Store info about the experiment session
39
psychopyVersion = '2021.2.3'
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
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

81 82
# Setup eyetracking
ioDevice = ioConfig = ioSession = ioServer = eyetracker = None
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
83 84

# create a default keyboard (e.g. to check for escape)
85
defaultKeyboard = keyboard.Keyboard()
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
86 87 88 89 90 91 92

# 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)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
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()
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
116 117 118
sound_wav = sound.Sound('578626main_sputnik-beep.wav', secs=1.0, stereo=True, hamming=True,
    name='sound_wav')
sound_wav.setVolume(0.0)
119 120
text_3 = visual.TextStim(win=win, name='text_3',
    text='Creating sound_wav',
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
121 122 123 124
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0, 
    color='white', colorSpace='rgb', opacity=None, 
    languageStyle='LTR',
125 126 127 128 129 130 131 132 133 134 135 136 137 138
    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);
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
139 140 141 142 143 144

# Initialize components for Routine "set_volumes"
set_volumesClock = core.Clock()

# Initialize components for Routine "play_sounds"
play_soundsClock = core.Clock()
145 146 147
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',
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    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
179
text_instruct.alignText = 'left'
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
180 181 182
sound_440.setSound('440', secs=1.0, hamming=True)
sound_440.setVolume(0.0, log=False)
# keep track of which components have finished
183
create_soundsComponents = [sound_440, text]
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
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
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428

# ------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)
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
429
sound_wav.stop()  # ensure sound has stopped at end of routine
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518

# ------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)
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
519 520 521 522

# ------Prepare to start Routine "set_volumes"-------
continueRoutine = True
# update component parameters for each repeat
523
sound_C.setVolume(1)
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
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
584
play_soundsComponents = [text_instruct, key_resp, text_playing]
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
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:
608 609 610 611 612 613 614 615 616 617 618 619 620
            # 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':
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
621 622 623 624 625 626 627 628 629
                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':
630 631
                sound_C.play()
                text_playing.text = 'Note (C)'
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
632 633 634 635
            elif key_resp.keys[-1] == 'space':
                continueRoutine = False
            nKeys = len(key_resp.keys)
    
636 637
    # *text_instruct* updates
    if text_instruct.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
638
        # keep track of start time/frame for later
639 640 641 642 643
        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)
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
    
    # *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:
659
        theseKeys = key_resp.getKeys(keyList=['m', 'f', 'w', 'n', 'space', 's'], waitRelease=False)
Wakefield Morys-Carter's avatar
Wakefield Morys-Carter committed
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
        _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()