Skip to content

Commit

Permalink
Changing how playback is checked
Browse files Browse the repository at this point in the history
The .status==PLAYING functionality seems to have been superseded by a built-in boolean .isPlaying. All PyHabClass versions have now been updated to use this new approach.
  • Loading branch information
jfkominsky committed Feb 14, 2025
1 parent f74034c commit 55787ad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
16 changes: 8 additions & 8 deletions PyHab/PyHabClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,15 +2081,15 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
tempGazeArray = {'trial':number, 'trialType':dataType, 'startTime':startOff, 'endTime':endOff, 'duration':offDur}
offArray.append(tempGazeArray)
if localType in self.dynamicPause and self.stimPres:
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie['stim'].status != PLAYING:
if disMovie['stimType'] in ['Movie', 'Audio'] and not disMovie['stim'].isPlaying:
disMovie['stim'].play()
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].status != PLAYING:
elif disMovie['stimType'] == ['Image with audio'] and not disMovie['stim']['Audio'].isPlaying:
disMovie['stim']['Audio'].play()
else:
if localType in self.dynamicPause and self.stimPres:
if disMovie['stimType'] in ['Movie','Audio'] and disMovie['stim'].status == PLAYING:
if disMovie['stimType'] in ['Movie','Audio'] and disMovie['stim'].isPlaying:
disMovie['stim'].pause()
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].status == PLAYING:
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].isPlaying:
disMovie['stim']['Audio'].pause()
if localType in self.midAG and self.stimPres:
try:
Expand All @@ -2102,9 +2102,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if nowOff - startAG >= self.midAG[localType]['trigger']:
# TODO: Do something here to deal with recording data about mid-trial AG behavior?
if localType not in self.dynamicPause: # Need to pause it anyways to play the AG so they don't overlap
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie['stim'].status == PLAYING:
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie['stim'].isPlaying:
disMovie['stim'].pause()
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].status == PLAYING:
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].isPlaying:
disMovie['stim']['Audio'].pause()
startAG = core.getTime() - startTrial
tempTiming = {'trialNum': number, 'trialType': dataType, 'event': 'startAttnGetter',
Expand All @@ -2122,9 +2122,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
durAG = endAG - startAG
maxDurAdd = maxDurAdd + durAG # Increase max length of trial by duration that AG played.
if localType not in self.dynamicPause:
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie['stim'].status != PLAYING:
if disMovie['stimType'] in ['Movie', 'Audio'] and not disMovie['stim'].isPlaying:
disMovie['stim'].play()
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].status != PLAYING:
elif disMovie['stimType'] == ['Image with audio'] and not disMovie['stim']['Audio'].isPlaying:
disMovie['stim']['Audio'].play()

elif gazeOn:
Expand Down
42 changes: 21 additions & 21 deletions PyHab/PyHabClassHPP.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if localType in self.dynamicPause and self.stimPres:
# Let's get fancy: This now only starts playing the thing on the screen they're looking at!
if disMovie['C'] != 0:
if disMovie['C']['stimType'] in ['Movie', 'Audio'] and disMovie['C']['stim'].status != PLAYING:
if disMovie['C']['stimType'] in ['Movie', 'Audio'] and not disMovie['C']['stim'].isPlaying:
disMovie['C']['stim'].play()
elif disMovie['C']['stimType'] == ['Image with audio'] and disMovie['C']['stim']['Audio'].status != PLAYING:
elif disMovie['C']['stimType'] == ['Image with audio'] and not disMovie['C']['stim']['Audio'].isPlaying:
disMovie['C']['stim']['Audio'].play()
elif self.keyboard[self.leftKey]:
gazeOnL = True
Expand All @@ -679,9 +679,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if localType in self.dynamicPause and self.stimPres:
# Let's get fancy: This now only starts playing the thing on the screen they're looking at!
if disMovie['L'] != 0:
if disMovie['L']['stimType'] in ['Movie', 'Audio'] and disMovie['L']['stim'].status != PLAYING:
if disMovie['L']['stimType'] in ['Movie', 'Audio'] and not disMovie['L']['stim'].isPlaying:
disMovie['L']['stim'].play()
elif disMovie['L']['stimType'] == ['Image with audio'] and disMovie['L']['stim']['Audio'].status != PLAYING:
elif disMovie['L']['stimType'] == ['Image with audio'] and not disMovie['L']['stim']['Audio'].isPlaying:
disMovie['L']['stim']['Audio'].play()
elif self.keyboard[self.rightKey]:
gazeOnR = True
Expand All @@ -696,9 +696,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if localType in self.dynamicPause and self.stimPres:
# Let's get fancy: This now only starts playing the thing on the screen they're looking at!
if disMovie['R'] != 0:
if disMovie['R']['stimType'] in ['Movie', 'Audio'] and disMovie['R']['stim'].status != PLAYING:
if disMovie['R']['stimType'] in ['Movie', 'Audio'] and not disMovie['R']['stim'].isPlaying:
disMovie['R']['stim'].play()
elif disMovie['R']['stimType'] == ['Image with audio'] and disMovie['R']['stim']['Audio'].status != PLAYING:
elif disMovie['R']['stimType'] == ['Image with audio'] and not disMovie['R']['stim']['Audio'].isPlaying:
disMovie['R']['stim']['Audio'].play()
else:
if localType in self.midAG and self.stimPres:
Expand All @@ -707,9 +707,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if localType not in self.dynamicPause: # Need to pause it anyways to play the AG so they don't overlap
for i,j in disMovie.items():
if j != 0:
if j['stimType'] in ['Movie', 'Audio'] and j['stim'].status == PLAYING:
if j['stimType'] in ['Movie', 'Audio'] and j['stim'].isPlaying:
j['stim'].pause()
elif j['stimType'] == ['Image with audio'] and j['stim']['Audio'].status == PLAYING:
elif j['stimType'] == ['Image with audio'] and j['stim']['Audio'].isPlaying:
j['stim']['Audio'].pause()
startAG = core.getTime()
tempTiming = {'trialNum': number, 'trialType': dataType, 'event': 'startAttnGetter',
Expand All @@ -724,9 +724,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if localType not in self.dynamicPause:
for i,j in disMovie.items():
if j != 0:
if j['stimType'] in ['Movie', 'Audio'] and j['stim'].status != PLAYING:
if j['stimType'] in ['Movie', 'Audio'] and not j['stim'].isPlaying:
j['stim'].play()
elif j['stimType'] == ['Image with audio'] and j['stim']['Audio'].status != PLAYING:
elif j['stimType'] == ['Image with audio'] and not j['stim']['Audio'].isPlaying:
j['stim']['Audio'].play()
elif gazeOnC or gazeOnL or gazeOnR:
nowOn = core.getTime() - startTrial
Expand Down Expand Up @@ -862,9 +862,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if localType not in self.dynamicPause: # Need to pause it anyways to play the AG so they don't overlap
for i, j in disMovie.items():
if j != 0:
if j['stimType'] in ['Movie', 'Audio'] and j['stim'].status == PLAYING:
if j['stimType'] in ['Movie', 'Audio'] and j['stim'].isPlaying:
j['stim'].pause()
elif j['stimType'] == ['Image with audio'] and j['stim']['Audio'].status == PLAYING:
elif j['stimType'] == ['Image with audio'] and j['stim']['Audio'].isPlaying:
j['stim']['Audio'].pause()
startAG = core.getTime()
self.attnGetter(localType, self.midAG[localType]['cutoff'],
Expand All @@ -874,10 +874,10 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if localType not in self.dynamicPause:
for i, j in disMovie.items():
if j != 0:
if j['stimType'] in ['Movie', 'Audio'] and j['stim'].status != PLAYING:
if j['stimType'] in ['Movie', 'Audio'] and not j['stim'].isPlaying:
j['stim'].play()
elif j['stimType'] == ['Image with audio'] and j['stim'][
'Audio'].status != PLAYING:
elif j['stimType'] == ['Image with audio'] and not j['stim'][
'Audio'].isPlaying:
j['stim']['Audio'].play()


Expand All @@ -891,9 +891,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
sumOnC = sumOnC + onDur
if localType in self.dynamicPause and self.stimPres:
if disMovie['C'] != 0:
if disMovie['C']['stimType'] in ['Movie','Audio'] and disMovie['C']['stim'].status == PLAYING:
if disMovie['C']['stimType'] in ['Movie','Audio'] and disMovie['C']['stim'].isPlaying:
disMovie['C']['stim'].pause()
elif disMovie['C']['stimType'] == ['Image with audio'] and disMovie['C']['stim']['Audio'].status == PLAYING:
elif disMovie['C']['stimType'] == ['Image with audio'] and disMovie['C']['stim']['Audio'].isPlaying:
disMovie['C']['stim']['Audio'].pause()
if self.keyboard[self.leftKey]:
gazeOnL = True
Expand Down Expand Up @@ -925,9 +925,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
sumOnL = sumOnL + onDur
if localType in self.dynamicPause and self.stimPres:
if disMovie['L'] != 0:
if disMovie['L']['stimType'] in ['Movie','Audio'] and disMovie['L']['stim'].status == PLAYING:
if disMovie['L']['stimType'] in ['Movie','Audio'] and disMovie['L']['stim'].isPlaying:
disMovie['L']['stim'].pause()
elif disMovie['L']['stimType'] == ['Image with audio'] and disMovie['L']['stim']['Audio'].status == PLAYING:
elif disMovie['L']['stimType'] == ['Image with audio'] and disMovie['L']['stim']['Audio'].isPlaying:
disMovie['L']['stim']['Audio'].pause()
if self.keyboard[self.centerKey]:
gazeOnC = True
Expand Down Expand Up @@ -959,9 +959,9 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
sumOnR = sumOnR + onDur
if localType in self.dynamicPause and self.stimPres:
if disMovie['R'] != 0:
if disMovie['R']['stimType'] in ['Movie','Audio'] and disMovie['R']['stim'].status == PLAYING:
if disMovie['R']['stimType'] in ['Movie','Audio'] and disMovie['R']['stim'].isPlaying:
disMovie['R']['stim'].pause()
elif disMovie['R']['stimType'] == ['Image with audio'] and disMovie['R']['stim']['Audio'].status == PLAYING:
elif disMovie['R']['stimType'] == ['Image with audio'] and disMovie['R']['stim']['Audio'].isPlaying:
disMovie['R']['stim']['Audio'].pause()
if self.keyboard[self.centerKey]:
gazeOnC = True
Expand Down
17 changes: 8 additions & 9 deletions PyHab/PyHabClassPL.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,20 +451,19 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
if np.nan in gpos:
#gaze off
if localType in self.dynamicPause and self.stimPres:
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie['stim'].status == PLAYING:
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie['stim'].isPlaying:
disMovie['stim'].pause()
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim'][
'Audio'].status == PLAYING:
'Audio'].isPlaying:
disMovie['stim']['Audio'].pause()
if localType in self.midAG and self.stimPres:
if nowOff - startOff >= self.midAG[localType]['trigger']:
# TODO: Do something here to deal with recording data about mid-trial AG behavior?
if localType not in self.dynamicPause: # Need to pause it anyways to play the AG so they don't overlap
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie[
'stim'].status == PLAYING:
'stim'].isPlaying:
disMovie['stim'].pause()
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim'][
'Audio'].status == PLAYING:
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].isPlaying:
disMovie['stim']['Audio'].pause()
tempTiming = {'trialNum': number, 'trialType': dataType, 'event': 'startAttnGetter',
'time': (core.getTime() - self.absoluteStart)}
Expand Down Expand Up @@ -557,17 +556,17 @@ def onDuration(adds=0, subs=0): # A function for the duration switch, while lea
disMovie['stim']['Audio'].play()
else:
if localType in self.dynamicPause and self.stimPres:
if disMovie['stimType'] in ['Movie','Audio'] and disMovie['stim'].status == PLAYING:
if disMovie['stimType'] in ['Movie','Audio'] and disMovie['stim'].isPlaying:
disMovie['stim'].pause()
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].status == PLAYING:
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].isPlaying:
disMovie['stim']['Audio'].pause()
if localType in self.midAG and self.stimPres:
if nowOff - startOff >= self.midAG[localType]['trigger']:
# TODO: Do something here to deal with recording data about mid-trial AG behavior?
if localType not in self.dynamicPause: # Need to pause it anyways to play the AG so they don't overlap
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie['stim'].status == PLAYING:
if disMovie['stimType'] in ['Movie', 'Audio'] and disMovie['stim'].isPlaying:
disMovie['stim'].pause()
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].status == PLAYING:
elif disMovie['stimType'] == ['Image with audio'] and disMovie['stim']['Audio'].isPlaying:
disMovie['stim']['Audio'].pause()
tempTiming = {'trialNum': number, 'trialType': dataType, 'event': 'startAttnGetter',
'time': (core.getTime() - self.absoluteStart)}
Expand Down

0 comments on commit 55787ad

Please sign in to comment.