Loading...
Searching...
No Matches
JitModel.hpp
1#pragma once
2#include <Process/Execution/ProcessComponent.hpp>
3#include <Process/GenericProcessFactory.hpp>
4#include <Process/Process.hpp>
5#include <Process/ProcessMetadata.hpp>
6#include <Process/Script/ScriptEditor.hpp>
7
8#include <Scenario/Commands/ScriptEditCommand.hpp>
9
10#include <Control/DefaultEffectItem.hpp>
11#include <Effect/EffectFactory.hpp>
12#include <JitCpp/EditScript.hpp>
13
14#include <ossia/dataflow/execution_state.hpp>
15#include <ossia/dataflow/graph_node.hpp>
16#include <ossia/dataflow/node_process.hpp>
17namespace Jit
18{
19class JitEffectModel;
20}
21
22PROCESS_METADATA(
23 , Jit::JitEffectModel, "0a3b49d6-4ce7-4668-aec3-9505b6ee1a60", "Jit", "JIT",
24 Process::ProcessCategory::Script, "Script", "JIT compilation process", "ossia score",
25 QStringList{}, {}, {},
26 QUrl("https://ossia.io/score-docs/processes/cpp_jit.html#c-jit"),
27 Process::ProcessFlags::SupportsAll)
28namespace Jit
29{
30struct Driver;
31
32using NodeCompiler = Driver;
33using NodeFactory = std::function<ossia::graph_node*()>;
34
35class JitEffectModel : public Process::ProcessModel
36{
37 friend class JitUI;
38 friend class JitUpdateUI;
39 SCORE_SERIALIZE_FRIENDS
40 PROCESS_METADATA_IMPL(JitEffectModel)
41
42 W_OBJECT(JitEffectModel)
43public:
44 JitEffectModel(
45 TimeVal t, const QString& jitProgram, const Id<Process::ProcessModel>&,
46 QObject* parent);
47 ~JitEffectModel() override;
48
49 JitEffectModel(DataStream::Deserializer& vis, QObject* parent);
50 JitEffectModel(JSONObject::Deserializer& vis, QObject* parent);
51 JitEffectModel(DataStream::Deserializer&& vis, QObject* parent);
52 JitEffectModel(JSONObject::Deserializer&& vis, QObject* parent);
53
54 bool validate(const QString& txt) const noexcept;
55
56 const QString& script() const { return m_text; }
57 [[nodiscard]] Process::ScriptChangeResult setScript(const QString& txt);
58 void scriptChanged(const QString& txt) W_SIGNAL(scriptChanged, txt);
59 void programChanged() W_SIGNAL(programChanged);
60
61 static constexpr bool hasExternalUI() noexcept { return true; }
62
63 QString prettyName() const noexcept override;
64
65 std::shared_ptr<NodeFactory> factory;
66
67 void errorMessage(int line, const QString& e) W_SIGNAL(errorMessage, line, e);
68 PROPERTY(QString, script READ script WRITE setScript NOTIFY scriptChanged)
69private:
70 std::shared_ptr<NodeFactory> getJitFactory();
71
72 QString effect() const noexcept override;
73 void loadPreset(const Process::Preset& preset) override;
74 Process::Preset savePreset() const noexcept override;
75
76 void init();
77 [[nodiscard]] Process::ScriptChangeResult reload();
78 QString m_text;
79 std::unique_ptr<NodeCompiler> m_compiler;
80};
81
82struct LanguageSpec
83{
84 static constexpr const char* language = "C++";
85};
86
88using LayerFactory = Process::EffectLayerFactory_T<
89 JitEffectModel, Process::DefaultEffectItem,
91 JitEffectModel, JitEffectModel::p_script, LanguageSpec>>;
92}
93
94namespace Process
95{
96template <>
97QString
98EffectProcessFactory_T<Jit::JitEffectModel>::customConstructionData() const noexcept;
99
100template <>
101Process::Descriptor
102EffectProcessFactory_T<Jit::JitEffectModel>::descriptor(QString d) const noexcept;
103
104template <>
105Process::Descriptor EffectProcessFactory_T<Jit::JitEffectModel>::descriptor(
106 const Process::ProcessModel& d) const noexcept;
107}
108
109namespace Execution
110{
112 : public Execution::ProcessComponent_T<Jit::JitEffectModel, ossia::node_process>
113{
114 COMPONENT_METADATA("122ceaeb-cbcc-4808-91f2-1929e3ca8292")
115
116public:
117 static constexpr bool is_unique = true;
118
120 Jit::JitEffectModel& proc, const Execution::Context& ctx, QObject* parent);
121 ~JitEffectComponent() override;
122};
125}
126
127namespace Jit
128{
129class EditScript : public Scenario::EditScript<JitEffectModel, JitEffectModel::p_script>
130{
131 SCORE_COMMAND_DECL(CommandFactoryName(), EditScript, "Edit a C++ program")
132public:
133 using Scenario::EditScript<JitEffectModel, JitEffectModel::p_script>::EditScript;
134};
135
136}
137
138namespace score
139{
140template <>
141struct StaticPropertyCommand<Jit::JitEffectModel::p_script> : Jit::EditScript
142{
143 using Jit::EditScript::EditScript;
144};
145}
Definition DataStreamVisitor.hpp:202
Definition JitModel.hpp:113
Definition Process/Execution/ProcessComponent.hpp:119
Definition JSONVisitor.hpp:423
Definition JitModel.hpp:130
Definition DefaultEffectItem.hpp:26
Definition EffectFactory.hpp:67
Definition EffectFactory.hpp:14
The Process class.
Definition score-lib-process/Process/Process.hpp:61
Definition ScriptEditor.hpp:42
Definition ScriptEditCommand.hpp:18
The id_base_t class.
Definition Identifier.hpp:57
Components used for the execution of a score.
Definition ProcessComponent.cpp:12
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
Base toolkit upon which the software is built.
Definition Application.cpp:90
STL namespace.
Definition ExecutionContext.hpp:76
Definition Process/Execution/ProcessComponent.hpp:89
Definition ScriptProcess.hpp:14
Definition TimeValue.hpp:21
Definition PropertyCommand.hpp:112