| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 | 
							- #pragma once
 
- #include <mutex>
 
- #include <atomic>
 
- #include <thread>
 
- #include <chrono>
 
- 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<bool> 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
 
 
  |