Files
lockstep/app/src/main/cpp/TempoController.cpp

51 lines
1.3 KiB
C++
Raw Normal View History

2026-06-14 16:26:27 +02:00
//
// Created by david on 14.06.2026.
//
#include "TempoController.h"
TempoController::TempoController(std::atomic<bool> *have_stretch_factor, std::atomic<double> *stretch_factor) :
have_stretch_factor(have_stretch_factor),
stretch_factor(stretch_factor),
lastBeatT(0.0),
lastStepT(0.0)
{
this->have_stretch_factor->store(false);
this->stretch_factor->store(1.0);
}
void TempoController::reset(std::vector<double> beatTimes) {
std::lock_guard<std::mutex> lock(mMutex);
beatTimesSec.assign(beatTimes.begin(), beatTimes.end());
lastBeatT = (0.0);
lastStepT = (0.0);
}
void TempoController::resume() {}
void TempoController::pause() {}
void TempoController::seekTo(double oldMarkerPosSec, double newMarkerPosSec) {
std::lock_guard<std::mutex> lock(mMutex);
double dt = newMarkerPosSec - oldMarkerPosSec;
lastBeatT += dt;
lastStepT += dt;
}
/**
* must be thread-safe since these are called from different threads
* @param t marker position in sec of original music time
*/
void TempoController::onBeat(double t) {
std::lock_guard<std::mutex> lock(mMutex);
lastBeatT = t;
}
/**
* must be thread-safe since these are called from different threads
* @param t time in sec of accelerometer timebase
*/
void TempoController::onStep(double t) {
std::lock_guard<std::mutex> lock(mMutex);
lastStepT = t;
}