Permalink
Browse files

BF: Fixes sound component error when duration is None.

When no duration is given, a ValueError is raised when the None string
is converted into a float. This fix changes the conditional statements
to set stopVal to -1 if no duration is given.
  • Loading branch information...
dvbridges authored and peircej committed Apr 11, 2018
1 parent ce76d8e commit 9b46ff0c04e05d3738b14c72581f4baedfcbd627
Showing with 5 additions and 3 deletions.
  1. +5 −3 psychopy/experiment/components/sound/__init__.py
@@ -62,7 +62,9 @@ def __init__(self, exp, parentName, name='sound_1', sound='A', volume=1,
def writeInitCode(self, buff):
# replaces variable params with sensible defaults
inits = getInitVals(self.params)
if float(inits['stopVal'].val) > 2:
if inits['stopVal'].val in ['', None, 'None']:
inits['stopVal'].val = -1
elif float(inits['stopVal'].val) > 2:
inits['stopVal'].val = -1
buff.writeIndented("%s = sound.Sound(%s, secs=%s)\n" %
(inits['name'], inits['sound'], inits['stopVal']))
@@ -80,8 +82,8 @@ def writeFrameCode(self, buff):
buff.writeIndented(code % self.params['name'])
# because of the 'if' statement of the time test
buff.setIndentLevel(-1, relative=True)
if not float(self.params['stopVal'].val) < 2: # Reduce spectral splatter but not stopping short sounds
if not self.params['stopVal'].val in ['', None, -1, 'None']:
if not self.params['stopVal'].val in ['', None, -1, 'None']:
if not float(self.params['stopVal'].val) < 2: # Reduce spectral splatter but not stopping short sounds
self.writeStopTestCode(buff)
code = "%s.stop() # stop the sound (if longer than duration)\n"
buff.writeIndented(code % self.params['name'])

0 comments on commit 9b46ff0

Please sign in to comment.