2#include <ossia/detail/config.hpp>
4#include <ossia/detail/flicks.hpp>
22struct OSSIA_EXPORT time_sync_callback
24 virtual ~time_sync_callback();
26 virtual void triggered();
29 virtual void entered_evaluation();
32 virtual void entered_triggering();
36 virtual void trigger_date_fixed(ossia::time_value);
39 virtual void left_evaluation();
42 virtual void finished_evaluation(
bool);
45struct OSSIA_EXPORT time_sync_callbacks
47 ossia::small_vector<time_sync_callback*, 2> callbacks;
51 for(
auto cb : callbacks)
58 for(
auto v : callbacks)
62 void entered_evaluation()
64 for(
auto v : callbacks)
65 v->entered_evaluation();
68 void entered_triggering()
70 for(
auto v : callbacks)
71 v->entered_triggering();
74 void trigger_date_fixed(ossia::time_value t)
76 for(
auto v : callbacks)
77 v->trigger_date_fixed(t);
80 void left_evaluation()
82 for(
auto v : callbacks)
86 void finished_evaluation(
bool b)
88 for(
auto v : callbacks)
89 v->finished_evaluation(b);
102class OSSIA_EXPORT time_sync final
104 friend class ossia::scenario;
107 using container = ossia::small_vector<std::shared_ptr<time_event>, 2>;
108 using iterator = container::iterator;
109 using const_iterator = container::const_iterator;
142 iterator insert(const_iterator, std::shared_ptr<time_event>);
143 void remove(
const std::shared_ptr<time_event>&);
154 [[nodiscard]]
bool is_observing_expression() const noexcept;
155 [[nodiscard]]
bool is_evaluating() const noexcept;
159 void start_trigger_request() noexcept;
160 void end_trigger_request() noexcept;
169 [[nodiscard]]
bool is_autotrigger() const noexcept;
170 void set_autotrigger(
bool) noexcept;
172 [[nodiscard]]
bool is_start() const noexcept;
173 void set_start(
bool) noexcept;
176 void observe_expression(
bool);
177 inline
void observe_expression(
bool b, auto&& cb)
181 return observe_expression_impl(b, std::move(cb));
192 [[nodiscard]]
bool muted() const noexcept {
return m_muted; }
200 enum class status : uint8_t
206 [[nodiscard]] status get_status() const noexcept {
return m_status; }
208 void set_sync_rate(
double syncRatio)
noexcept { m_sync_rate = syncRatio; }
209 [[nodiscard]]
double get_sync_rate() const noexcept {
return m_sync_rate; }
210 [[nodiscard]]
bool has_sync_rate() const noexcept {
return m_sync_rate > 0; }
212 void set_trigger_date(time_value v)
noexcept
215 callbacks.trigger_date_fixed(v);
217 [[nodiscard]] time_value get_trigger_date() const noexcept {
return m_trigger_date; }
218 [[nodiscard]]
bool has_trigger_date() const noexcept
220 return !m_trigger_date.infinite();
223 void set_is_being_triggered(
bool v)
noexcept;
224 [[nodiscard]]
bool is_being_triggered() const noexcept {
return m_is_being_triggered; }
227 ossia::expression_ptr m_expression;
228 container m_timeEvents;
230 std::optional<expressions::expression_callback_iterator> m_callback;
232 double m_sync_rate = 0.;
234 std::atomic_bool trigger_request{};
235 time_value m_trigger_date = Infinite;
239 bool m_evaluating : 1;
241 bool m_autotrigger : 1;
242 bool m_is_being_triggered : 1;
expression_bool : a constant boolean value.
Definition expression_bool.hpp:16
The state class.
Definition editor/state/state.hpp:25
The time_event class.
Definition time_event.hpp:34
std::function< void(status)> exec_callback
to get the event status back
Definition time_event.hpp:63
iterator emplace(const_iterator, time_event::exec_callback, expression_ptr=expressions::make_expression_true())
create and store a time_event
Definition time_sync.cpp:92
time_value get_date() const noexcept
get the date
Definition time_sync.cpp:39
const expression & get_expression() const noexcept
get the expression of the time_sync
Definition time_sync.cpp:61
time_sync_callbacks callbacks
Execution callbacks.
Definition time_sync.hpp:198
const auto & get_time_events() const noexcept
get the time_events of the time_sync
Definition time_sync.hpp:151
time_sync & set_expression(expression_ptr) noexcept
set the expression of the time_sync
Definition time_sync.cpp:66
auto & get_time_events() noexcept
get the time_events of the time_sync
Definition time_sync.hpp:147
expression_ptr make_expression_true()
make_expression_true
Definition expression.hpp:130
smallfun::function< void(bool), smallfun::DefaultSize *2 > expression_result_callback
Definition expression_fwd.hpp:24
expressions::expression_base expression
Definition expression_fwd.hpp:222
The time_value class.
Definition ossia/editor/scenario/time_value.hpp:30