From 4faa5d3df880bc2ceb8551f1c3d6434fbb897773 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Mon, 27 Jan 2020 13:25:42 +0100 Subject: [PATCH] doc/hubs.EV3Brick: toggle note specs This condenses long lists that are not frequently used. --- doc/api/hubs_ev3brick.inc | 21 +++++++++++++++++++++ pybricks/builtins.py | 21 +++------------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/doc/api/hubs_ev3brick.inc b/doc/api/hubs_ev3brick.inc index f514099..dbade4d 100644 --- a/doc/api/hubs_ev3brick.inc +++ b/doc/api/hubs_ev3brick.inc @@ -24,6 +24,27 @@ .. automethod:: pybricks.hubs::EV3Brick.speaker.play_notes + .. toggle-header:: + :header: **Show/hide musical note format** + + Each note is a string with the following format: + + - The first character is the name of the note, ``A`` to ``G`` or ``R`` + for a rest. + - Note names can also include an accidental ``#`` (sharp) or ``b`` + (flat). ``B#``/``Cb`` and ``E#``/``Fb`` are not allowed. + - The note name is followed by the octave number ``2`` to ``8``. For + example ``C4`` is middle C. The octave changes to the next number at + the note C, for example, ``B3`` is the note below middle C (``C4``). + - The octave is followed by ``/`` and a number that indicates the size + of the note. For example ``/4`` is a quarter note, ``/8`` is an + eight note and so on. + - This can optionally followed by a ``.`` to make a dotted note. + Dotted notes are 1-1/2 times as long as notes without a dot. + - The note can optionally end with a ``_`` which is a tie or a slur. + This causes there to be no pause between this note and the next note. + + .. automethod:: pybricks.hubs::EV3Brick.speaker.play_file .. automethod:: pybricks.hubs::EV3Brick.speaker.say diff --git a/pybricks/builtins.py b/pybricks/builtins.py index 8609e35..6b9c965 100644 --- a/pybricks/builtins.py +++ b/pybricks/builtins.py @@ -341,28 +341,13 @@ class Speaker(): pass def play_notes(self, notes, tempo=120): - """Play a sequence of notes. + """Play a sequence of musical notes. - Notes are strings with the following format: - - - The first character is the name of the note, ``A`` to ``G`` or ``R`` - for a rest. - - Note names can also include an accidental ``#`` (sharp) or ``b`` - (flat). ``B#``/``Cb`` and ``E#``/``Fb`` are not allowed. - - The note name is followed by the octave number ``2`` to ``8``. For - example ``C4`` is middle C. The octave changes to the next number at - the note C, for example, ``B3`` is the note below middle C (``C4``). - - The octave is followed by ``/`` and a number that indicates the size - of the note. For example ``/4`` is a quarter note, ``/8`` is an - eight note and so on. - - This can optionally followed by a ``.`` to make a dotted note. - Dotted notes are 1-1/2 times as long as notes without a dot. - - The note can optionally end with a ``_`` which is a tie or a slur. - This causes there to be no pause between this note and the next note. + For example, you can play: ``['C4/4', 'C4/4', 'G4/4', 'G4/4']``. Arguments: notes (iter): - A sequence of notes to be played (see format above). + A sequence of notes to be played (see format below). tempo (int): Beats per minute where a quarter note is one beat. """