Skip to content

Commit

Permalink
BF: Fixes sound component error when duration is None.
Browse files Browse the repository at this point in the history
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 May 14, 2018
1 parent ce76d8e commit 9b46ff0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions psychopy/experiment/components/sound/__init__.py
Expand Up @@ -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']))
Expand All @@ -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'])
Expand Down

0 comments on commit 9b46ff0

Please sign in to comment.