score-plugin-faust/Faust/EffectModel.hpp
1 #pragma once
2 #include <Process/Execution/ProcessComponent.hpp>
3 #include <Process/GenericProcessFactory.hpp>
4 #include <Process/Inspector/ProcessInspectorWidgetDelegate.hpp>
5 #include <Process/Inspector/ProcessInspectorWidgetDelegateFactory.hpp>
6 #include <Process/Process.hpp>
7 #include <Process/Script/ScriptEditor.hpp>
8 #include <Process/Script/ScriptProcess.hpp>
9 
10 #include <Control/DefaultEffectItem.hpp>
11 #include <Effect/EffectFactory.hpp>
12 
13 #include <ossia/dataflow/node_process.hpp>
14 
15 #include <QDialog>
16 
17 #include <iostream> // needed by poly-llvm-dsp.h...
18 #include <verdigris>
19 
20 #include <faust/dsp/poly-llvm-dsp.h>
21 namespace Faust
22 {
23 class FaustEffectModel;
24 }
25 
26 namespace ossia::nodes
27 {
28 struct custom_dsp_poly_factory;
29 class custom_dsp_poly_effect;
30 }
31 
32 PROCESS_METADATA(
33  , Faust::FaustEffectModel, "5354c61a-1649-4f59-b952-5c2f1b79c1bd", "Faust", "Faust",
34  Process::ProcessCategory::Script, "Plugins",
35  "Faust process. Refer to https://faust.grame.fr", "GRAME and the Faust team",
36  {"Script"}, {}, {}, QUrl("https://ossia.io/score-docs/processes/faust.html"), Process::ProcessFlags::ExternalEffect)
37 DESCRIPTION_METADATA(, Faust::FaustEffectModel, "Faust")
38 namespace Faust
39 {
40 class FaustEffectModel : public Process::ProcessModel
41 {
42  friend class FaustUI;
43  friend class FaustUpdateUI;
44  W_OBJECT(FaustEffectModel)
45  SCORE_SERIALIZE_FRIENDS
46  PROCESS_METADATA_IMPL(FaustEffectModel)
47 
48 public:
49  static constexpr bool hasExternalUI() noexcept { return true; }
50 
51  FaustEffectModel(
52  TimeVal t, const QString& faustProgram, const Id<Process::ProcessModel>&,
53  QObject* parent);
54  ~FaustEffectModel();
55 
56  template <typename Impl>
57  FaustEffectModel(Impl& vis, QObject* parent)
58  : Process::ProcessModel{vis, parent}
59  {
60  vis.writeTo(*this);
61  init();
62  }
63 
64  QString prettyName() const noexcept override;
65 
66  bool validate(const QString& txt) const noexcept;
67  const QString& script() const { return m_script; }
68  [[nodiscard]] Process::ScriptChangeResult setScript(const QString& txt);
69 
70  Process::Inlets& inlets() noexcept { return m_inlets; }
71  Process::Outlets& outlets() noexcept { return m_outlets; }
72  const Process::Inlets& inlets() const noexcept { return m_inlets; }
73  const Process::Outlets& outlets() const noexcept { return m_outlets; }
74 
75  std::shared_ptr<llvm_dsp_factory> faust_factory{};
76  std::shared_ptr<llvm_dsp> faust_object{};
77 
78  std::shared_ptr<ossia::nodes::custom_dsp_poly_factory> faust_poly_factory{};
79  std::shared_ptr<ossia::nodes::custom_dsp_poly_effect> faust_poly_object{};
80 
81  void scriptChanged(const QString& str) W_SIGNAL(scriptChanged, str);
82  void programChanged() W_SIGNAL(programChanged);
83 
84  void errorMessage(int line, const QString& e) W_SIGNAL(errorMessage, line, e);
85 
86  PROPERTY(QString, script READ script WRITE setScript NOTIFY scriptChanged)
87 private:
88  QString effect() const noexcept override;
89  void loadPreset(const Process::Preset& preset) override;
90  Process::Preset savePreset() const noexcept override;
91 
92  void init();
93  [[nodiscard]] Process::ScriptChangeResult reload();
94 
95  QString m_script;
96  QString m_path;
97  QString m_declareName;
98 };
99 }
100 
101 namespace Process
102 {
103 template <>
104 QString
105 EffectProcessFactory_T<Faust::FaustEffectModel>::customConstructionData() const noexcept;
106 
107 template <>
108 Process::Descriptor
109 EffectProcessFactory_T<Faust::FaustEffectModel>::descriptor(QString d) const noexcept;
110 }
111 
112 namespace Faust
113 {
115 {
116  static constexpr const char* language = "Faust";
117 };
118 
121  FaustEffectModel, Process::DefaultEffectItem,
123  FaustEffectModel, FaustEffectModel::p_script, LanguageSpec>>;
124 }
125 
126 namespace Execution
127 {
129  : public Execution::ProcessComponent_T<Faust::FaustEffectModel, ossia::node_process>
130 {
131  W_OBJECT(FaustEffectComponent)
132  COMPONENT_METADATA("eb4f83af-5ddc-4f2f-9426-6f8a599a1e96")
133 
134 public:
135  static constexpr bool is_unique = true;
136 
138  Faust::FaustEffectModel& proc, const Execution::Context& ctx, QObject* parent);
139 
140 private:
141  void reload(Execution::Transaction&);
142  void reloadSynth(Execution::Transaction&);
143  void reloadFx(Execution::Transaction&);
144 
145  template <typename Node_T>
146  void setupExecutionControls(const Node_T&, int firstControlIndex);
147  template <typename Node_T>
148  void setupExecutionControlOutlets(const Node_T&, int firstControlIndex);
149 
150  std::vector<QMetaObject::Connection> m_controlConnections;
151 };
154 }
Definition: score-plugin-faust/Faust/EffectModel.hpp:130
Definition: Process/Execution/ProcessComponent.hpp:119
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
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
Definition: ExecutionContext.hpp:76
Definition: Process/Execution/ProcessComponent.hpp:89
Definition: ExecutionTransaction.hpp:18
Definition: score-plugin-faust/Faust/EffectModel.hpp:115
Definition: PortForward.hpp:23
Definition: PortForward.hpp:27
Definition: ScriptProcess.hpp:14
Definition: TimeValue.hpp:21