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 local_time_factor(const ossia::token_request& parent_request) const noexcept;
65
69 int64_t
70 advance_for(ossia::time_value, const ossia::token_request& parent_request) const noexcept;
71
75 int64_t take_backward_step(
76 ossia::time_value, const ossia::token_request& parent_request) noexcept;
77
78 void set_offset(ossia::time_value g) noexcept { m_offset = g; }
79
80 void set_speed(double g) noexcept { m_speed = g; }
81
82 void set_parent_speed(double sp) noexcept { m_parentSpeed = sp; }
83 tick_transport_info current_transport_info() const noexcept;
84
85 void
86 tick_current(ossia::time_value offset, const ossia::token_request& parent_request);
87
89 void tick(
90 ossia::time_value, const ossia::token_request& parent_request, double ratio = 1.0);
91
97 void tick_offset(
99 const ossia::token_request& parent_request, int32_t start_sample = -1,
100 int32_t length_sample = -1);
101 void tick_offset_speed_precomputed(
103 const ossia::token_request& parent_request, int32_t start_sample = -1,
104 int32_t length_sample = -1);
105
111 = std::optional<smallfun::function<void(bool, ossia::time_value), 32>>;
112
124 static std::shared_ptr<time_interval> create(
126 ossia::time_value = Zero, ossia::time_value = Infinite);
127
130 ossia::time_value = Zero, ossia::time_value = Infinite);
131
134
136 void start();
137 void start_and_tick();
138
140 void stop();
141
143 void pause();
144
146 void resume();
147
154 void offset(ossia::time_value);
155
156 void transport(ossia::time_value);
157
162 void set_callback(exec_callback);
163 void set_callback(smallfun::function<void(bool, ossia::time_value), 32>);
164
167 const time_value& get_nominal_duration() const;
168
172 time_interval& set_nominal_duration(ossia::time_value);
173
176 const time_value& get_min_duration() const;
177
181 time_interval& set_min_duration(ossia::time_value);
182
185 const time_value& get_max_duration() const;
186
190 time_interval& set_max_duration(ossia::time_value);
191
194 time_event& get_start_event() const;
195
198 time_event& get_end_event() const;
199
204 void add_time_process(std::shared_ptr<time_process>);
205
210 void remove_time_process(time_process*);
211
212 void reserve_processes(std::size_t sz);
213
216 const std::vector<std::shared_ptr<time_process>>& get_time_processes() const
217 {
218 return m_processes;
219 }
220
221 bool running() const noexcept { return m_running; }
222 void cleanup();
223 void mute(bool);
224
225#if defined(OSSIA_SCENARIO_DATAFLOW)
226 void set_tempo_curve(std::optional<tempo_curve> curve);
227#endif
228 void set_time_signature_map(std::optional<time_signature_map> map);
229 void set_quarter_duration(double tu);
230
231#if defined(OSSIA_EXECUTION_LOG)
232 std::string name;
233#endif
234
235 bool graphal{};
236
237private:
238 time_interval(const time_interval&) = delete;
239 time_interval(time_interval&&) = delete;
240 time_interval& operator=(const time_interval&) = delete;
241 time_interval& operator=(time_interval&&) = delete;
242
248 void state(ossia::time_value from, ossia::time_value to);
249
250 time_signature
251 signature(time_value date, const ossia::token_request& parent_request) const noexcept;
252 double
253 tempo(time_value date, const ossia::token_request& parent_request) const noexcept;
254 double tempo(time_value date) const noexcept;
255
256 void tick_impl(
257 ossia::time_value old_date, ossia::time_value new_date, ossia::time_value offset,
258 const ossia::token_request& parent_request);
259
262 to_local_offset(ossia::time_value offset, double factor) const noexcept;
263
265 int64_t take_step(double exact) noexcept;
266
267 std::vector<std::shared_ptr<time_process>> m_processes;
268 time_interval::exec_callback m_callback;
269
270 time_event& m_start;
271 time_event& m_end;
272
273 time_value m_nominal{};
274 time_value m_min{};
275 time_value m_max{};
276
277 time_value m_date{};
278 time_value m_offset{};
279
280 time_value m_tick_offset{};
281
284 int32_t m_tick_start_sample{-1};
285 int32_t m_tick_length_sample{-1};
286
287 double m_current_tempo{};
288
289 time_signature_map m_timeSignature{};
290#if defined(OSSIA_SCENARIO_DATAFLOW)
291 tempo_curve m_tempoCurve{};
292#endif
293
294 ossia::quarter_note m_musical_start_last_signature{};
295
296 ossia::quarter_note m_musical_start_last_bar{};
297 ossia::quarter_note m_musical_start_position{};
298
299 ossia::quarter_note m_musical_end_last_bar{};
300 ossia::quarter_note m_musical_end_position{};
301
302 double m_speed{1.};
303 double m_date_residue{};
304 double m_globalSpeed{1.};
305 double m_parentSpeed{1.};
306 time_signature m_current_signature{};
307 double m_quarter_duration{ossia::quarter_duration<double>};
308 bool m_running{false};
309 bool m_hasTempo{false};
310 bool m_hasSignature{false};
311};
312}
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:216
std::optional< smallfun::function< void(bool, ossia::time_value), 32 > > exec_callback
to get the interval execution back
Definition time_interval.hpp:111
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