OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
clock.hpp
1#pragma once
2
3#include <ossia/detail/config.hpp>
4
6
7#include <atomic>
8#include <chrono>
9#include <functional>
10#include <memory>
11#include <thread>
12
13namespace ossia
14{
15class state;
16class time_interval;
17using clock_type = std::chrono::steady_clock;
18class OSSIA_EXPORT clock
19{
20 friend class time_interval;
21
22public:
23 enum exec_status
24 {
25 RUNNING,
26 STOPPED
27 };
28 using exec_status_callback = std::function<void(exec_status)>;
29
31 clock(ossia::time_interval& cst, double time_ratio = 1000.);
32
34 ~clock();
35
37 void start_and_tick();
38
40 void stop();
41
43 void pause();
44
46 [[nodiscard]] bool paused() const;
47
49 void resume();
50
55 bool tick();
56
59 [[nodiscard]] time_value get_duration() const;
60
64 clock& set_duration(ossia::time_value);
65
68 [[nodiscard]] time_value get_granularity() const;
69
73 clock& set_granularity(std::chrono::microseconds);
74 clock& set_granularity(std::chrono::milliseconds);
75
78 [[nodiscard]] bool running() const;
79
82 [[nodiscard]] time_value get_position() const;
83
86 [[nodiscard]] time_value get_date() const;
87
88 // Execution status will be called when the clock starts and stops.
89 void set_exec_status_callback(exec_status_callback);
90 [[nodiscard]] exec_status_callback get_exec_status_callback() const;
91
92private:
94 void do_set_duration(ossia::time_value);
95
98 void request_stop();
99
100 time_interval& m_interval;
101
102 double m_ratio{};
103
104 time_value m_duration{};
105
107 time_value m_granularity{};
108
111 time_value m_date{};
112
113 std::thread m_thread;
114
116 clock_type::time_point m_lastTime{};
117
118 exec_status_callback m_statusCallback;
119
121 int64_t m_elapsedTime{};
122
123 std::atomic_bool m_running{};
124 std::atomic_bool m_paused{};
125 std::atomic_bool m_shouldStop{};
126
128 void thread_callback();
129};
130}
The time_interval class.
Definition time_interval.hpp:49
Definition git_info.h:7
The time_value class.
Definition ossia/editor/scenario/time_value.hpp:30