Texgen.hpp
1 #pragma once
2 #if __has_include(<score_plugin_gfx.hpp>)
3 #define SCORE_JIT_HAS_TEXGEN 1
4 #include <Process/Execution/ProcessComponent.hpp>
5 #include <Process/GenericProcessFactory.hpp>
6 #include <Process/Process.hpp>
7 #include <Process/ProcessMetadata.hpp>
8 #include <Process/Script/ScriptEditor.hpp>
9 #include <Process/Script/ScriptProcess.hpp>
10 
11 #include <Scenario/Commands/ScriptEditCommand.hpp>
12 
13 #include <Control/DefaultEffectItem.hpp>
14 #include <Effect/EffectFactory.hpp>
15 #include <JitCpp/EditScript.hpp>
16 
17 #include <ossia/dataflow/execution_state.hpp>
18 #include <ossia/dataflow/graph_node.hpp>
19 #include <ossia/dataflow/node_process.hpp>
20 
21 #include <verdigris>
22 
23 namespace Jit
24 {
25 class TexgenModel;
26 }
27 PROCESS_METADATA(
28  , Jit::TexgenModel, "b9a20181-2925-4ade-925e-a2fd05fcbf9b", "Jit",
29  "Texture generator", Process::ProcessCategory::Script, "Visuals",
30  "Generate a texture", "ossia score", QStringList{}, {}, {},
31  QUrl("https://ossia.io/score-docs/processes/texgen.html#texture-generator"),
32  Process::ProcessFlags::SupportsAll)
33 namespace Jit
34 {
35 struct Driver;
36 using TexgenFunction = void(unsigned char* rgb, int width, int height, int t);
37 using TexgenCompiler = Driver;
38 using TexgenFactory = std::function<TexgenFunction>;
39 class TexgenModel : public Process::ProcessModel
40 {
41  friend class JitUI;
42  friend class JitUpdateUI;
43  SCORE_SERIALIZE_FRIENDS
44  PROCESS_METADATA_IMPL(TexgenModel)
45 
46  W_OBJECT(TexgenModel)
47 public:
48  TexgenModel(
49  TimeVal t, const QString& jitProgram, const Id<Process::ProcessModel>&,
50  QObject* parent);
51  ~TexgenModel() override;
52 
53  TexgenModel(DataStream::Deserializer& vis, QObject* parent);
54  TexgenModel(JSONObject::Deserializer& vis, QObject* parent);
55  TexgenModel(DataStream::Deserializer&& vis, QObject* parent);
56  TexgenModel(JSONObject::Deserializer&& vis, QObject* parent);
57 
58  bool validate(const QString& txt) const noexcept;
59  const QString& script() const noexcept { return m_text; }
60  [[nodiscard]] Process::ScriptChangeResult setScript(const QString& txt);
61  void scriptChanged(const QString& txt) W_SIGNAL(scriptChanged, txt);
62  void programChanged() W_SIGNAL(programChanged);
63 
64  static constexpr bool hasExternalUI() noexcept { return true; }
65 
66  QString prettyName() const noexcept override;
67 
68  TexgenFactory factory;
69 
70  void errorMessage(int line, const QString& e) W_SIGNAL(errorMessage, line, e);
71 
72  PROPERTY(QString, script READ script WRITE setScript NOTIFY scriptChanged)
73 private:
74  QString effect() const noexcept override;
75  void loadPreset(const Process::Preset& preset) override;
76  Process::Preset savePreset() const noexcept override;
77  void init();
78  [[nodiscard]] Process::ScriptChangeResult reload();
79  QString m_text;
80  std::unique_ptr<TexgenCompiler> m_compiler;
81 };
82 }
83 
84 namespace Process
85 {
86 template <>
87 QString
88 EffectProcessFactory_T<Jit::TexgenModel>::customConstructionData() const noexcept;
89 
90 template <>
91 Process::Descriptor
92 EffectProcessFactory_T<Jit::TexgenModel>::descriptor(QString d) const noexcept;
93 }
94 class QPlainTextEdit;
95 namespace Jit
96 {
97 
98 struct TexgenLanguageSpec
99 {
100  static constexpr const char* language = "C++";
101 };
102 
103 using TexgenEffectFactory = Process::EffectProcessFactory_T<TexgenModel>;
104 using TexgenLayerFactory = Process::EffectLayerFactory_T<
105  TexgenModel, Process::DefaultEffectItem,
107  TexgenModel, TexgenModel::p_script, TexgenLanguageSpec>>;
108 
109 class TexgenExecutor final
110  : public Execution::ProcessComponent_T<Jit::TexgenModel, ossia::node_process>
111 {
112  COMPONENT_METADATA("ec4bd3af-8d81-4d92-9b53-86a34d8108f8")
113 
114 public:
115  static constexpr bool is_unique = true;
116 
117  TexgenExecutor(Jit::TexgenModel& proc, const Execution::Context& ctx, QObject* parent);
118  ~TexgenExecutor() override;
119 };
120 using TexgenExecutorFactory = Execution::ProcessComponentFactory_T<TexgenExecutor>;
121 }
122 
123 namespace Jit
124 {
125 class EditTexgen : public Scenario::EditScript<TexgenModel, TexgenModel::p_script>
126 {
127  SCORE_COMMAND_DECL(CommandFactoryName(), EditTexgen, "Edit a texture script")
128 public:
129  using Scenario::EditScript<TexgenModel, TexgenModel::p_script>::EditScript;
130 };
131 
132 }
133 
134 namespace score
135 {
136 template <>
137 struct StaticPropertyCommand<Jit::TexgenModel::p_script> : Jit::EditTexgen
138 {
139  using Jit::EditTexgen::EditTexgen;
140 };
141 }
142 
143 #endif
Definition: DataStreamVisitor.hpp:202
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
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
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: Process/Execution/ProcessComponent.hpp:89
Definition: ScriptProcess.hpp:14
Definition: TimeValue.hpp:21