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  QUrl("https://ossia.io/score-docs/processes/audio-plugins.html#common-formats-vst-vst3-lv2-jsfx"),
24  Process::ProcessFlags::ExternalEffect)
25 DESCRIPTION_METADATA(, LV2::Model, "LV2")
26 namespace LV2
27 {
28 class Model : public Process::ProcessModel
29 {
30  W_OBJECT(Model)
31  SCORE_SERIALIZE_FRIENDS
32 public:
33  PROCESS_METADATA_IMPL(Model)
34  Model(
35  TimeVal t, const QString& name, const Id<Process::ProcessModel>&, QObject* parent);
36 
37  ~Model() override;
38  template <typename Impl>
39  Model(Impl& vis, QObject* parent)
40  : ProcessModel{vis, parent}
41  {
42  vis.writeTo(*this);
43  }
44 
45  QString effect() const noexcept override { return m_effectPath; }
46 
47  void setEffect(const QString& s) { m_effectPath = s; }
48 
49  QString prettyName() const noexcept override;
50 
51  bool hasExternalUI() const noexcept;
52 
53  const LilvPlugin* plugin{};
54  mutable LV2::EffectContext effectContext;
55  LV2::HostContext* hostContext{};
56 
57  std::size_t m_controlInStart{};
58  std::size_t m_controlOutStart{};
59  mutable moodycamel::ReaderWriterQueue<Message> ui_events; // from ui to score
60  mutable moodycamel::ReaderWriterQueue<Message> plugin_events; // from plug-in
61  mutable moodycamel::ReaderWriterQueue<Message>
62  to_process_events; // from score to process
63 
64  ossia::hash_map<uint32_t, std::pair<Process::ControlInlet*, bool>> control_map;
65  ossia::hash_map<uint32_t, Process::ControlOutlet*> control_out_map;
66 
67 private:
68  void reload();
69  QString m_effectPath;
70  void readPlugin();
71 
72  ossia::float_vector fInControls, fOutControls;
73 };
74 
75 class LV2EffectComponent final
76  : public Execution::ProcessComponent_T<LV2::Model, ossia::node_process>
77 {
78  W_OBJECT(LV2EffectComponent)
79  COMPONENT_METADATA("57f50003-a179-424a-80b1-b9394d73a84a")
80 
81 public:
82  static constexpr bool is_unique = true;
83 
84  LV2EffectComponent(LV2::Model& proc, const Execution::Context& ctx, QObject* parent);
85 
86  void lazy_init() override;
87 
88  void
89  writeAtomToUi(uint32_t port_index, uint32_t type, uint32_t size, const void* body);
90  void writeAtomToUi(uint32_t port_index, LV2_Atom& atom);
91 };
92 }
93 
94 namespace Process
95 {
96 template <>
97 QString EffectProcessFactory_T<LV2::Model>::customConstructionData() const noexcept;
98 }
99 
100 namespace LV2
101 {
102 using ProcessFactory = Process::EffectProcessFactory_T<Model>;
104 }
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