Loading...
Searching...
No Matches
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#include <Process/Preset.hpp>
10
11#include <ossia/dataflow/node_process.hpp>
12
13#include <QTimer>
14
15#include <lilv/lilvmm.hpp>
16
17#include <score_plugin_lv2_export.h>
18
19#include <optional>
20
21#include <verdigris>
22
23namespace LV2
24{
25class Model;
26// Call after a rescan: LilvPlugin* values may dangle if lilv rebuilt its index
27SCORE_PLUGIN_LV2_EXPORT void clearPluginCache();
28
29// Resolve a plug-in URI, bundle path or (legacy) display name against the
30// loaded world, loading its bundle on demand. Main thread only.
31// (get_lv2_plugin_name is declared in LV2/Context.hpp.)
32SCORE_PLUGIN_LV2_EXPORT std::optional<Lilv::Plugin>
33find_lv2_plugin(Lilv::World& world, QString path);
34}
35PROCESS_METADATA(
36 , LV2::Model, "fd5243ba-70b5-4164-b44a-ecb0dcdc0494", "LV2", "LV2",
37 Process::ProcessCategory::Other, "Plugins", "LV2 plug-in", "ossia score", {}, {}, {},
38 QUrl("https://ossia.io/score-docs/processes/audio-plugins.html#common-formats-vst-vst3-lv2-jsfx"),
39 Process::ProcessFlags::ExternalEffect)
40DESCRIPTION_METADATA(, LV2::Model, "LV2")
41namespace LV2
42{
43class SCORE_PLUGIN_LV2_EXPORT Model : public Process::ProcessModel
44{
45 W_OBJECT(Model)
46 SCORE_SERIALIZE_FRIENDS
47public:
48 PROCESS_METADATA_IMPL(Model)
49 Model(
50 TimeVal t, const QString& name, const Id<Process::ProcessModel>&, QObject* parent);
51
52 ~Model() override;
53 template <typename Impl>
54 Model(Impl& vis, QObject* parent)
55 : ProcessModel{vis, parent}
56 {
57 vis.writeTo(*this);
58 }
59
60 QString effect() const noexcept override { return m_effectPath; }
61
62 void setEffect(const QString& s) { m_effectPath = s; }
63
64 QString prettyName() const noexcept override;
65
66 bool hasExternalUI() const noexcept;
67
68 void loadPreset(const Process::Preset& preset) override;
69 Process::Preset savePreset() const noexcept override;
70 std::vector<Process::Preset> builtinPresets() const noexcept override;
71
72 const LilvPlugin* plugin{};
73 mutable LV2::EffectContext effectContext;
74 LV2::HostContext* hostContext{};
75
76 std::size_t m_controlInStart{};
77 std::size_t m_controlOutStart{};
78 mutable moodycamel::ReaderWriterQueue<Message> ui_events; // from ui to score
79 mutable moodycamel::ReaderWriterQueue<Message> plugin_events; // from plug-in
80 mutable moodycamel::ReaderWriterQueue<Message>
81 to_process_events; // from score to process
82
83 ossia::hash_map<uint32_t, std::pair<Process::ControlInlet*, bool>> control_map;
84 ossia::hash_map<uint32_t, Process::ControlOutlet*> control_out_map;
85
86private:
87 void reload();
88 QString m_effectPath;
89 void readPlugin();
90
91 ossia::float_vector fInControls, fOutControls;
92};
93
94class LV2EffectComponent final
95 : public Execution::ProcessComponent_T<LV2::Model, ossia::node_process>
96{
97 W_OBJECT(LV2EffectComponent)
98 COMPONENT_METADATA("57f50003-a179-424a-80b1-b9394d73a84a")
99
100public:
101 static constexpr bool is_unique = true;
102
103 LV2EffectComponent(LV2::Model& proc, const Execution::Context& ctx, QObject* parent);
104
105 void lazy_init() override;
106
107 void
108 writeAtomToUi(uint32_t port_index, uint32_t type, uint32_t size, const void* body);
109 void writeAtomToUi(uint32_t port_index, LV2_Atom& atom);
110
111private:
112 // per_channel voice-pool grower (main thread). Audio thread pushes high-water mark.
113 QTimer* m_grow_timer{};
114 int m_pool_sample_rate{};
115 std::size_t m_pool_pushed{};
116 std::size_t m_pool_max_requested{};
117
118 void growVoicePoolTick();
119};
120}
121
122namespace Process
123{
124template <>
125QString EffectProcessFactory_T<LV2::Model>::customConstructionData() const noexcept;
126}
127
128namespace LV2
129{
130using ProcessFactory = Process::EffectProcessFactory_T<Model>;
132}
Definition Process/Execution/ProcessComponent.hpp:131
Definition EffectFactory.hpp:14
The Process class.
Definition score-lib-process/Process/Process.hpp:75
The id_base_t class.
Definition Identifier.hpp:59
Components used for the execution of a score.
Definition ProcessComponent.cpp:14
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
STL namespace.
Definition Process/Execution/ProcessComponent.hpp:101
Definition Context.hpp:191
Definition Context.hpp:60
Definition TimeValue.hpp:21