project-kyoku/include/tools/bpmcalculator.h

39 lines
843 B
C++

#pragma once
#include "tools/music.h"
#include "tools/beatutils.h"
#include <memory>
class BPMCalculator
{
public:
explicit BPMCalculator(const std::shared_ptr<Music>& music);
void setMusic(const std::shared_ptr<Music>& music);
std::shared_ptr<Music> music() const;
void start();
void stop();
void click();
const beat_utils::BeatInfo& fetchApproximatedInfo();
microsec fetchTimeUntilNextBeat();
microsec getStartingOffset() const;
void setStartingOffset(microsec offset);
void moveStartingOffsetBy(microsec shift);
private:
bool _need_recalculate;
bool _calculating;
std::shared_ptr<Music> _music;
std::vector<microsec> _deltas;
microsec _previous_click_offset;
microsec _first_click_offset;
beat_utils::BeatInfo _approximated_info;
inline void reset();
};