Make tap tempo use g_get_monotonic_time(), and fix minimum BPM
authorColin Fletcher <colin.m.fletcher@googlemail.com>
Fri, 16 May 2014 17:50:30 +0000 (18:50 +0100)
committerColin Fletcher <colin.m.fletcher@googlemail.com>
Sat, 5 Jul 2014 20:47:49 +0000 (21:47 +0100)
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.

gtk2_ardour/tempo_dialog.cc
gtk2_ardour/tempo_dialog.h

index 56e375dc9121890cb058d2c6f4c78d3ba8ed4a5b..a96958136910827123c3630fa8240e5db65627df 100644 (file)
@@ -257,18 +257,16 @@ TempoDialog::pulse_change ()
 void
 TempoDialog::tap_tempo ()
 {
-       struct timeval now;
-       gettimeofday (&now, NULL);
+       gint64 now;
+       now = g_get_monotonic_time (); // microseconds
 
-       if (last_tap.tv_sec >= 0 || last_tap.tv_usec > 0) {
-               struct timeval diff;
+       if (last_tap > 0) {
                double interval, bpm;
                static const double decay = 0.5;
 
-               timersub (&now, &last_tap, &diff);
-               interval = diff.tv_sec + diff.tv_usec * 1.0e-6;
-               if (interval <= 0.25) {
-                       // >= 15 bpm, say
+               interval = (now - last_tap) * 1.0e-6;
+               if (interval <= 6.0) {
+                       // >= 10 bpm, say
                        if (average_interval > 0) {
                                average_interval = interval * decay
                                        + average_interval * (1.0-decay);
index 9e97afa98db767454850c8fb5a3ac3b37472a21f..616be2433e3cf4c0d4cf49dc6ae19c02d6bf0c69 100644 (file)
@@ -57,7 +57,7 @@ private:
        typedef std::map<std::string,float> NoteTypes;
        NoteTypes note_types;
 
-       struct timeval last_tap;
+       gint64 last_tap;
        double average_interval;
 
        Gtk::ComboBoxText pulse_selector;