5 #ifndef LODESTAR_METRONOME_HPP
6 #define LODESTAR_METRONOME_HPP
9 #include "TimeResolution.hpp"
10 #include "TimeDuration.hpp"
14 template <TimeDuration TDuration = TimeDuration::milliseconds, TimeResolution TTimeRes = TimeResolution::HighResolution>
17 template <TimeDuration TDuration>
18 class Metronome<TDuration, TimeResolution::HighResolution> {
20 using Clock = std::chrono::high_resolution_clock;
21 Metronome() : period_(100 * (
int) TDuration) {
25 Metronome(
size_t period) : period_(period * (
int) TDuration) {
30 auto current = Clock::now();
32 if (std::chrono::duration_cast<std::chrono::nanoseconds>(current - last_).count() >= period_) {
41 double timeElapsed()
const {
42 auto current = Clock::now();
44 return (
double) std::chrono::duration_cast<std::chrono::nanoseconds>(current - last_).count() / (int) TDuration;
47 std::chrono::time_point<Clock, std::chrono::nanoseconds> last_;
53 #endif //LODESTAR_METRONOME_HPP