Repository navigation
Proposed implementation for issue #403 - #431
Conversation
| Args: | ||
| frequency (int): the tone frequency, in Hertz | ||
| duration (float): tone duration, in seconds | ||
| delay (float): delay after tone, in seconds |
There was a problem hiding this comment.
What's the use for the delay? Why doesn't the caller do that instead?
There was a problem hiding this comment.
The caller can take care of the delay between successive tones, but using the parameter makes its code simpler by avoiding additional time.delay() calls.
In addition, chances are that this will give more accurate timings, by removing the overhead added by the time.delay() additional call, the delay being managed directly by the beep system command.
|
|
||
| if duration <= 0: | ||
| raise ValueError('invalid duration (%s)' % duration) | ||
| if delay <= 0: |
There was a problem hiding this comment.
It can be. Sorry for the copy/paste of this part of the sanity check code. I'll fix this ASAP.
There was a problem hiding this comment.
I've just pushed a fix for this.
|
|
||
| def play(self, wav_file, play_type=PLAY_WAIT_FOR_COMPLETE): | ||
| def play_note(self, note, duration, volume=100, play_type=PLAY_WAIT_FOR_COMPLETE): | ||
| """ Plays a note, given by its name as defined in ``_NOTE_FREQUENCIES``. |
There was a problem hiding this comment.
For the musically-inept (e.g. me) could you include explanations to differentiate tone from note? I think tone is arbitrary frequency and notes are named frequencies, but I'm not the expert here.
There was a problem hiding this comment.
You're 100% right. play_note() is only a convenience call for tone() with the corresponding frequency. The tone() method was already there when I started to collaborate to this module, and it can be useful for arbitrary frequencies. However, I'd suggest to remove the example show how to play a song with tone() since IMHO it can lead to some confusion (you question is a perfect example of such a side effect). I didn't take the decision on my own since not the author of this part of the code.
|
The only musical instrument I can play is the radio so my knowledge here is about zero :) Looks good to me. Thank you for taking care of this one. |
|
@dwalton76 You're welcome ;) |
Adds the play_note method, and changes duration parameters of methods exposed as EV3-G blocks so that values are provided in seconds.
Documentation has been added in some places, minor changes done for better PEP compliance and additional method parameter checking added.