OSSIA
Open Scenario System for Interactive Application
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)
10 #include <ossia/editor/curve/curve.hpp>
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 
23 namespace ossia
24 {
25 struct token_request;
26 class time_event;
27 class time_process;
28 class graph_node;
29 
30 using time_signature_map = ossia::flat_map<ossia::time_value, time_signature>;
31 
32 #if defined(OSSIA_SCENARIO_DATAFLOW)
33 using tempo_curve = ossia::curve<int64_t, double>;
34 #endif
35 
48 class OSSIA_EXPORT time_interval
49 {
50 public:
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  void set_offset(ossia::time_value g) noexcept { m_offset = g; }
61 
62  void set_speed(double g) noexcept { m_speed = g; }
63 
64  void set_parent_speed(double sp) noexcept { m_parentSpeed = sp; }
65  tick_transport_info current_transport_info() const noexcept;
66 
67  void
68  tick_current(ossia::time_value offset, const ossia::token_request& parent_request);
69 
70  void tick(
71  ossia::time_value, const ossia::token_request& parent_request, double ratio = 1.0);
72  void tick_offset(
74  const ossia::token_request& parent_request);
75  void tick_offset_speed_precomputed(
77  const ossia::token_request& parent_request);
78 
84  = std::optional<smallfun::function<void(bool, ossia::time_value), 32>>;
85 
97  static std::shared_ptr<time_interval> create(
99  ossia::time_value = Zero, ossia::time_value = Infinite);
100 
103  ossia::time_value = Zero, ossia::time_value = Infinite);
104 
107 
109  void start();
110  void start_and_tick();
111 
113  void stop();
114 
116  void pause();
117 
119  void resume();
120 
127  void offset(ossia::time_value);
128 
129  void transport(ossia::time_value);
130 
135  void set_callback(exec_callback);
136  void set_callback(smallfun::function<void(bool, ossia::time_value), 32>);
137 
140  const time_value& get_nominal_duration() const;
141 
145  time_interval& set_nominal_duration(ossia::time_value);
146 
149  const time_value& get_min_duration() const;
150 
154  time_interval& set_min_duration(ossia::time_value);
155 
158  const time_value& get_max_duration() const;
159 
163  time_interval& set_max_duration(ossia::time_value);
164 
167  time_event& get_start_event() const;
168 
171  time_event& get_end_event() const;
172 
177  void add_time_process(std::shared_ptr<time_process>);
178 
183  void remove_time_process(time_process*);
184 
185  void reserve_processes(std::size_t sz);
186 
189  const std::vector<std::shared_ptr<time_process>>& get_time_processes() const
190  {
191  return m_processes;
192  }
193 
194  bool running() const noexcept { return m_running; }
195  void cleanup();
196  void mute(bool);
197 
198 #if defined(OSSIA_SCENARIO_DATAFLOW)
199  void set_tempo_curve(std::optional<tempo_curve> curve);
200 #endif
201  void set_time_signature_map(std::optional<time_signature_map> map);
202  void set_quarter_duration(double tu);
203 
204 #if defined(OSSIA_EXECUTION_LOG)
205  std::string name;
206 #endif
207 
208  bool graphal{};
209 
210 private:
211  time_interval(const time_interval&) = delete;
212  time_interval(time_interval&&) = delete;
213  time_interval& operator=(const time_interval&) = delete;
214  time_interval& operator=(time_interval&&) = delete;
215 
221  void state(ossia::time_value from, ossia::time_value to);
222 
223  time_signature
224  signature(time_value date, const ossia::token_request& parent_request) const noexcept;
225  double
226  tempo(time_value date, const ossia::token_request& parent_request) const noexcept;
227  double tempo(time_value date) const noexcept;
228 
229  void tick_impl(
230  ossia::time_value old_date, ossia::time_value new_date, ossia::time_value offset,
231  const ossia::token_request& parent_request);
232 
233  std::vector<std::shared_ptr<time_process>> m_processes;
234  time_interval::exec_callback m_callback;
235 
236  time_event& m_start;
237  time_event& m_end;
238 
239  time_value m_nominal{};
240  time_value m_min{};
241  time_value m_max{};
242 
243  time_value m_date{};
244  time_value m_offset{};
245 
246  time_value m_tick_offset{};
247 
248  double m_current_tempo{};
249 
250  time_signature_map m_timeSignature{};
251 #if defined(OSSIA_SCENARIO_DATAFLOW)
252  tempo_curve m_tempoCurve{};
253 #endif
254 
255  ossia::quarter_note m_musical_start_last_signature{};
256 
257  ossia::quarter_note m_musical_start_last_bar{};
258  ossia::quarter_note m_musical_start_position{};
259 
260  ossia::quarter_note m_musical_end_last_bar{};
261  ossia::quarter_note m_musical_end_position{};
262 
263  double m_speed{1.};
264  double m_globalSpeed{1.};
265  double m_parentSpeed{1.};
266  time_signature m_current_signature{};
267  double m_quarter_duration{ossia::quarter_duration<double>};
268  bool m_running{false};
269  bool m_hasTempo{false};
270  bool m_hasSignature{false};
271 };
272 }
The time_event class.
Definition: time_event.hpp:34
The time_interval class.
Definition: time_interval.hpp:49
~time_interval()
destructor
std::optional< smallfun::function< void(bool, ossia::time_value), 32 > > exec_callback
to get the interval execution back
Definition: time_interval.hpp:84
const std::vector< std::shared_ptr< time_process > > & get_time_processes() const
get time processes attached to the #time_interval
Definition: time_interval.hpp:189
The time_process class.
Definition: time_process.hpp:24
Definition: git_info.h:7
The time_value class.
Definition: ossia/editor/scenario/time_value.hpp:28