Bytebeat.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 <verdigris>
19 
20 namespace Jit
21 {
22 class BytebeatModel;
23 }
24 PROCESS_METADATA(
25  , Jit::BytebeatModel, "608beeb7-e5c2-40a5-bd1a-aa7aec80f864", "Jit", "Bytebeat",
26  Process::ProcessCategory::Script, "Audio/Generators", "Run bytebeat code",
27  "ossia score", QStringList{}, {}, {}, Process::ProcessFlags::SupportsAll)
28 namespace Jit
29 {
30 struct Driver;
31 using BytebeatFunction = void(double* input, int size, int time);
32 using BytebeatCompiler = Driver;
33 using BytebeatFactory = std::function<BytebeatFunction>;
34 class BytebeatModel : public Process::ProcessModel
35 {
36  friend class JitUI;
37  friend class JitUpdateUI;
38  SCORE_SERIALIZE_FRIENDS
39  PROCESS_METADATA_IMPL(BytebeatModel)
40 
41  W_OBJECT(BytebeatModel)
42 public:
43  BytebeatModel(
44  TimeVal t, const QString& jitProgram, const Id<Process::ProcessModel>&,
45  QObject* parent);
46  ~BytebeatModel() override;
47 
48  BytebeatModel(DataStream::Deserializer& vis, QObject* parent);
49  BytebeatModel(JSONObject::Deserializer& vis, QObject* parent);
50  BytebeatModel(DataStream::Deserializer&& vis, QObject* parent);
51  BytebeatModel(JSONObject::Deserializer&& vis, QObject* parent);
52 
53  const QString& script() const noexcept { return m_text; }
54  [[nodiscard]] Process::ScriptChangeResult setScript(const QString& txt);
55  void scriptChanged(const QString& txt) W_SIGNAL(scriptChanged, txt);
56 
57  static constexpr bool hasExternalUI() noexcept { return true; }
58 
59  bool validate(const QString& txt) const noexcept;
60 
61  QString prettyName() const noexcept override;
62  void programChanged() W_SIGNAL(programChanged);
63 
64  BytebeatFactory factory;
65 
66  void errorMessage(int line, const QString& e) W_SIGNAL(errorMessage, line, e);
67 
68  PROPERTY(QString, script READ script WRITE setScript NOTIFY scriptChanged)
69 private:
70  QString effect() const noexcept override;
71  void loadPreset(const Process::Preset& preset) override;
72  Process::Preset savePreset() const noexcept override;
73  void init();
74  [[nodiscard]] Process::ScriptChangeResult reload();
75  QString m_text;
76  std::unique_ptr<BytebeatCompiler> m_compiler;
77 };
78 }
79 
80 namespace Process
81 {
82 template <>
83 QString
84 EffectProcessFactory_T<Jit::BytebeatModel>::customConstructionData() const noexcept;
85 
86 template <>
87 Process::Descriptor
88 EffectProcessFactory_T<Jit::BytebeatModel>::descriptor(QString d) const noexcept;
89 }
90 class QPlainTextEdit;
91 namespace Jit
92 {
93 
95 {
96  static constexpr const char* language = "C++";
97 };
98 
101  BytebeatModel, Process::DefaultEffectItem,
103  BytebeatModel, BytebeatModel::p_script, BytebeatLanguageSpec>>;
104 
105 class BytebeatExecutor final
106  : public Execution::ProcessComponent_T<Jit::BytebeatModel, ossia::node_process>
107 {
108  COMPONENT_METADATA("dc4f88ae-ca36-4330-b0e7-8093a1793521")
109 
110 public:
111  static constexpr bool is_unique = true;
112 
114  Jit::BytebeatModel& proc, const Execution::Context& ctx, QObject* parent);
115  ~BytebeatExecutor() override;
116 };
118 }
119 
120 namespace Jit
121 {
122 class EditBytebeat : public Scenario::EditScript<BytebeatModel, BytebeatModel::p_script>
123 {
124  SCORE_COMMAND_DECL(CommandFactoryName(), EditBytebeat, "Edit a bytebeat")
125 public:
127 };
128 
129 }
130 
131 namespace score
132 {
133 template <>
134 struct StaticPropertyCommand<Jit::BytebeatModel::p_script> : Jit::EditBytebeat
135 {
136  using Jit::EditBytebeat::EditBytebeat;
137 };
138 }
Definition: DataStreamVisitor.hpp:202
Definition: Process/Execution/ProcessComponent.hpp:119
Definition: JSONVisitor.hpp:423
Definition: Bytebeat.hpp:107
Definition: Bytebeat.hpp:123
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:23
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:75
Definition: Process/Execution/ProcessComponent.hpp:89
Definition: Bytebeat.hpp:95
Definition: ScriptProcess.hpp:14
Definition: TimeValue.hpp:21
Definition: PropertyCommand.hpp:112