From 5214642bc35b850a8504dda13333b9664aace940 Mon Sep 17 00:00:00 2001 From: Simone Guscetti Date: Fri, 24 Feb 2017 12:13:47 +0100 Subject: [PATCH] tunes lib: Minor changes --- src/lib/tunes/tunes.cpp | 18 ++++---- src/lib/tunes/tunes.h | 43 +++++++++++++------- src/systemcmds/tune_control/tune_control.cpp | 4 +- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/lib/tunes/tunes.cpp b/src/lib/tunes/tunes.cpp index fd69a13c03..e9451125fd 100644 --- a/src/lib/tunes/tunes.cpp +++ b/src/lib/tunes/tunes.cpp @@ -49,8 +49,6 @@ #define BEAT_TIME_CONVERSION_US BEAT_TIME_CONVERSION_MS * 1000 #define BEAT_TIME_CONVERSION BEAT_TIME_CONVERSION_US -using namespace output; - // initialise default tunes const char *Tunes::_default_tunes[] = { "", // empty to align with the index @@ -84,7 +82,7 @@ Tunes::Tunes(unsigned default_tempo, unsigned default_octave, unsigned default_n config_tone(); } -Tunes::Tunes(): Tunes(120, 4, 4, NoteMode::MODE_NORMAL) +Tunes::Tunes(): Tunes(120, 4, 4, NoteMode::NORMAL) { } @@ -100,7 +98,7 @@ void Tunes::config_tone() _octave = _default_octave; } -int Tunes::parse_cmd(struct tune_control_s &tune_control, unsigned &frequency, unsigned &duration, unsigned &silence) +int Tunes::parse_cmd(const tune_control_s &tune_control, unsigned &frequency, unsigned &duration, unsigned &silence) { int continue_sequnece = 0; @@ -168,16 +166,16 @@ unsigned Tunes::note_duration(unsigned &silence, unsigned note_length, unsigned unsigned note_period = whole_note_period / note_length; switch (_note_mode) { - case MODE_NORMAL: + case NoteMode::NORMAL: silence = note_period / 8; break; - case MODE_STACCATO: + case NoteMode::STACCATO: silence = note_period / 4; break; + case NoteMode::LEGATO: default: - case MODE_LEGATO: silence = 0; break; } @@ -317,15 +315,15 @@ int Tunes::next_note(unsigned &frequency, unsigned &duration, unsigned &silence) switch (c) { case 'N': - _note_mode = MODE_NORMAL; + _note_mode = NoteMode::NORMAL; break; case 'L': - _note_mode = MODE_LEGATO; + _note_mode = NoteMode::LEGATO; break; case 'S': - _note_mode = MODE_STACCATO; + _note_mode = NoteMode::STACCATO; break; case 'F': diff --git a/src/lib/tunes/tunes.h b/src/lib/tunes/tunes.h index cfe8c28094..a15939624b 100644 --- a/src/lib/tunes/tunes.h +++ b/src/lib/tunes/tunes.h @@ -42,16 +42,25 @@ // TODO: find better way to include the number of tunes, maybe include them in the lib directly? #include -namespace output -{ - -enum NoteMode { MODE_NORMAL, MODE_LEGATO, MODE_STACCATO}; - class Tunes { public: + enum class NoteMode {NORMAL, LEGATO, STACCATO}; + + /** + * Constructor with the default parameter set to: + * default_tempo: 120 + * default_octave: 4 + * default_note_length: 4 + * default_mode: NORMAL + */ Tunes(); - Tunes(unsigned tempo, unsigned octave, unsigned note_length, NoteMode mode); + + /** + * Constructor that can set the default parameters + */ + Tunes(unsigned default_tempo, unsigned default_octave, unsigned default_note_length, NoteMode default_mode); + ~Tunes() = default; /** @@ -63,7 +72,7 @@ public: * @param silence return silance duration (us) * @return -1 for error, 0 for play one tone and 1 for continue a sequence */ - int parse_cmd(tune_control_s &tune_control, unsigned &frequency, unsigned &duration, unsigned &silence); + int parse_cmd(const tune_control_s &tune_control, unsigned &frequency, unsigned &duration, unsigned &silence); /** * parse a tune string, formatted with the syntax of the Microsoft GWBasic/QBasic, in frequency(Hz), @@ -80,10 +89,10 @@ public: private: static const char *_default_tunes[TONE_NUMBER_OF_TUNES]; static const uint8_t _note_tab[]; - bool _repeat; // if true, tune restarts at end + bool _repeat; ///< if true, tune restarts at end - const char *_tune = nullptr; // current tune string - const char *_next = nullptr; // next note in the string + const char *_tune = nullptr; ///< current tune string + const char *_next = nullptr; ///< next note in the string unsigned _tempo; unsigned _note_length; @@ -92,7 +101,7 @@ private: unsigned _default_tempo = 120; unsigned _default_note_length = 4; - NoteMode _default_mode = NoteMode::MODE_NORMAL; + NoteMode _default_mode = NoteMode::NORMAL; unsigned _default_octave = 4; /** @@ -133,12 +142,16 @@ private: // unsigned next_number(); - // Consume dot characters from the string, returning the number consumed. - // + /** + * Consume dot characters from the string + * + * @return number of consumed dots + */ unsigned next_dots(); + /** + * set the tune parameters to default + */ void config_tone(); }; - -} /* output */ diff --git a/src/systemcmds/tune_control/tune_control.cpp b/src/systemcmds/tune_control/tune_control.cpp index bdbe84ad2c..d6d6edaede 100644 --- a/src/systemcmds/tune_control/tune_control.cpp +++ b/src/systemcmds/tune_control/tune_control.cpp @@ -68,7 +68,7 @@ usage() "\t-t \tPlay the default (1...15) (default=1)\n" "\t-f \t\tFrequency from 0-20kHz\n" "\t-d \t\tDuration of the tone in us\n" - "\t-s \t\tStrenght of the tone between 0-100\n" + "\t-s \t\tStrength of the tone between 0-100\n" "\t-m \t\tMelody in a string form ex: \"MFT200e8a8a\"\n" ); } @@ -88,7 +88,7 @@ static void publish_tune_control(tune_control_s &tune_control) int tune_control_main(int argc, char *argv[]) { - output::Tunes tunes; + Tunes tunes; bool string_input = false; const char *tune_string = NULL; int myoptind = 1;