You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project-kyoku/include/tools/bpmcalculator.h

41 lines
923 B
C++

#pragma once
#include "tools/music.h"
#include <memory>
#include <vector>
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();
float fetchCurrentBPMApproximation();
microsec getStartingOffset() const;
void setStartingOffset(microsec offset);
void moveStartingOffsetBy(microsec shift);
microsec fetchTimeUntilNextBeat();
microsec fetchBeatInterval();
private:
bool _need_recalculate;
bool _calculating;
std::shared_ptr<Music> _music;
std::vector<microsec> _deltas;
microsec _previous_click_offset;
microsec _first_click_offset;
int _approximated_bpm;
inline float calculateBPM(microsec all_microseconds, std::size_t beats_amount) const;
inline void reset();
};