OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
time_interval.hpp
Go to the documentation of this file.
1#pragma once
2#include <ossia/detail/config.hpp>
3
4#include <ossia/dataflow/transport.hpp>
5#include <ossia/detail/flat_map.hpp>
6#include <ossia/detail/flicks.hpp>
7#include <ossia/detail/optional.hpp>
9#if defined(OSSIA_SCENARIO_DATAFLOW)
11#endif
12#include <ossia/editor/scenario/execution_log.hpp>
13#include <ossia/editor/scenario/time_signature.hpp>
15
16#include <smallfun.hpp>
17
18#include <memory>
19
23namespace ossia
24{
25struct token_request;
26class time_event;
27class time_process;
28class graph_node;
29
30using time_signature_map = ossia::flat_map<ossia::time_value, time_signature>;
31
32#if defined(OSSIA_SCENARIO_DATAFLOW)
33using tempo_curve = ossia::curve<int64_t, double>;
34#endif
35
48class OSSIA_EXPORT time_interval
49{
50public:
51#if defined(OSSIA_SCENARIO_DATAFLOW)
52 const std::shared_ptr<ossia::graph_node> node;
53#endif
54
55 auto get_date() const noexcept { return m_date; }
56 auto get_offset() const noexcept { return m_offset; }
57 double get_internal_speed() const noexcept { return m_speed; }
58
59 double get_speed(time_value date) const noexcept;
60
64 double speed_override() const noexcept;
65
69 double local_time_factor(const ossia::token_request& parent_request) const noexcept;
70
74 int64_t
75 advance_for(ossia::time_value, const ossia::token_request& parent_request) const noexcept;
76
80 int64_t take_backward_step(
81 ossia::time_value, const ossia::token_request& parent_request) noexcept;
82
83 void set_offset(ossia::time_value g) noexcept { m_offset = g; }
84
85 void set_speed(double g) noexcept { m_speed = g; }
86
87 void set_parent_speed(double sp) noexcept { m_parentSpeed = sp; }
88 tick_transport_info current_transport_info() const noexcept;
89
90 void
91 tick_current(ossia::time_value offset, const ossia::token_request& parent_request);
92
94 void tick(
95 ossia::time_value, const ossia::token_request& parent_request, double ratio = 1.0);
96
102 void tick_offset(
104 const ossia::token_request& parent_request, int32_t start_sample = -1,
105 int32_t length_sample = -1);
106 void tick_offset_speed_precomputed(
108 const ossia::token_request& parent_request, int32_t start_sample = -1,
109 int32_t length_sample = -1);
110
116 = std::optional<smallfun::function<void(bool, ossia::time_value), 32>>;
117
129 static std::shared_ptr<time_interval> create(
131 ossia::time_value = Zero, ossia::time_value = Infinite);
132
135 ossia::time_value = Zero, ossia::time_value = Infinite);
136
139
141 void start();
142 void start_and_tick();
143
145 void stop();
146
148 void pause();
149
151 void resume();
152
159 void offset(ossia::time_value);
160
161 void transport(ossia::time_value);
162
167 void set_callback(exec_callback);
168 void set_callback(smallfun::function<void(bool, ossia::time_value), 32>);
169
172 const time_value& get_nominal_duration() const;
173
177 time_interval& set_nominal_duration(ossia::time_value);
178
181 const time_value& get_min_duration() const;
182
186 time_interval& set_min_duration(ossia::time_value);
187
190 const time_value& get_max_duration() const;
191
195 time_interval& set_max_duration(ossia::time_value);
196
199 time_event& get_start_event() const;
200
203 time_event& get_end_event() const;
204
209 void add_time_process(std::shared_ptr<time_process>);
210
215 void remove_time_process(time_process*);
216
217 void reserve_processes(std::size_t sz);
218
221 const std::vector<std::shared_ptr<time_process>>& get_time_processes() const
222 {
223 return m_processes;
224 }
225
226 bool running() const noexcept { return m_running; }
227 void cleanup();
228 void mute(bool);
229
230#if defined(OSSIA_SCENARIO_DATAFLOW)
231 void set_tempo_curve(std::optional<tempo_curve> curve);
232#endif
233 void set_time_signature_map(std::optional<time_signature_map> map);
234 void set_quarter_duration(double tu);
235
236#if defined(OSSIA_EXECUTION_LOG)
237 std::string name;
238#endif
239
240 bool graphal{};
241
242private:
243 time_interval(const time_interval&) = delete;
244 time_interval(time_interval&&) = delete;
245 time_interval& operator=(const time_interval&) = delete;
246 time_interval& operator=(time_interval&&) = delete;
247
253 void state(ossia::time_value from, ossia::time_value to);
254
255 time_signature
256 signature(time_value date, const ossia::token_request& parent_request) const noexcept;
257 double
258 tempo(time_value date, const ossia::token_request& parent_request) const noexcept;
259 double tempo(time_value date) const noexcept;
260
261 void tick_impl(
262 ossia::time_value old_date, ossia::time_value new_date, ossia::time_value offset,
263 const ossia::token_request& parent_request);
264
267 to_local_offset(ossia::time_value offset, double factor) const noexcept;
268
270 int64_t take_step(double exact) noexcept;
271
272 std::vector<std::shared_ptr<time_process>> m_processes;
273 time_interval::exec_callback m_callback;
274
275 time_event& m_start;
276 time_event& m_end;
277
278 time_value m_nominal{};
279 time_value m_min{};
280 time_value m_max{};
281
282 time_value m_date{};
283 time_value m_offset{};
284
285 time_value m_tick_offset{};
286
289 int32_t m_tick_start_sample{-1};
290 int32_t m_tick_length_sample{-1};
291
292 double m_current_tempo{};
293
294 time_signature_map m_timeSignature{};
295#if defined(OSSIA_SCENARIO_DATAFLOW)
296 tempo_curve m_tempoCurve{};
297#endif
298
299 ossia::quarter_note m_musical_start_last_signature{};
300
301 ossia::quarter_note m_musical_start_last_bar{};
302 ossia::quarter_note m_musical_start_position{};
303
304 ossia::quarter_note m_musical_end_last_bar{};
305 ossia::quarter_note m_musical_end_position{};
306
307 double m_speed{1.};
308 double m_date_residue{};
309 double m_globalSpeed{1.};
310 double m_parentSpeed{1.};
311 time_signature m_current_signature{};
312 double m_quarter_duration{ossia::quarter_duration<double>};
313 bool m_running{false};
314 bool m_hasTempo{false};
315 bool m_hasSignature{false};
316};
317}
The curve class.
Definition curve.hpp:59
The time_event class.
Definition time_event.hpp:34
The time_interval class.
Definition time_interval.hpp:49
~time_interval()
destructor
const std::vector< std::shared_ptr< time_process > > & get_time_processes() const
get time processes attached to the time_interval
Definition time_interval.hpp:221
std::optional< smallfun::function< void(bool, ossia::time_value), 32 > > exec_callback
to get the interval execution back
Definition time_interval.hpp:116
The time_process class.
Definition time_process.hpp:25
Definition git_info.h:7
The time_value class.
Definition ossia/editor/scenario/time_value.hpp:30