Loading...
Searching...
No Matches
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 <Bytebeat/BytebeatCodegen.hpp>
15
16#include <ossia/dataflow/execution_state.hpp>
17#include <ossia/dataflow/graph_node.hpp>
18#include <ossia/dataflow/node_process.hpp>
19
20#include <verdigris>
21
22namespace Jit
23{
24class BytebeatModel;
25}
26PROCESS_METADATA(
27 , Jit::BytebeatModel, "608beeb7-e5c2-40a5-bd1a-aa7aec80f864", "Jit", "Bytebeat",
28 Process::ProcessCategory::Script, "Audio/Generators", "Run bytebeat code",
29 "ossia score", QStringList{}, {}, {}, QUrl("https://ossia.io/score-docs/processes/bytebeat.html#what-is-bytebeat"), Process::ProcessFlags::SupportsAll | Process::ProcessFlags::ScriptEditingSupported)
30namespace Jit
31{
32struct Driver;
33using BytebeatCompiler = Driver;
34
35// A compiled formula; the compiler owns the code the function points into.
36struct BytebeatProgram
37{
38 std::shared_ptr<BytebeatCompiler> compiler;
39 Bytebeat::Function* function{};
40 int state_size{};
41};
42class SCORE_PLUGIN_JIT_TEST_EXPORT BytebeatModel : public Process::ProcessModel
43{
44 friend class JitUI;
45 friend class JitUpdateUI;
46 SCORE_SERIALIZE_FRIENDS
47 PROCESS_METADATA_IMPL(BytebeatModel)
48
49 W_OBJECT(BytebeatModel)
50public:
51 BytebeatModel(
52 TimeVal t, const QString& jitProgram, const Id<Process::ProcessModel>&,
53 QObject* parent);
54 ~BytebeatModel() override;
55
56 BytebeatModel(DataStream::Deserializer& vis, QObject* parent);
57 BytebeatModel(JSONObject::Deserializer& vis, QObject* parent);
58 BytebeatModel(DataStream::Deserializer&& vis, QObject* parent);
59 BytebeatModel(JSONObject::Deserializer&& vis, QObject* parent);
60
61 const QString& script() const noexcept { return m_text; }
62 [[nodiscard]] Process::ScriptChangeResult setScript(const QString& txt);
63 void scriptChanged(const QString& txt) E_SIGNAL(SCORE_PLUGIN_JIT_TEST_EXPORT, scriptChanged, txt);
64
65 bool validate(const QString& txt) const noexcept;
66
67 // Inlets: language, output mode, rate
68 Bytebeat::Language language() const noexcept;
69 Bytebeat::OutputMode outputMode() const noexcept;
70 int rate() const noexcept;
71
72 QString prettyName() const noexcept override;
73 void programChanged() E_SIGNAL(SCORE_PLUGIN_JIT_TEST_EXPORT, programChanged);
74
75 std::shared_ptr<const BytebeatProgram> program;
76
77 void errorMessage(int line, const QString& e) E_SIGNAL(SCORE_PLUGIN_JIT_TEST_EXPORT, errorMessage, line, e);
78
79 PROPERTY(QString, script READ script WRITE setScript NOTIFY scriptChanged)
80private:
81 QString effect() const noexcept override;
82 void loadPreset(const Process::Preset& preset) override;
83 Process::Preset savePreset() const noexcept override;
84 void init();
85 void finishLoad();
86 [[nodiscard]] Process::ScriptChangeResult reload();
87 QString m_text;
88 bool m_loadingPreset{};
89};
90}
91
92namespace Process
93{
94template <>
95QString
96EffectProcessFactory_T<Jit::BytebeatModel>::customConstructionData() const noexcept;
97
98template <>
99Process::Descriptor
100EffectProcessFactory_T<Jit::BytebeatModel>::descriptor(QString d) const noexcept;
101
102template <>
103Process::Descriptor EffectProcessFactory_T<Jit::BytebeatModel>::descriptor(
104 const Process::ProcessModel& d) const noexcept;
105}
106class QPlainTextEdit;
107namespace Jit
108{
109
111{
112 static constexpr const char* language = "C++";
113};
114
118 BytebeatModel, BytebeatModel::p_script, BytebeatLanguageSpec>>;
119
121 : public Execution::ProcessComponent_T<Jit::BytebeatModel, ossia::node_process>
122{
123 COMPONENT_METADATA("dc4f88ae-ca36-4330-b0e7-8093a1793521")
124
125public:
126 static constexpr bool is_unique = true;
127
129 Jit::BytebeatModel& proc, const Execution::Context& ctx, QObject* parent);
130 ~BytebeatExecutor() override;
131};
133}
134
135namespace Jit
136{
137class EditBytebeat : public Scenario::EditScript<BytebeatModel, BytebeatModel::p_script>
138{
139 SCORE_COMMAND_DECL(CommandFactoryName(), EditBytebeat, "Edit a bytebeat")
140public:
141 using Scenario::EditScript<BytebeatModel, BytebeatModel::p_script>::EditScript;
142};
143
144}
145
146namespace score
147{
148template <>
149struct StaticPropertyCommand<Jit::BytebeatModel::p_script> : Jit::EditBytebeat
150{
151 using Jit::EditBytebeat::EditBytebeat;
152};
153}
Definition DataStreamVisitor.hpp:202
Definition Process/Execution/ProcessComponent.hpp:131
Definition JSONVisitor.hpp:423
Definition Bytebeat.hpp:122
Definition Bytebeat.hpp:138
Definition EffectFactory.hpp:86
Definition EffectFactory.hpp:14
The Process class.
Definition score-lib-process/Process/Process.hpp:82
Definition ScriptEditor.hpp:54
Definition ScriptEditCommand.hpp:16
The id_base_t class.
Definition Identifier.hpp:59
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
@ ScriptEditingSupported
The process is based on user-editable source code (JS, Faust, etc.)
Definition ProcessFlags.hpp:70
Base toolkit upon which the software is built.
Definition Application.cpp:83
STL namespace.
Definition ExecutionContext.hpp:208
Definition Process/Execution/ProcessComponent.hpp:101
Definition Bytebeat.hpp:111
Definition ScriptProcess.hpp:14
Definition TimeValue.hpp:21
Definition PropertyCommand.hpp:112