Skip to content

Proposed implementation for issue #403 - #431

Merged
dwalton76 merged 3 commits into
ev3dev:developfrom
EricPobot:develop
Nov 23, 2017
Merged

dwalton76 merged 3 commits into
ev3dev:developfrom
EricPobot:develop

Conversation

@EricPobot

Copy link
Copy Markdown
Contributor

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.

Comment thread ev3dev/sound.py Outdated
Args:
frequency (int): the tone frequency, in Hertz
duration (float): tone duration, in seconds
delay (float): delay after tone, in seconds

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use for the delay? Why doesn't the caller do that instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ev3dev/sound.py Outdated

if duration <= 0:
raise ValueError('invalid duration (%s)' % duration)
if delay <= 0:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't delay be 0?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be. Sorry for the copy/paste of this part of the sanity check code. I'll fix this ASAP.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just pushed a fix for this.

Comment thread ev3dev/sound.py

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``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@WasabiFan
WasabiFan requested a review from dwalton76 November 21, 2017 01:48
@dwalton76

Copy link
Copy Markdown
Collaborator

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
dwalton76 merged commit 5516016 into ev3dev:develop Nov 23, 2017
@EricPobot

Copy link
Copy Markdown
Contributor Author

@dwalton76 You're welcome ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants