-
-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathProcessComponent.hpp
More file actions
170 lines (145 loc) · 4.67 KB
/
Copy pathProcessComponent.hpp
File metadata and controls
170 lines (145 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#pragma once
#include <Process/ExecutionComponent.hpp>
#include <Process/ExecutionContext.hpp>
#include <Process/ExecutionTransaction.hpp>
#include <Process/Process.hpp>
#include <Process/ProcessComponent.hpp>
#include <score/model/ComponentFactory.hpp>
#include <score/plugins/ModelFactory.hpp>
#include <ossia/dataflow/graph_node.hpp>
#include <ossia/editor/scenario/time_process.hpp>
#include <QObject>
#include <score_lib_process_export.h>
#include <memory>
#include <verdigris>
#if __cpp_lib_concepts >= 202002L
#include <concepts>
#endif
namespace ossia
{
class scenario;
class time_process;
}
namespace Execution
{
struct Context;
struct Transaction;
template <typename T>
class InvalidProcessException : public std::runtime_error
{
public:
InvalidProcessException(const QString& s)
: std::runtime_error{(Metadata<PrettyName_k, T>::get() + ": " + s).toStdString()}
{
}
};
class SCORE_LIB_PROCESS_EXPORT ProcessComponent
: public Process::GenericProcessComponent<const Context>
, public std::enable_shared_from_this<ProcessComponent>
{
W_OBJECT(ProcessComponent)
ABSTRACT_COMPONENT_METADATA(
Execution::ProcessComponent, "d0f714de-c832-42d8-a605-60f5ffd0b7af")
public:
static constexpr bool is_unique = true;
ProcessComponent(
Process::ProcessModel& proc, const Context& ctx, const QString& name,
QObject* parent);
//! Reimplement this if the element needs two-phase initialization.
virtual void lazy_init();
virtual ~ProcessComponent();
virtual void cleanup();
virtual void stop()
{
process().setExecuting(false);
process().stopExecution();
}
const std::shared_ptr<ossia::time_process>& OSSIAProcessPtr()
{
return m_ossia_process;
}
ossia::time_process& OSSIAProcess() const { return *m_ossia_process; }
std::shared_ptr<ossia::graph_node> node;
//! Override to expose a gfx_forward_node for texture propagation
virtual std::shared_ptr<ossia::graph_node> gfxForwardNode() const { return {}; }
public:
void nodeChanged(
const ossia::node_ptr& old_node, const ossia::node_ptr& new_node,
Execution::Transaction* commands)
E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, nodeChanged, old_node, new_node, commands)
protected:
std::shared_ptr<ossia::time_process> m_ossia_process;
};
template <typename Process_T, typename OSSIA_Process_T>
struct ProcessComponent_T
: public Process::GenericProcessComponent_T<ProcessComponent, Process_T>
{
using Process::GenericProcessComponent_T<
ProcessComponent, Process_T>::GenericProcessComponent_T;
OSSIA_Process_T& OSSIAProcess() const
{
return static_cast<OSSIA_Process_T&>(ProcessComponent::OSSIAProcess());
}
};
class SCORE_LIB_PROCESS_EXPORT ProcessComponentFactory
: public score::GenericComponentFactory<
Process::ProcessModel, Execution::Context, Execution::ProcessComponentFactory>
{
SCORE_ABSTRACT_COMPONENT_FACTORY(Execution::ProcessComponent)
public:
virtual ~ProcessComponentFactory() override;
virtual std::shared_ptr<ProcessComponent>
make(Process::ProcessModel& proc, const Context& ctx, QObject* parent) const = 0;
};
template <typename ProcessComponent_T>
#if __cpp_lib_concepts >= 202002L
requires std::constructible_from<
ProcessComponent_T, typename ProcessComponent_T::model_type&, const Context&,
QObject*>
#endif
class ProcessComponentFactory_T
: public score::GenericComponentFactoryImpl<
ProcessComponent_T, ProcessComponentFactory>
{
public:
using model_type = typename ProcessComponent_T::model_type;
std::shared_ptr<ProcessComponent> make(
Process::ProcessModel& proc, const Context& ctx,
QObject* parent) const final override
{
try
{
#if defined(SCORE_DEBUG)
// A bit slower but really makes backtraces simpler
auto comp = std::shared_ptr<ProcessComponent_T>(
new ProcessComponent_T{static_cast<model_type&>(proc), ctx, parent});
#else
auto comp = std::make_shared<ProcessComponent_T>(
static_cast<model_type&>(proc), ctx, parent);
#endif
comp->lazy_init();
return comp;
}
catch(const std::runtime_error& e)
{
qDebug() << "Error during plug-in creation: " << e.what();
return {};
}
catch(...)
{
return {};
}
}
};
class SCORE_LIB_PROCESS_EXPORT ProcessComponentFactoryList final
: public score::GenericComponentFactoryList<
Process::ProcessModel, Execution::Context, Execution::ProcessComponentFactory>
{
public:
~ProcessComponentFactoryList();
};
}
W_REGISTER_ARGTYPE(ossia::node_ptr)
Q_DECLARE_METATYPE(std::shared_ptr<Execution::ProcessComponent>)
W_REGISTER_ARGTYPE(std::shared_ptr<Execution::ProcessComponent>)
W_REGISTER_ARGTYPE(const std::shared_ptr<Execution::ProcessComponent>&)