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