fix: use clock instead of timeofday

This commit is contained in:
2026-05-16 17:56:51 +02:00
parent 988cf799b4
commit 3b6d4d642d
4 changed files with 12 additions and 21 deletions
+6 -12
View File
@@ -1,19 +1,13 @@
#include <math.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "types.h"
#include "config.h"
#include "tempo.h"
static long now() {
struct timeval now;
gettimeofday(&now, NULL);
return now.tv_sec * 1000 + now.tv_usec / 1000;
}
static long now_ms() { return 1000 * clock() / CLOCKS_PER_SEC; }
static void reset_tap_chain(Tempo *tempo, long t) {
tempo->last_reset = t;
@@ -93,7 +87,7 @@ static void add_tap_to_chain(Tempo *tempo, long t) {
void tempo_init(Tempo *tempo, float value) {
long t;
t = now();
t = now_ms();
reset_tap_chain(tempo, t);
@@ -105,7 +99,7 @@ void tempo_set(Tempo *tempo, float value) {
long t;
long progress;
t = now();
t = now_ms();
progress = (t - tempo->last_reset) % tempo->beat_length;
@@ -118,7 +112,7 @@ void tempo_set(Tempo *tempo, float value) {
void tempo_tap(Tempo *tempo) {
long t;
t = now();
t = now_ms();
if (!is_chain_active(*tempo, t)) {
reset_tap_chain(tempo, t);
@@ -130,7 +124,7 @@ void tempo_tap(Tempo *tempo) {
double tempo_total(const Tempo *tempo) {
long t;
t = now();
t = now_ms();
return (double)(t - tempo->last_reset) / (double)tempo->beat_length;
}