2#include <ossia/detail/config.hpp>
4#include <ossia/dataflow/graph/small_graph.hpp>
5#include <ossia/detail/flat_map.hpp>
6#include <ossia/detail/flat_set.hpp>
7#include <ossia/detail/pod_vector.hpp>
9#include <ossia/detail/ptr_set.hpp>
10#include <ossia/detail/small_vector.hpp>
14#include <boost/graph/adjacency_list.hpp>
16#include <ankerl/unordered_dense.h>
23using interval_set = ossia::flat_set<time_interval*>;
24using sync_set = ossia::flat_set<time_sync*>;
25using small_sync_vec = ossia::small_vector<time_sync*, 4>;
26using small_event_vec = std::vector<time_event*>;
29 ossia::time_value min;
30 ossia::time_value max;
31 ossia::time_value offset;
35 int32_t start_sample{-1};
37using overtick_map = ossia::flat_map<time_sync*, overtick>;
43using scenario_graph_t = boost::adjacency_list<
44 boost::smallvecS, boost::smallvecS, boost::undirectedS, scenario_graph_vertex,
48remove_vertex(
typename scenario_graph_t::vertex_descriptor v, scenario_graph_t& g)
50 typedef typename scenario_graph_t::directed_category Cat;
51 g.removing_vertex(v, boost::graph_detail::iterator_stability(g.m_vertices));
52 boost::detail::remove_vertex_dispatch(g, v, Cat());
86class OSSIA_EXPORT scenario final :
public looping_process<scenario>
88 friend class looping_process<scenario>;
98 void add_time_interval(std::shared_ptr<time_interval>);
103 void remove_time_interval(
const std::shared_ptr<time_interval>&);
107 void add_time_sync(std::shared_ptr<time_sync>);
111 void remove_time_sync(
const std::shared_ptr<time_sync>&);
115 const std::shared_ptr<time_sync>& get_start_time_sync()
const;
119 const ptr_container<time_sync>& get_time_syncs()
const;
123 const ptr_container<time_interval>& get_time_intervals()
const;
125 friend struct scenario_graph;
126 void offset_impl(ossia::time_value)
override;
128 void state_impl(
const ossia::token_request& req);
130 void start()
override;
131 void stop()
override;
132 void pause()
override;
133 void resume()
override;
135 void transport_impl(ossia::time_value offset)
override;
136 void mute_impl(
bool)
override;
144 void request_start_interval(
145 ossia::time_interval&,
double ratio = 0.0, ossia::time_value from = {});
151 void request_stop_interval(ossia::time_interval&,
double ratio = 0.0);
153 small_sync_vec get_roots() const noexcept;
156 const ptr_container<time_sync>&, const ptr_container<time_interval>&,
159 ossia::time_value last_date() const noexcept {
return m_last_date; }
161 void set_exclusive(
bool excl)
noexcept;
162 bool exclusive(
bool excl)
const noexcept;
165 void stop_all_intervals();
166 void prepare_offset();
167 void make_rigid(time_interval& itv, time_value min, time_value max);
168 void restore_durations();
169 ossia::time_value m_last_date{ossia::Infinite};
172 struct saved_durations
177 ossia::flat_map<time_interval*, saved_durations> m_offset_durations;
179 ptr_container<time_interval> m_intervals;
180 ptr_container<time_sync> m_nodes;
183 interval_set m_runningIntervals;
184 sync_set m_waitingNodes;
185 small_sync_vec m_rootNodes;
186 small_event_vec m_pendingEvents;
187 small_event_vec m_maxReachedEvents;
188 overtick_map m_overticks;
189 ossia::flat_map<time_interval*, time_value> m_itv_end_map;
190 sync_set m_retry_syncs;
194 overtick_map m_backward_overticks;
195 sync_set m_startNodes;
198 sync_set m_component_visit_cache;
199 std::vector<ossia::time_sync*> m_component_visit_stack;
204 struct quantized_interval
206 ossia::time_interval* interval{};
207 double quantization_ratio{};
208 ossia::time_value from{};
209 operator ossia::time_interval*()
const noexcept {
return interval; }
212 ossia::small_vector<quantized_interval, 2> m_itv_to_start;
213 ossia::small_vector<quantized_interval, 2> m_itv_to_stop;
215 static void make_happen(
216 time_event& event, interval_set& started, interval_set& stopped,
217 ossia::time_value tick_offset,
const ossia::token_request& tok);
219 static void make_dispose(time_event& event, interval_set& stopped);
221 sync_status process_this(
222 time_sync& node, small_event_vec& pendingEvents, small_event_vec& maxReachedEvents,
223 interval_set& started, interval_set& stopped, ossia::time_value tick_offset,
224 const token_request& tok);
226 sync_status trigger_sync(
227 time_sync& node, small_event_vec& pending, small_event_vec& maxReachedEv,
228 interval_set& started, interval_set& stopped, ossia::time_value tick_offset,
229 const token_request& req,
bool maxReached);
231 sync_status process_this_musical(
232 time_sync& node, small_event_vec& pendingEvents, small_event_vec& maxReachedEvents,
233 ossia::time_value tick_offset,
const token_request& tok)
noexcept;
235 sync_status trigger_sync_musical(
236 time_sync& node, small_event_vec& maxReachedEvents, ossia::time_value tick_offset,
237 const token_request& req,
bool maxReached)
noexcept;
240 quantify_time_sync(time_sync& sync,
const ossia::token_request& tk)
noexcept;
243 trigger_quantified_time_sync(time_sync& sync,
bool& maximalDurationReached)
noexcept;
249 ossia::time_interval& interval,
const ossia::token_request& tk,
250 const time_value& tick_ms, ossia::time_value tick, ossia::time_value offset,
251 int32_t start_sample, int32_t end_sample);
253 void stop_interval(ossia::time_interval& itv);
254 void reset_component(ossia::time_sync& n);
255 void reset_all_components_except(ossia::time_sync& n);
257 void state_impl_backward(
const ossia::token_request& tk, time_value tick_amount);
258 void run_interval_backward(
259 ossia::time_interval& interval,
const ossia::token_request& tk,
260 const time_value& tick_ms, ossia::time_value tick, ossia::time_value offset,
261 int32_t start_sample, int32_t end_sample);
The time_event class.
Definition time_event.hpp:34
The time_interval class.
Definition time_interval.hpp:49
time_sync is use to describe temporal structure to synchronize each attached time_event evaluation.
Definition time_sync.hpp:103
OSSIA_INLINE constexpr auto min(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
min function tailored for values
Definition math.hpp:125
OSSIA_INLINE constexpr auto max(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
max function tailored for values
Definition math.hpp:96