This is a Swift class that provides the ability to average a series of button taps and return a tempo in beats per minute.
To instantiate, provide a value for
timeOutInterval (the amount of idle time between taps that will reset analysis) and a value for
minimumTaps (the number of taps required to start analysis). Then, repeatedly call the
addTap() function (typically in an @IBAction handler), which will return the tempo, or nil if the minimum number of taps has not been reached.
- Currently, this class averages all taps between time out resets. Line 24 could easily be rewritten to provide an average of only the last x taps, a weighted average, or some other type of analysis.
- A value of 1.0 for
timeOutIntervalwill effectively limit the slowest tempo detected to 60 bpm. A more reasonable value would be between 2.0 (30 bpm) and 3.0 (20 bpm).