Loading...
Searching...
No Matches
ExecutionContext.hpp
1#pragma once
2#include <Process/ExecutionCommand.hpp>
3#include <Process/TimeValue.hpp>
4
5#include <ossia/detail/lockfree_queue.hpp>
6#include <ossia/detail/thread.hpp>
7#include <ossia/editor/scenario/time_value.hpp>
8
9#include <score_lib_process_export.h>
10
11#include <atomic>
12#include <memory>
13namespace ossia
14{
15class graph_node;
16class graph_interface;
17struct execution_state;
18
19#if __cplusplus > 201703L
20// TODO moveme
21static const constexpr struct disable_init_key_t
22{
23} disable_init;
24struct disable_init_t
25{
26 disable_init_t(disable_init_key_t) { }
27 disable_init_t() = delete;
28 disable_init_t(const disable_init_t&) = delete;
29 disable_init_t(disable_init_t&&) = delete;
30 disable_init_t& operator=(const disable_init_t&) = delete;
31 disable_init_t& operator=(disable_init_t&&) = delete;
32};
33#endif
34
35namespace net
36{
37class node_base;
38}
39}
40namespace score
41{
42struct DocumentContext;
43template <typename T, typename U, typename V>
44class GenericComponentFactoryList;
45}
46namespace State
47{
48struct Address;
49}
50namespace Process
51{
52class ProcessModel;
53}
54namespace Execution
55{
56struct Transaction;
57class ProcessComponent;
58class ProcessComponentFactory;
59class ProcessComponentFactoryList;
60struct SetupContext;
61namespace Settings
62{
63class Model;
64}
65
66using time_function = smallfun::function<ossia::time_value(const TimeVal&)>;
67using reverse_time_function = smallfun::function<TimeVal(const ossia::time_value&)>;
68
69using ExecutionCommandQueue = moodycamel::ConcurrentQueue<ExecutionCommand>;
70using EditionCommandQueue = moodycamel::ConcurrentQueue<ExecutionCommand>;
71using GCCommandQueue = moodycamel::ConcurrentQueue<GCCommand>;
72
75struct SCORE_LIB_PROCESS_EXPORT Context
76{
77 std::weak_ptr<void> alias;
78
79 auto acquireExecutionQueue() const noexcept
80 {
81 return std::shared_ptr<Execution::ExecutionCommandQueue>(
82 alias.lock(), &executionQueue);
83 }
84 auto acquireEditionQueue() const noexcept
85 {
86 return std::shared_ptr<Execution::EditionCommandQueue>(alias.lock(), &editionQueue);
87 }
88 auto acquireGCQueue() const noexcept
89 {
90 return std::shared_ptr<Execution::GCCommandQueue>(alias.lock(), &gcQueue);
91 }
92 std::weak_ptr<const Context> weakSelf() const noexcept
93 {
94 return std::shared_ptr<const Context>(alias.lock(), this);
95 }
96 std::weak_ptr<Execution::ExecutionCommandQueue> weakExecutionQueue() const noexcept
97 {
98 return std::shared_ptr<Execution::ExecutionCommandQueue>(
99 alias.lock(), &executionQueue);
100 }
101 std::weak_ptr<Execution::EditionCommandQueue> weakEditionQueue() const noexcept
102 {
103 return std::shared_ptr<Execution::EditionCommandQueue>(alias.lock(), &editionQueue);
104 }
105 std::weak_ptr<Execution::GCCommandQueue> weakGCQueue() const noexcept
106 {
107 return std::shared_ptr<Execution::GCCommandQueue>(alias.lock(), &gcQueue);
108 }
109
110 const score::DocumentContext& doc;
111 const std::atomic_bool& created;
112
119 Execution::reverse_time_function reverseTime;
120
122 ExecutionCommandQueue& executionQueue;
123 EditionCommandQueue& editionQueue;
124 GCCommandQueue& gcQueue;
125 SetupContext& setup;
126
127 const std::shared_ptr<ossia::graph_interface>& execGraph;
128 const std::shared_ptr<ossia::execution_state>& execState;
129
130 auto& context() const { return *this; }
131
132#if !defined(_MSC_VER)
133#if __cplusplus > 201703L
134#pragma clang diagnostic push
135#pragma clang diagnostic ignored "-Wunknown-attributes"
136 [[no_unique_address]] ossia::disable_init_t disable_copy;
137#pragma clang diagnostic pop
138#else
139 Context() = delete;
140 Context(const Context&) = delete;
141 Context& operator=(const Context&) = delete;
142 Context(Context&&) = delete;
143 Context& operator=(Context&&) = delete;
144#endif
145#endif
146};
147
148}
149
150#define in_exec this->system().executionQueue.enqueue
151#define in_edit this->system().editionQueue.enqueue
152#define weak_exec this->system().weakExecutionQueue()
153#define weak_edit this->system().weakEditionQueue()
154#define weak_gc this->system().weakGCQueue()
Components used for the execution of a score.
Definition ProcessComponent.cpp:14
smallfun::function< ossia::time_value(const TimeVal &)> time_function
Sets-up and manages the main execution clock.
Definition ExecutionContext.hpp:66
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:33
Base toolkit upon which the software is built.
Definition Application.cpp:97
Definition ExecutionContext.hpp:76
ExecutionCommandQueue & executionQueue
Definition ExecutionContext.hpp:122
Execution::time_function time
Definition ExecutionContext.hpp:118
Definition ExecutionSetup.hpp:38
Definition TimeValue.hpp:21
Definition DocumentContext.hpp:18