feat: TempoController: minimal demo

This commit is contained in:
2026-06-14 17:46:32 +02:00
parent 968afb6920
commit 81e8d2727b
2 changed files with 17 additions and 0 deletions

View File

@@ -37,7 +37,9 @@ void TempoController::seekTo(double oldMarkerPosSec, double newMarkerPosSec) {
*/
void TempoController::onBeat(double t) {
std::lock_guard<std::mutex> lock(mMutex);
if(lastBeatT != 0.0) dtBeat = t - lastBeatT;
lastBeatT = t;
setStretchFactor();
}
/**
@@ -46,5 +48,16 @@ void TempoController::onBeat(double t) {
*/
void TempoController::onStep(double t) {
std::lock_guard<std::mutex> lock(mMutex);
if(lastStepT != 0.0) dtStep = t - lastStepT;
lastStepT = t;
setStretchFactor();
}
void TempoController::setStretchFactor() {
if(dtBeat == 0.0 || dtStep == 0.0) return;
double ratio = dtStep / dtBeat;
ratio = std::min(3.3, ratio);
ratio = std::max(0.3, ratio);
this->have_stretch_factor->store(true);
this->stretch_factor->store(ratio);
}

View File

@@ -17,6 +17,8 @@ private:
std::atomic<double> *stretch_factor;
double lastBeatT;
double lastStepT;
double dtBeat;
double dtStep;
public:
TempoController(std::atomic<bool> *have_stretch_factor, std::atomic<double> *stretch_factor);
void reset(std::vector<double> beatTimesSec);
@@ -33,6 +35,8 @@ public:
* @param t marker position in sec of original music time
*/
void onStep(double t);
private:
void setStretchFactor();
};
#endif //LOCKSTEP_TEMPOCONTROLLER_H