GMTapTempo:
Filter:
GraphicalModule/Classes (extension) | GUI > Graphical Module

GMTapTempo
ExtensionExtension

A simple tap tempo button for creating graphical interfaces

Description

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.

First click & reset

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.

Action

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.

Class Methods

.new

Creates a new instance of GMTapTempo.

Instance Methods

Interaction

.action

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.

.bpm

Sets or gets the current bpm.

Graphics

.blink

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.

.blinkColor

Sets or gets the button color when it blinks.

.blinkFontColor

Sets or gets the string color when it blinks.

.stringRatio

Sets or gets the string ratio relative to the widget's height.

Internal Methods

.draw

Examples