psychopy/psychopy — pull request #221 by kastman (2012-11-01 19:59:59+00:00)
Title: setSound should fail when given a bad value instead of defaulting to a tone

Although sound.py is supposed to raise an error if a sound's value cannot be figured out heuristically, it effectively only does that check on initialization. This is because it fails only if the instance var _snd is None, which only occurs directly after initialization.

When a Sound Builder Component is set to "set each repeat", it initializes a sound with a dummy value (so _snd is initialized to a tone) and doesn't do any smart checking to ensure that the files to be presented each repeat exist. Later during repeat, if a sound file doesn't exist, this currently doesn't fail because the previous sound (the dummy tone) is valid.

This has the effect of causing experiments created with Builder to default to a tone instead of raising an error when a bad filepath is given.

By resetting _snd at the beginning of each setSound call, each new sound will either be set correctly or raise an error, as appropriate. This does introduce the possibility of raising an error halfway through an experiment, so we it would be nice to have some smart checking of stimuli at experiment initialization, but at least the error will be more obvious now and easier to fix given this PR.