feat: add skeleton TempoController
This commit is contained in:
50
app/src/main/cpp/TempoController.cpp
Normal file
50
app/src/main/cpp/TempoController.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user