GMTapTempo is an easy to use customisable button that allows to specify a tempo by clicking it regularly. In addition, it displays its BPM and can display a visual feedback when a new beat is triggered.
When clicking it regularly, GMTapTempo will output a Number value expressed in beats per minute. This value is calculated averaging the elapsed time between clicks.
First, this means that when clicking for the first time (or when resetted), it will output nil
instead, because it needs at least two clicks to express a time value.
Second, it needs to be able to discriminate between a click that is part from the current tempo specification, or a click that initiate a new tempo specification. To do so, it will check how much time has passed since the last click. If this time is more than twice the current BPM, it will assume a new tempo specification is starting, thus resetting.
Depending on your needs, a tap tempo button might initiate different actions. For example, one might simply want to adjust a TempoClock tempo. Or one might want to pause a routine, yield its next events on subsequent clicks, and resume the routine at the new tempo when clicks have stopped.
To provide as much polyvalence as possible, GMTapTempo associated action
is a Function which takes two arguments: the current BPM, and a 'time list'.
On the first click (or when resetting), the function will be called passing nil
as BPM argument. On subsequent clicks, the function will be called will be called passing an average of the time between each clicks as BPM argument.
Every time the button is clicked, the event time will be registered in two formats:
Date format: Date().hourStamp
Time since SC started: SystemClock.seconds
Those two timestamps are concatenated inside an array, and stored within a 'time list', which is passed to the action
function every time it is called, allowing to trace each clicks position in time.
Creates a new instance of GMTapTempo.
Sets or gets the Function to be triggered when the button is pressed down. This Function takes two arguments: the current BPM, and a list of events timestamps.
Sets or gets the current bpm.
Triggers a visual feedback used to a indicate a new beat. View's refresh is internally deferred so this method can be called within a Routine context.
Sets or gets the button color when it blinks.
Sets or gets the string color when it blinks.
Sets or gets the string ratio relative to the widget's height.