#pragma once #include "tools/music.h" #include "tools/beatutils.h" #include class BPMCalculator { public: explicit BPMCalculator(const std::shared_ptr& music); void setMusic(const std::shared_ptr& music); std::shared_ptr 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; std::vector _deltas; microsec _previous_click_offset; microsec _first_click_offset; beat_utils::BeatInfo _approximated_info; inline void reset(); };