mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
tunes lib: Minor changes
This commit is contained in:
committed by
Daniel Agar
parent
546a92af1e
commit
5214642bc3
@@ -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':
|
||||
|
||||
@@ -42,16 +42,25 @@
|
||||
// TODO: find better way to include the number of tunes, maybe include them in the lib directly?
|
||||
#include <drivers/drv_tone_alarm.h>
|
||||
|
||||
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 */
|
||||
|
||||
@@ -68,7 +68,7 @@ usage()
|
||||
"\t-t <defualt tunes>\tPlay the default (1...15) (default=1)\n"
|
||||
"\t-f <frequency>\t\tFrequency from 0-20kHz\n"
|
||||
"\t-d <duration>\t\tDuration of the tone in us\n"
|
||||
"\t-s <strength>\t\tStrenght of the tone between 0-100\n"
|
||||
"\t-s <strength>\t\tStrength of the tone between 0-100\n"
|
||||
"\t-m <melody>\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;
|
||||
|
||||
Reference in New Issue
Block a user