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