AvndJit.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 
18 #include <score_plugin_jit_export.h>
19 namespace AvndJit
20 {
21 class Model;
22 }
23 
24 namespace Jit
25 {
26 struct Driver;
27 }
28 PROCESS_METADATA(
29  , AvndJit::Model, "193686f2-1f3b-45ce-9251-2e79ca06933b", "Jit", "Avendish",
30  Process::ProcessCategory::Script, "Script", "Avendish compilation process",
31  "ossia score", QStringList{}, {}, {},
32  QUrl("https://ossia.io/score-docs/development/plugins/plugins-with-avendish.html#avendish-documentation"),
33  Process::ProcessFlags::SupportsAll)
34 namespace AvndJit
35 {
36 using NodeCompiler = Jit::Driver;
37 using NodeFunction = ossia::graph_node*(int, double);
38 using NodeFactory = std::function<NodeFunction>;
39 class Model : public Process::ProcessModel
40 {
41  friend class JitUI;
42  friend class JitUpdateUI;
43  SCORE_SERIALIZE_FRIENDS
44  PROCESS_METADATA_IMPL(Model)
45 
46  W_OBJECT(Model)
47 public:
48  Model(
49  TimeVal t, const QString& jitProgram, const Id<Process::ProcessModel>&,
50  QObject* parent);
51  ~Model() override;
52 
53  Model(DataStream::Deserializer& vis, QObject* parent);
54  Model(JSONObject::Deserializer& vis, QObject* parent);
55  Model(DataStream::Deserializer&& vis, QObject* parent);
56  Model(JSONObject::Deserializer&& vis, QObject* parent);
57 
58  bool validate(const QString& txt) const noexcept;
59 
60  const QString& script() const { return m_text; }
61  [[nodiscard]] Process::ScriptChangeResult setScript(const QString& txt);
62  void scriptChanged(const QString& txt) W_SIGNAL(scriptChanged, txt);
63  void programChanged() W_SIGNAL(programChanged);
64 
65  static constexpr bool hasExternalUI() noexcept { return true; }
66 
67  QString prettyName() const noexcept override;
68 
69  std::shared_ptr<NodeFactory> factory;
70 
71  void errorMessage(int line, const QString& e) W_SIGNAL(errorMessage, line, e);
72  PROPERTY(QString, script READ script WRITE setScript NOTIFY scriptChanged)
73 private:
74  std::shared_ptr<NodeFactory> getJitFactory();
75 
76  QString effect() const noexcept override;
77  void loadPreset(const Process::Preset& preset) override;
78  Process::Preset savePreset() const noexcept override;
79 
80  void init();
81  [[nodiscard]] Process::ScriptChangeResult reload();
82  QString m_text;
83  std::unique_ptr<NodeCompiler> m_compiler;
84 };
85 
86 struct LanguageSpec
87 {
88  static constexpr const char* language = "C++";
89 };
90 
92 using LayerFactory = Process::EffectLayerFactory_T<
95 }
96 
97 namespace Process
98 {
99 template <>
100 QString EffectProcessFactory_T<AvndJit::Model>::customConstructionData() const noexcept;
101 
102 template <>
103 Process::Descriptor
104 EffectProcessFactory_T<AvndJit::Model>::descriptor(QString d) const noexcept;
105 }
106 
107 namespace AvndJit
108 {
109 class Executor final
110  : public Execution::ProcessComponent_T<AvndJit::Model, ossia::node_process>
111 {
112  COMPONENT_METADATA("086fbfcf-44e9-4ea6-baad-b4f76e938d69")
113 
114 public:
115  static constexpr bool is_unique = true;
116 
117  Executor(AvndJit::Model& proc, const Execution::Context& ctx, QObject* parent);
118  ~Executor() override;
119 };
121 }
122 
123 namespace AvndJit
124 {
125 class EditAvndScript : public Scenario::EditScript<Model, Model::p_script>
126 {
127  SCORE_COMMAND_DECL(Jit::CommandFactoryName(), EditAvndScript, "Edit a C++ program")
128 public:
130 };
131 
132 }
133 
134 namespace score
135 {
136 template <>
137 struct StaticPropertyCommand<AvndJit::Model::p_script> : AvndJit::EditAvndScript
138 {
139  using AvndJit::EditAvndScript::EditAvndScript;
140 };
141 }
Definition: AvndJit.hpp:126
Definition: AvndJit.hpp:111
Definition: DataStreamVisitor.hpp:202
Definition: Process/Execution/ProcessComponent.hpp:119
Definition: JSONVisitor.hpp:423
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
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: Driver.hpp:11
Definition: ScriptProcess.hpp:14
Definition: TimeValue.hpp:21
Definition: PropertyCommand.hpp:112