feat: TempoController: minimal demo
This commit is contained in:
@@ -37,7 +37,9 @@ void TempoController::seekTo(double oldMarkerPosSec, double newMarkerPosSec) {
|
|||||||
*/
|
*/
|
||||||
void TempoController::onBeat(double t) {
|
void TempoController::onBeat(double t) {
|
||||||
std::lock_guard<std::mutex> lock(mMutex);
|
std::lock_guard<std::mutex> lock(mMutex);
|
||||||
|
if(lastBeatT != 0.0) dtBeat = t - lastBeatT;
|
||||||
lastBeatT = t;
|
lastBeatT = t;
|
||||||
|
setStretchFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,5 +48,16 @@ void TempoController::onBeat(double t) {
|
|||||||
*/
|
*/
|
||||||
void TempoController::onStep(double t) {
|
void TempoController::onStep(double t) {
|
||||||
std::lock_guard<std::mutex> lock(mMutex);
|
std::lock_guard<std::mutex> lock(mMutex);
|
||||||
|
if(lastStepT != 0.0) dtStep = t - lastStepT;
|
||||||
lastStepT = t;
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ private:
|
|||||||
std::atomic<double> *stretch_factor;
|
std::atomic<double> *stretch_factor;
|
||||||
double lastBeatT;
|
double lastBeatT;
|
||||||
double lastStepT;
|
double lastStepT;
|
||||||
|
double dtBeat;
|
||||||
|
double dtStep;
|
||||||
public:
|
public:
|
||||||
TempoController(std::atomic<bool> *have_stretch_factor, std::atomic<double> *stretch_factor);
|
TempoController(std::atomic<bool> *have_stretch_factor, std::atomic<double> *stretch_factor);
|
||||||
void reset(std::vector<double> beatTimesSec);
|
void reset(std::vector<double> beatTimesSec);
|
||||||
@@ -33,6 +35,8 @@ public:
|
|||||||
* @param t marker position in sec of original music time
|
* @param t marker position in sec of original music time
|
||||||
*/
|
*/
|
||||||
void onStep(double t);
|
void onStep(double t);
|
||||||
|
private:
|
||||||
|
void setStretchFactor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //LOCKSTEP_TEMPOCONTROLLER_H
|
#endif //LOCKSTEP_TEMPOCONTROLLER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user