FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
This API defines a player of melodies, defined as a sequence of tones and durations. More...
#include <fastarduino/devices/tone_player.h>
Public Types | |
using | GENERATOR = typename BASE::GENERATOR |
The type of ToneGenerator to use as constructor's argument. More... | |
using | TONE_PLAY = typename BASE::TONE_PLAY |
The type that holds unit of information of a melody. More... | |
Public Member Functions | |
TonePlayer (GENERATOR &tone_generator) | |
Create a new synchronous tone player, based on an existing ToneGenerator . More... | |
void | play_sram (const TONE_PLAY *melody, const Beat &beat) |
Play a melody, defined by a sequence of TONE_PLAY s, stored in SRAM. More... | |
void | play_eeprom (const TONE_PLAY *melody, const Beat &beat) |
Play a melody, defined by a sequence of TONE_PLAY s, stored in EEPROM. More... | |
void | play_flash (const TONE_PLAY *melody, const Beat &beat) |
Play a melody, defined by a sequence of TONE_PLAY s, stored in Flash. More... | |
void | stop () |
Stop playing current melody (if any). More... | |
bool | is_playing () const |
Tell if a melody is currently playing. More... | |
Additional Inherited Members | |
Protected Types inherited from devices::audio::AbstractTonePlayer< NTIMER, OUTPUT, TONEPLAY > | |
using | TONE_PLAY = TONEPLAY |
The type that holds unit of information of a melody. More... | |
using | GENERATOR = ToneGenerator< NTIMER, OUTPUT > |
The type of ToneGenerator to use as constructor's argument. More... | |
Protected Member Functions inherited from devices::audio::AbstractTonePlayer< NTIMER, OUTPUT, TONEPLAY > | |
AbstractTonePlayer (GENERATOR &tone_generator) | |
Create a new tone player, based on an existing ToneGenerator . More... | |
void | set_min_duration (uint16_t min_duration) |
Set the duration, in milliseconds, of a 32nd note. More... | |
uint16_t | get_min_duration () const |
Get the duration, in milliseconds, of a 32nd note. More... | |
void | prepare_sram (const TONE_PLAY *melody) |
Prepare playing of melody , which should be stored in SRAM. More... | |
void | prepare_eeprom (const TONE_PLAY *melody) |
Prepare playing of melody , which should be stored in EEPROM. More... | |
void | prepare_flash (const TONE_PLAY *melody) |
Prepare playing of melody , which should be stored in Flash. More... | |
uint16_t | start_next_note () |
Ask this player to start playing the next note of the melody. More... | |
uint16_t | stop_current_note () |
Ask this player to stop playing the current note of the melody. More... | |
bool | is_finished () const |
Indicate if the currently played melody is finished. More... | |
This API defines a player of melodies, defined as a sequence of tones and durations.
This player is synchronous, i.e. when asking it to play a melody, the called method will not return until the melody is finished playing (or if stop()
has been called, e.g. by an ISR).
Melodies are defined as sequence of unit information, which can be either:
TonePlay
s: easy to write in source code but not efficient in size of generated codeQTonePlay
s: requires more effort in source code, but reduces generated code size Which types is used is defined as the TONEPLAY
template parameter.With this API, played melodies can be stored on 3 possible locations:
Each API has 3 distinct methods, one for each storage strategy.
NTIMER | the AVR timer to use for the underlying Timer |
OUTPUT | the board::PWMPin connected to the buzzer; this must be the pin OCnA, where n is the AVR Timer number |
TONEPLAY | the type used to store melody data, QTonePlay by default |
Definition at line 712 of file tone_player.h.
using devices::audio::TonePlayer< NTIMER, OUTPUT, TONEPLAY >::GENERATOR = typename BASE::GENERATOR |
The type of ToneGenerator
to use as constructor's argument.
Definition at line 718 of file tone_player.h.
using devices::audio::TonePlayer< NTIMER, OUTPUT, TONEPLAY >::TONE_PLAY = typename BASE::TONE_PLAY |
The type that holds unit of information of a melody.
Definition at line 720 of file tone_player.h.
|
inlineexplicit |
Create a new synchronous tone player, based on an existing ToneGenerator
.
tone_generator | the ToneGenerator used to actually produce tones. |
Definition at line 727 of file tone_player.h.
|
inline |
Play a melody, defined by a sequence of TONE_PLAY
s, stored in SRAM.
This method is blocking: it will return only when the melody is finished playing.
melody | a pointer, in SRAM, to the sequence of TONE_PLAY to be played; the sequence MUST finish with a SpecialTone::END . |
beat | the tempo (beats per minute) at which the melody shall be played; one beat is the duration of a quarter note. |
Definition at line 741 of file tone_player.h.
|
inline |
Play a melody, defined by a sequence of TONE_PLAY
s, stored in EEPROM.
This method is blocking: it will return only when the melody is finished playing.
melody | a pointer, in EEPROM, to the sequence of TONE_PLAY to be played; the sequence MUST finish with a SpecialTone::END . |
beat | the tempo (beats per minute) at which the melody shall be played; one beat is the duration of a quarter note. |
Definition at line 760 of file tone_player.h.
|
inline |
Play a melody, defined by a sequence of TONE_PLAY
s, stored in Flash.
This method is blocking: it will return only when the melody is finished playing.
melody | a pointer, in Flash, to the sequence of TONE_PLAY to be played; the sequence MUST finish with a SpecialTone::END . |
beat | the tempo (beats per minute) at which the melody shall be played; one beat is the duration of a quarter note. |
Definition at line 779 of file tone_player.h.
|
inline |
Stop playing current melody (if any).
Effect is not immediate but will stop at the end of the current tone.
Definition at line 790 of file tone_player.h.
|
inline |
Tell if a melody is currently playing.
Definition at line 798 of file tone_player.h.