2021-08-11 15:00:28 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "tools/music.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class BPMCalculator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit BPMCalculator(const std::shared_ptr<Music>& music);
|
2021-09-08 15:05:56 -04:00
|
|
|
|
2021-08-11 15:00:28 -04:00
|
|
|
void setMusic(const std::shared_ptr<Music>& music);
|
2021-09-01 15:04:18 -04:00
|
|
|
std::shared_ptr<Music> music() const;
|
2021-08-11 15:00:28 -04:00
|
|
|
|
2021-08-27 13:40:48 -04:00
|
|
|
void start();
|
2021-09-08 15:05:56 -04:00
|
|
|
void stop();
|
2021-08-11 15:00:28 -04:00
|
|
|
void click();
|
2021-09-08 15:05:56 -04:00
|
|
|
float fetchCurrentBPMApproximation();
|
|
|
|
|
|
|
|
microsec getStartingOffset() const;
|
|
|
|
void setStartingOffset(microsec offset);
|
|
|
|
void moveStartingOffsetBy(microsec shift);
|
|
|
|
|
|
|
|
microsec fetchTimeUntilNextBeat();
|
|
|
|
microsec fetchBeatInterval();
|
2021-08-11 15:00:28 -04:00
|
|
|
|
|
|
|
private:
|
2021-09-08 15:05:56 -04:00
|
|
|
bool _need_recalculate;
|
|
|
|
bool _calculating;
|
|
|
|
|
2021-08-11 15:00:28 -04:00
|
|
|
std::shared_ptr<Music> _music;
|
|
|
|
std::vector<microsec> _deltas;
|
|
|
|
microsec _previous_click_offset;
|
2021-09-08 15:05:56 -04:00
|
|
|
microsec _first_click_offset;
|
|
|
|
|
|
|
|
int _approximated_bpm;
|
|
|
|
|
|
|
|
inline float calculateBPM(microsec all_microseconds, std::size_t beats_amount) const;
|
|
|
|
inline void reset();
|
2021-08-11 15:00:28 -04:00
|
|
|
};
|