Make tap tempo use g_get_monotonic_time(), and fix minimum BPM
gettimeofday() is not guaranteed to be monotonic: use g_get_monotonic_time() instead. Also, fix calculation of slowest tap tempo BPM so that the slowest tempo which can be set by tapping is 10 BPM rather than 240.
This commit is contained in:
parent
61d413ada4
commit
7815aa1e89
@ -257,18 +257,16 @@ TempoDialog::pulse_change ()
|
|||||||
void
|
void
|
||||||
TempoDialog::tap_tempo ()
|
TempoDialog::tap_tempo ()
|
||||||
{
|
{
|
||||||
struct timeval now;
|
gint64 now;
|
||||||
gettimeofday (&now, NULL);
|
now = g_get_monotonic_time (); // microseconds
|
||||||
|
|
||||||
if (last_tap.tv_sec >= 0 || last_tap.tv_usec > 0) {
|
if (last_tap > 0) {
|
||||||
struct timeval diff;
|
|
||||||
double interval, bpm;
|
double interval, bpm;
|
||||||
static const double decay = 0.5;
|
static const double decay = 0.5;
|
||||||
|
|
||||||
timersub (&now, &last_tap, &diff);
|
interval = (now - last_tap) * 1.0e-6;
|
||||||
interval = diff.tv_sec + diff.tv_usec * 1.0e-6;
|
if (interval <= 6.0) {
|
||||||
if (interval <= 0.25) {
|
// >= 10 bpm, say
|
||||||
// >= 15 bpm, say
|
|
||||||
if (average_interval > 0) {
|
if (average_interval > 0) {
|
||||||
average_interval = interval * decay
|
average_interval = interval * decay
|
||||||
+ average_interval * (1.0-decay);
|
+ average_interval * (1.0-decay);
|
||||||
|
@ -57,7 +57,7 @@ private:
|
|||||||
typedef std::map<std::string,float> NoteTypes;
|
typedef std::map<std::string,float> NoteTypes;
|
||||||
NoteTypes note_types;
|
NoteTypes note_types;
|
||||||
|
|
||||||
struct timeval last_tap;
|
gint64 last_tap;
|
||||||
double average_interval;
|
double average_interval;
|
||||||
|
|
||||||
Gtk::ComboBoxText pulse_selector;
|
Gtk::ComboBoxText pulse_selector;
|
||||||
|
Loading…
Reference in New Issue
Block a user