blob: f7c5543ab081cf7422ae13137ad5c5fcc990a9e5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#ifndef SCHEDULE_H_EF7B9D12
#define SCHEDULE_H_EF7B9D12
class Schedule {
public:
explicit Schedule(
double bpm) :
bpm_(bpm),
bps_(bpm_ / 60.0),
tick_(1.0 / bps_)
{
}
double getBPM() const
{
return bpm_;
}
double getBPS() const
{
return bps_;
}
void accumulate(double dt)
{
accum_ += dt;
}
bool step()
{
if (accum_ > tick_)
{
accum_ -= tick_;
beats_++;
return true;
} else {
return false;
}
}
size_t getBeat() const
{
return beats_;
}
private:
double bpm_;
double bps_;
double tick_;
double accum_ = 0.0;
size_t beats_ = 0;
};
#endif /* end of include guard: SCHEDULE_H_EF7B9D12 */
|