#pragma once #include #include #include #include #include namespace midi { class Clock { typedef std::chrono::high_resolution_clock clock; typedef clock::time_point time_point; typedef clock::duration duration; public: typedef unsigned int bpm_type; private: bpm_type bpm; std::mutex bpm_mutex; time_point lastTickTime; std::thread tickThread; std::atomic stopTickThread; bool running; std::mutex running_mutex; public: Clock(); bpm_type getBpm(); void setBpm(bpm_type bpm); duration getTickInterval(); void start(); void stop(); bool isRunning(); static inline time_point now() { return clock::now(); } protected: virtual void tick(); private: void run(); void setRunning(bool running); }; } // namespace