score-plugin-lv2/LV2/EffectModel.hpp
1 #pragma once
2 #include <Process/Execution/ProcessComponent.hpp>
3 #include <Process/GenericProcessFactory.hpp>
4 #include <Process/Process.hpp>
5 
6 #include <Control/DefaultEffectItem.hpp>
7 #include <Effect/EffectFactory.hpp>
8 #include <LV2/Context.hpp>
9 
10 #include <ossia/dataflow/node_process.hpp>
11 
12 #include <lilv/lilvmm.hpp>
13 
14 #include <verdigris>
15 
16 namespace LV2
17 {
18 class Model;
19 }
20 PROCESS_METADATA(
21  , LV2::Model, "fd5243ba-70b5-4164-b44a-ecb0dcdc0494", "LV2", "LV2",
22  Process::ProcessCategory::Other, "Plugins", "LV2 plug-in", "ossia score", {}, {}, {},
23  Process::ProcessFlags::ExternalEffect)
24 DESCRIPTION_METADATA(, LV2::Model, "LV2")
25 namespace LV2
26 {
27 class Model : public Process::ProcessModel
28 {
29  W_OBJECT(Model)
30  SCORE_SERIALIZE_FRIENDS
31 public:
32  PROCESS_METADATA_IMPL(Model)
33  Model(
34  TimeVal t, const QString& name, const Id<Process::ProcessModel>&, QObject* parent);
35 
36  ~Model() override;
37  template <typename Impl>
38  Model(Impl& vis, QObject* parent)
39  : ProcessModel{vis, parent}
40  {
41  vis.writeTo(*this);
42  }
43 
44  QString effect() const noexcept override { return m_effectPath; }
45 
46  void setEffect(const QString& s) { m_effectPath = s; }
47 
48  QString prettyName() const noexcept override;
49 
50  bool hasExternalUI() const noexcept;
51 
52  const LilvPlugin* plugin{};
53  mutable LV2::EffectContext effectContext;
54  LV2::HostContext* hostContext{};
55 
56  std::size_t m_controlInStart{};
57  std::size_t m_controlOutStart{};
58  mutable moodycamel::ReaderWriterQueue<Message> ui_events; // from ui to score
59  mutable moodycamel::ReaderWriterQueue<Message> plugin_events; // from plug-in
60  mutable moodycamel::ReaderWriterQueue<Message>
61  to_process_events; // from score to process
62 
63  ossia::hash_map<uint32_t, std::pair<Process::ControlInlet*, bool>> control_map;
64  ossia::hash_map<uint32_t, Process::ControlOutlet*> control_out_map;
65 
66 private:
67  void reload();
68  QString m_effectPath;
69  void readPlugin();
70 
71  ossia::float_vector fInControls, fOutControls;
72 };
73 
74 class LV2EffectComponent final
75  : public Execution::ProcessComponent_T<LV2::Model, ossia::node_process>
76 {
77  W_OBJECT(LV2EffectComponent)
78  COMPONENT_METADATA("57f50003-a179-424a-80b1-b9394d73a84a")
79 
80 public:
81  static constexpr bool is_unique = true;
82 
83  LV2EffectComponent(LV2::Model& proc, const Execution::Context& ctx, QObject* parent);
84 
85  void lazy_init() override;
86 
87  void
88  writeAtomToUi(uint32_t port_index, uint32_t type, uint32_t size, const void* body);
89  void writeAtomToUi(uint32_t port_index, LV2_Atom& atom);
90 };
91 }
92 
93 namespace Process
94 {
95 template <>
96 QString EffectProcessFactory_T<LV2::Model>::customConstructionData() const noexcept;
97 }
98 
99 namespace LV2
100 {
101 using ProcessFactory = Process::EffectProcessFactory_T<Model>;
103 }
Definition: Process/Execution/ProcessComponent.hpp:119
Definition: EffectFactory.hpp:14
The Process class.
Definition: score-lib-process/Process/Process.hpp:61
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: Process/Execution/ProcessComponent.hpp:89
Definition: Context.hpp:135
Definition: Context.hpp:49
Definition: TimeValue.hpp:21