summaryrefslogtreecommitdiff
path: root/gtk2_ardour/tempo_dialog.cc
diff options
context:
space:
mode:
authorColin Fletcher <colin.m.fletcher@googlemail.com>2014-02-12 21:49:00 +0000
committerColin Fletcher <colin.m.fletcher@googlemail.com>2014-07-05 21:47:49 +0100
commit61d413ada423f456ad7687b2ae2d39047c7f53a6 (patch)
treedc1f5f34779ee958e7113e6da40171064af05084 /gtk2_ardour/tempo_dialog.cc
parente0eaea6471e25f4c3797450a96f35fcdbb1c6992 (diff)
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.
Diffstat (limited to 'gtk2_ardour/tempo_dialog.cc')
-rw-r--r--gtk2_ardour/tempo_dialog.cc21
1 files changed, 16 insertions, 5 deletions
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&)