From: Colin Fletcher Date: Wed, 12 Feb 2014 21:49:00 +0000 (+0000) Subject: Make 'Tap tempo' set the bpm to a running average X-Git-Tag: 4.0-rc1~1601^2~631 X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=61d413ada423f456ad7687b2ae2d39047c7f53a6;p=ardour.git Make 'Tap tempo' set the bpm to a running average Keep a running average of the interval between clicks on the 'Tap tempo' button, and use that average to set the bpm value. --- diff --git a/gtk2_ardour/tempo_dialog.cc b/gtk2_ardour/tempo_dialog.cc index 9173393ff5..56e375dc91 100644 --- a/gtk2_ardour/tempo_dialog.cc +++ b/gtk2_ardour/tempo_dialog.cc @@ -263,17 +263,28 @@ TempoDialog::tap_tempo () if (last_tap.tv_sec >= 0 || last_tap.tv_usec > 0) { struct timeval diff; double interval, bpm; + static const double decay = 0.5; + timersub (&now, &last_tap, &diff); interval = diff.tv_sec + diff.tv_usec * 1.0e-6; - - bpm = 60.0 / interval; - if (bpm >= 20) { + if (interval <= 0.25) { + // >= 15 bpm, say + if (average_interval > 0) { + average_interval = interval * decay + + average_interval * (1.0-decay); + } else { + average_interval = interval; + } + + bpm = 60.0 / average_interval; bpm_spinner.set_value (bpm); + } else { + average_interval = 0; } + } else { + average_interval = 0; } last_tap = now; - - } MeterDialog::MeterDialog (TempoMap& map, framepos_t frame, const string&) diff --git a/gtk2_ardour/tempo_dialog.h b/gtk2_ardour/tempo_dialog.h index 848b55cb59..9e97afa98d 100644 --- a/gtk2_ardour/tempo_dialog.h +++ b/gtk2_ardour/tempo_dialog.h @@ -58,6 +58,7 @@ private: NoteTypes note_types; struct timeval last_tap; + double average_interval; Gtk::ComboBoxText pulse_selector; Gtk::Adjustment bpm_adjustment;