2021-08-11 21:00:28 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "tools/music.h"
|
2021-09-10 20:35:48 +02:00
|
|
|
#include "tools/beatutils.h"
|
2021-08-11 21:00:28 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
class BPMCalculator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit BPMCalculator(const std::shared_ptr<Music>& music);
|
2021-09-08 21:05:56 +02:00
|
|
|
|
2021-08-11 21:00:28 +02:00
|
|
|
void setMusic(const std::shared_ptr<Music>& music);
|
2021-09-01 21:04:18 +02:00
|
|
|
std::shared_ptr<Music> music() const;
|
2021-08-11 21:00:28 +02:00
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
void start();
|
2021-09-08 21:05:56 +02:00
|
|
|
void stop();
|
2021-08-11 21:00:28 +02:00
|
|
|
void click();
|
2021-09-10 20:35:48 +02:00
|
|
|
|
2021-09-13 20:50:39 +02:00
|
|
|
bool calculating() const;
|
|
|
|
|
2021-09-10 20:35:48 +02:00
|
|
|
const beat_utils::BeatInfo& fetchApproximatedInfo();
|
|
|
|
microsec fetchTimeUntilNextBeat();
|
2021-09-08 21:05:56 +02:00
|
|
|
|
|
|
|
microsec getStartingOffset() const;
|
|
|
|
void setStartingOffset(microsec offset);
|
|
|
|
void moveStartingOffsetBy(microsec shift);
|
|
|
|
|
2021-08-11 21:00:28 +02:00
|
|
|
private:
|
2021-09-08 21:05:56 +02:00
|
|
|
bool _need_recalculate;
|
|
|
|
bool _calculating;
|
|
|
|
|
2021-08-11 21:00:28 +02:00
|
|
|
std::shared_ptr<Music> _music;
|
|
|
|
std::vector<microsec> _deltas;
|
|
|
|
microsec _previous_click_offset;
|
2021-09-08 21:05:56 +02:00
|
|
|
microsec _first_click_offset;
|
|
|
|
|
2021-09-10 20:35:48 +02:00
|
|
|
beat_utils::BeatInfo _approximated_info;
|
2021-09-08 21:05:56 +02:00
|
|
|
|
|
|
|
inline void reset();
|
2021-08-11 21:00:28 +02:00
|
|
|
};
|