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>
17 namespace Jit
18 {
19 class JitEffectModel;
20 }
21 
22 PROCESS_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)
28 namespace Jit
29 {
30 struct Driver;
31 
32 using NodeCompiler = Driver;
33 using NodeFactory = std::function<ossia::graph_node*()>;
34 
35 class 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)
43 public:
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)
69 private:
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 
82 struct LanguageSpec
83 {
84  static constexpr const char* language = "C++";
85 };
86 
88 using LayerFactory = Process::EffectLayerFactory_T<
89  JitEffectModel, Process::DefaultEffectItem,
91  JitEffectModel, JitEffectModel::p_script, LanguageSpec>>;
92 }
93 
94 namespace Process
95 {
96 template <>
97 QString
98 EffectProcessFactory_T<Jit::JitEffectModel>::customConstructionData() const noexcept;
99 
100 template <>
101 Process::Descriptor
102 EffectProcessFactory_T<Jit::JitEffectModel>::descriptor(QString d) const noexcept;
103 }
104 
105 namespace Execution
106 {
108  : public Execution::ProcessComponent_T<Jit::JitEffectModel, ossia::node_process>
109 {
110  COMPONENT_METADATA("122ceaeb-cbcc-4808-91f2-1929e3ca8292")
111 
112 public:
113  static constexpr bool is_unique = true;
114 
116  Jit::JitEffectModel& proc, const Execution::Context& ctx, QObject* parent);
117  ~JitEffectComponent() override;
118 };
121 }
122 
123 namespace Jit
124 {
125 class EditScript : public Scenario::EditScript<JitEffectModel, JitEffectModel::p_script>
126 {
127  SCORE_COMMAND_DECL(CommandFactoryName(), EditScript, "Edit a C++ program")
128 public:
130 };
131 
132 }
133 
134 namespace score
135 {
136 template <>
137 struct StaticPropertyCommand<Jit::JitEffectModel::p_script> : Jit::EditScript
138 {
139  using Jit::EditScript::EditScript;
140 };
141 }
Definition: DataStreamVisitor.hpp:202
Definition: JitModel.hpp:109
Definition: Process/Execution/ProcessComponent.hpp:119
Definition: JSONVisitor.hpp:423
Definition: JitModel.hpp:126
Definition: DefaultEffectItem.hpp:26
Definition: EffectFactory.hpp:66
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
Definition: ExecutionContext.hpp:76
Definition: Process/Execution/ProcessComponent.hpp:89
Definition: ScriptProcess.hpp:14
Definition: TimeValue.hpp:21
Definition: PropertyCommand.hpp:112