Skip to content

Commit 9b46ff0

Browse files
dvbridgespeircej
authored andcommitted
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.
1 parent ce76d8e commit 9b46ff0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

psychopy/experiment/components/sound/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def __init__(self, exp, parentName, name='sound_1', sound='A', volume=1,
6262
def writeInitCode(self, buff):
6363
# replaces variable params with sensible defaults
6464
inits = getInitVals(self.params)
65-
if float(inits['stopVal'].val) > 2:
65+
if inits['stopVal'].val in ['', None, 'None']:
66+
inits['stopVal'].val = -1
67+
elif float(inits['stopVal'].val) > 2:
6668
inits['stopVal'].val = -1
6769
buff.writeIndented("%s = sound.Sound(%s, secs=%s)\n" %
6870
(inits['name'], inits['sound'], inits['stopVal']))
@@ -80,8 +82,8 @@ def writeFrameCode(self, buff):
8082
buff.writeIndented(code % self.params['name'])
8183
# because of the 'if' statement of the time test
8284
buff.setIndentLevel(-1, relative=True)
83-
if not float(self.params['stopVal'].val) < 2: # Reduce spectral splatter but not stopping short sounds
84-
if not self.params['stopVal'].val in ['', None, -1, 'None']:
85+
if not self.params['stopVal'].val in ['', None, -1, 'None']:
86+
if not float(self.params['stopVal'].val) < 2: # Reduce spectral splatter but not stopping short sounds
8587
self.writeStopTestCode(buff)
8688
code = "%s.stop() # stop the sound (if longer than duration)\n"
8789
buff.writeIndented(code % self.params['name'])

0 commit comments

Comments
 (0)