Tempo Tapper
1.0.0
A simple library to implement a tempo tapper
|
Provides all necessary structs and functions to implement a tempo tapper. More...
#include <stdint.h>
Go to the source code of this file.
Classes | |
struct | tempo_tapper |
Tempo tapper struct. More... | |
Macros | |
#define | S_TO_US 1000000 |
Typedefs | |
typedef float | BPM_t |
typedef struct tempo_tapper | tempo_tapper |
Tempo tapper struct. More... | |
Functions | |
void | current_time (tt_time_t *time) |
Receives the current clock time. More... | |
void | add_time (tt_time_t *a, tt_time_t *b, tt_time_t *res) |
Adds two time values. More... | |
void | sub_time (tt_time_t *a, tt_time_t *b, tt_time_t *res) |
Subtracts two time values. More... | |
void | reset_time (tt_time_t *time) |
Resets a time var to 0. More... | |
unsigned long | time_to_us (tt_time_t *time) |
Returns a time value in microseconds. More... | |
tempo_tapper * | tt_new () |
Creates a new tempo tapper instance. More... | |
unsigned long | tt_period_us (tempo_tapper *tapper) |
Returns the period of a tempo in microseconds. More... | |
void | tt_tap (tempo_tapper *tapper) |
"Taps" the tempo tapper More... | |
void | tt_reset (tempo_tapper *tapper) |
Resets the tempo tapper. More... | |
BPM_t | tt_bpm (tempo_tapper *tapper) |
Returns the tempo in BPM. More... | |
Provides all necessary structs and functions to implement a tempo tapper.
The following file Provides all necessary strucs and functions to implement a tempo tapper, i.e. the tempo tapper struct and prototypes for all functions that interact with a tempo tapper struct instance.
The tempo tapper libraries is supported by multiple target platforms. Define one of the following preprocessors to select your target platform:
Definition in file tempo_tapper.h.
typedef struct tempo_tapper tempo_tapper |
Tempo tapper struct.
The following struct represents a virtual tempo tapper, and stores the necessary information to set, alter and receive a tempo value.
To create and interface with a tempo tapper struct, use the following functions:
To store time values, the platform varying tt_time_t typedef is used, as each platform offers its own preferred data type or struct to store time values (Ex. timeval on posix). This means that time arithmetic is implemented differently on every platform (see current_time(), add_time(), sub_time(), time_to_us(), reset_time()). For the library user, this is irrelevant as platform specific code is handled by the library internally. The only noticable external difference may be a variation in speed and precision.
void add_time | ( | tt_time_t * | a, |
tt_time_t * | b, | ||
tt_time_t * | res | ||
) |
Adds two time values.
The following function adds two time values, a, and b and stores the result in res.
Referenced by tt_tap().
void current_time | ( | tt_time_t * | time | ) |
Receives the current clock time.
The following function sets the parsed time var to the current clock time. The clock time may be the time that has passed since the start of the program, (ex. micros() on arduino platforms), but may also be the current time of the day (ex. gettimeofday() on posix).
Referenced by tt_tap().
void reset_time | ( | tt_time_t * | time | ) |
Resets a time var to 0.
The following function resets a time var to 0
Referenced by tt_reset().
void sub_time | ( | tt_time_t * | a, |
tt_time_t * | b, | ||
tt_time_t * | res | ||
) |
Subtracts two time values.
The following function subtracts the time value of b from a and stores the result in res.
Referenced by tt_tap().
unsigned long time_to_us | ( | tt_time_t * | time | ) |
Returns a time value in microseconds.
The following function converts and returns a time value in microseconds.
Referenced by tt_period_us().
BPM_t tt_bpm | ( | tempo_tapper * | tapper | ) |
Returns the tempo in BPM.
The following function returns the tempo of the tempo tapper in BPM. The decimal precision is platform dependant.
Definition at line 72 of file tempo_tapper_common.cxx.
References tt_period_us().
Referenced by tempo_tapper_cpp::bpm().
tempo_tapper* tt_new | ( | ) |
Creates a new tempo tapper instance.
The following function creates and initializes a tempo tapper struct instance.
Definition at line 61 of file tempo_tapper_common.cxx.
References tt_reset().
Referenced by tempo_tapper_cpp::tempo_tapper_cpp().
unsigned long tt_period_us | ( | tempo_tapper * | tapper | ) |
Returns the period of a tempo in microseconds.
The following function returns the time in microseconds for a period of the current tempo set by the tempo tapper struct.
Definition at line 37 of file tempo_tapper_common.cxx.
References tempo_tapper::prd_sum, tempo_tapper::taps, and time_to_us().
Referenced by tempo_tapper_cpp::period_us(), and tt_bpm().
void tt_reset | ( | tempo_tapper * | tapper | ) |
Resets the tempo tapper.
The following function resets the tempo tapper to its iniital values.
Definition at line 83 of file tempo_tapper_common.cxx.
References tempo_tapper::prd_sum, reset_time(), and tempo_tapper::taps.
Referenced by tempo_tapper_cpp::reset(), and tt_new().
void tt_tap | ( | tempo_tapper * | tapper | ) |
"Taps" the tempo tapper
The following function is used to "tap" a tempo tapper struct instance. Calling this function on a tempo tapper struct will increase the value of taps, add the time that has passed since the last tap to prd_sum and update lst_t to the current clock time.
Definition at line 46 of file tempo_tapper_common.cxx.
References add_time(), current_time(), tempo_tapper::lst_t, tempo_tapper::prd_sum, sub_time(), and tempo_tapper::taps.
Referenced by tempo_tapper_cpp::tap().