Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
plugin_descriptor.h
1// SPDX-FileCopyrightText: © 2018-2021, 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <filesystem>
7
8#include "plugins/plugin_protocol.h"
9#include "utils/icloneable.h"
10#include "utils/utf8_string.h"
11
12#include <QObject>
13
14#include <boost/describe.hpp>
15#include <juce_audio_processors_headless/juce_audio_processors_headless.h>
16#include <nlohmann/json_fwd.hpp>
17
18namespace zrythm::plugins
19{
20using namespace std::string_view_literals;
21
25enum class PluginCategory : std::uint8_t
26{
28 None,
29 Delay,
30 REVERB,
31 DISTORTION,
32 WAVESHAPER,
33 DYNAMICS,
34 AMPLIFIER,
35 COMPRESSOR,
36 ENVELOPE,
37 EXPANDER,
38 GATE,
39 LIMITER,
40 FILTER,
41 ALLPASS_FILTER,
42 BANDPASS_FILTER,
43 COMB_FILTER,
44 EQ,
45 MULTI_EQ,
46 PARA_EQ,
47 HIGHPASS_FILTER,
48 LOWPASS_FILTER,
49 GENERATOR,
50 CONSTANT,
51 Instrument,
52 OSCILLATOR,
53 MIDI,
54 MODULATOR,
55 CHORUS,
56 FLANGER,
57 PHASER,
58 SIMULATOR,
59 SIMULATOR_REVERB,
60 SPATIAL,
61 SPECTRAL,
62 PITCH,
63 UTILITY,
64 ANALYZER,
65 CONVERTER,
66 FUNCTION,
67 MIXER,
68};
69
73enum class PluginArchitecture : std::uint8_t
74{
75 ARCH_32_BIT,
76 ARCH_64_BIT
77};
78
82enum class BridgeMode : std::uint8_t
83{
84 None,
85 UI,
86 Full,
87};
88
108class PluginDescriptor : public QObject
109{
110 Q_OBJECT
111 QML_ELEMENT
112 Q_PROPERTY (QString name READ name CONSTANT FINAL)
113 Q_PROPERTY (QString vendor READ vendor CONSTANT FINAL)
114 Q_PROPERTY (QString format READ format CONSTANT FINAL)
115 Q_PROPERTY (QString category READ category CONSTANT FINAL)
116 QML_UNCREATABLE ("")
117
118public:
119 static std::unique_ptr<PluginDescriptor>
120 from_juce_description (const juce::PluginDescription &juce_desc);
121
122 std::unique_ptr<juce::PluginDescription> to_juce_description () const;
123
124 static PluginCategory string_to_category (const utils::Utf8String &str);
125 static utils::Utf8String category_to_string (PluginCategory category);
126
127 // =========================================================
128 // QML interface
129 // =========================================================
130
131 [[nodiscard]] QString name () const { return name_.to_qstring (); }
132 QString format () const;
133 QString vendor () const;
134 QString category () const;
135
141 Q_INVOKABLE QString serializeToString () const;
142
143 Q_INVOKABLE bool isInstrument () const;
144 Q_INVOKABLE bool isEffect () const;
145 Q_INVOKABLE bool isModulator () const;
146 Q_INVOKABLE bool isMidiModifier () const;
147
148 // =========================================================
149
154 bool is_same_plugin (const PluginDescriptor &other) const;
155
159 bool has_custom_ui () const;
160
164 BridgeMode get_min_bridge_mode () const;
165
170
171 // GMenuModel * generate_context_menu () const;
172
173 friend void init_from (
174 PluginDescriptor &obj,
175 const PluginDescriptor &other,
176 utils::ObjectCloneType clone_type);
177
178private:
179 static constexpr auto kAuthorKey = "author"sv;
180 static constexpr auto kNameKey = "name"sv;
181 static constexpr auto kWebsiteKey = "website"sv;
182 static constexpr auto kCategoryKey = "category"sv;
183 static constexpr auto kCategoryStringKey = "categoryString"sv;
184 static constexpr auto kNumAudioInsKey = "numAudioIns"sv;
185 static constexpr auto kNumAudioOutsKey = "numAudioOuts"sv;
186 static constexpr auto kNumMidiInsKey = "numMidiIns"sv;
187 static constexpr auto kNumMidiOutsKey = "numMidiOuts"sv;
188 static constexpr auto kNumCtrlInsKey = "numCtrlIns"sv;
189 static constexpr auto kNumCtrlOutsKey = "numCtrlOuts"sv;
190 static constexpr auto kNumCvInsKey = "numCvIns"sv;
191 static constexpr auto kNumCvOutsKey = "numCvOuts"sv;
192 static constexpr auto kUniqueIdKey = "uniqueId"sv;
193 static constexpr auto kDeprecatedUniqueIdKey = "deprecatedUniqueId"sv;
194 static constexpr auto kArchitectureKey = "architecture"sv;
195 static constexpr auto kProtocolKey = "protocol"sv;
196 static constexpr auto kPathOrIdKey = "pathOrId"sv;
197 static constexpr auto kMinBridgeModeKey = "minBridgeMode"sv;
198 static constexpr auto kHasCustomUIKey = "hasCustomUI"sv;
199 friend void to_json (nlohmann::json &j, const PluginDescriptor &p);
200 friend void from_json (const nlohmann::json &j, PluginDescriptor &p);
201
202 friend bool operator== (const PluginDescriptor &a, const PluginDescriptor &b)
203 {
204 constexpr auto tie = [] (const auto &p) {
205 return std::tie (
206 p.arch_, p.protocol_, p.path_or_id_, p.unique_id_,
207 p.juce_compat_deprecated_unique_id_, p.min_bridge_mode_,
208 p.has_custom_ui_);
209 };
210 return tie (a) == tie (b);
211 }
212
213public:
214 utils::Utf8String author_;
215 utils::Utf8String name_;
216 utils::Utf8String website_;
217 PluginCategory category_ = PluginCategory::None;
233 int num_cv_ins_ = 0;
237 PluginArchitecture arch_ = PluginArchitecture::ARCH_64_BIT;
240
245 std::variant<std::filesystem::path, utils::Utf8String> path_or_id_;
246
248 int64_t unique_id_{};
249
252
254 BridgeMode min_bridge_mode_ = BridgeMode::None;
255
256 bool has_custom_ui_{};
257
258 BOOST_DESCRIBE_CLASS (
260 (),
261 (author_,
262 name_,
263 website_,
264 category_,
266 protocol_,
272 arch_,
274 has_custom_ui_),
275 (),
276 ())
277};
278
279} // namespace zrythm::plugins
280
281namespace std
282{
283template <> struct hash<zrythm::plugins::PluginDescriptor>
284{
285 size_t operator() (const zrythm::plugins::PluginDescriptor &d) const
286 {
287 size_t h{};
288 h = h ^ qHash (d.protocol_);
289 h = h ^ qHash (d.arch_);
290 if (std::holds_alternative<std::filesystem::path> (d.path_or_id_))
291 {
292 h =
293 h ^ qHash (std::get<std::filesystem::path> (d.path_or_id_).string ());
294 }
295 else
296 {
297 h =
298 h ^ qHash (std::get<zrythm::utils::Utf8String> (d.path_or_id_).str ());
299 }
300 h = h ^ qHash (d.unique_id_);
301 h = h ^ qHash (d.juce_compat_deprecated_unique_id_);
302 return h;
303 }
304};
305}
The PluginDescriptor class provides a set of static utility functions and member functions to work wi...
int num_midi_ins_
Number of MIDI input ports.
int num_ctrl_outs_
Number of output control (plugin param) ports.
int juce_compat_deprecated_unique_id_
This is additionally needed by JUCE for some plugin formats.
Protocol::ProtocolType protocol_
Plugin protocol (Lv2/DSSI/LADSPA/VST/etc.).
int64_t unique_id_
Used by some plugin formats to uniquely identify the plugin.
bool has_custom_ui() const
Returns if the Plugin has a supported custom UI.
PluginArchitecture arch_
Architecture (32/64bit).
bool is_same_plugin(const PluginDescriptor &other) const
Returns whether the two descriptors describe the same plugin, ignoring irrelevant fields.
BridgeMode min_bridge_mode_
Minimum required bridge mode.
BridgeMode get_min_bridge_mode() const
Returns the minimum bridge mode required for this plugin.
int num_midi_outs_
Number of MIDI output ports.
int num_audio_ins_
Number of audio input ports.
int num_ctrl_ins_
Number of input control (plugin param) ports.
int num_cv_outs_
Number of output CV ports.
std::variant< std::filesystem::path, utils::Utf8String > path_or_id_
Identifier, for plugin formats that use unique identifiers, or path otherwise.
Q_INVOKABLE QString serializeToString() const
Serializes the descriptor to a string.
int num_audio_outs_
Number of audio output ports.
int num_cv_ins_
Number of input CV ports.
utils::Utf8String category_str_
Lv2 plugin subcategory.
utils::Utf8String get_icon_name() const
Gets an appropriate icon name.
@ Internal
Dummy protocol for tests.
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:37