Tempo Tapper  1.0.0
A simple library to implement a tempo tapper
tempo_tapper_posix.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Patrick Pedersen
3 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13 
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  *
17  */
18 
32 #ifdef TT_TARGET_PLATFORM_POSIX
33 
34 #include <stdlib.h>
35 #include <stddef.h>
36 #include <sys/time.h>
37 
38 #include <tempo_tapper.h>
39 
40 void current_time(tt_time_t *time)
41 {
42  gettimeofday(time, NULL);
43 }
44 
45 void add_time(tt_time_t *a, tt_time_t *b, tt_time_t *res)
46 {
47  timeradd(a, b, res);
48 }
49 
50 void sub_time(tt_time_t *a, tt_time_t *b, tt_time_t *res)
51 {
52  timersub(a, b, res);
53 }
54 
55 unsigned long time_to_us(tt_time_t *time)
56 {
57  return (time->tv_sec * S_TO_US + time->tv_usec);
58 }
59 
60 void reset_time(tt_time_t *time)
61 {
62  time->tv_sec = 0;
63  time->tv_usec = 0;
64 }
65 
66 #endif
reset_time
void reset_time(tt_time_t *time)
Resets a time var to 0.
add_time
void add_time(tt_time_t *a, tt_time_t *b, tt_time_t *res)
Adds two time values.
sub_time
void sub_time(tt_time_t *a, tt_time_t *b, tt_time_t *res)
Subtracts two time values.
time_to_us
unsigned long time_to_us(tt_time_t *time)
Returns a time value in microseconds.
current_time
void current_time(tt_time_t *time)
Receives the current clock time.
tempo_tapper.h
Provides all necessary structs and functions to implement a tempo tapper.