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-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "plugins/plugin_protocol.h"
7#include "utils/icloneable.h"
8#include "utils/utf8_string.h"
9
10#include <QObject>
11
12#include <boost/describe.hpp>
13#include <nlohmann/json_fwd.hpp>
14
20
21namespace zrythm::plugins
22{
23
27enum class PluginCategory : std::uint8_t
28{
30 None,
31 Delay,
32 REVERB,
33 DISTORTION,
34 WAVESHAPER,
35 DYNAMICS,
36 AMPLIFIER,
37 COMPRESSOR,
38 ENVELOPE,
39 EXPANDER,
40 GATE,
41 LIMITER,
42 FILTER,
43 ALLPASS_FILTER,
44 BANDPASS_FILTER,
45 COMB_FILTER,
46 EQ,
47 MULTI_EQ,
48 PARA_EQ,
49 HIGHPASS_FILTER,
50 LOWPASS_FILTER,
51 GENERATOR,
52 CONSTANT,
53 Instrument,
54 OSCILLATOR,
55 MIDI,
56 MODULATOR,
57 CHORUS,
58 FLANGER,
59 PHASER,
60 SIMULATOR,
61 SIMULATOR_REVERB,
62 SPATIAL,
63 SPECTRAL,
64 PITCH,
65 UTILITY,
66 ANALYZER,
67 CONVERTER,
68 FUNCTION,
69 MIXER,
70};
71
75enum class PluginArchitecture : std::uint8_t
76{
77 ARCH_32_BIT,
78 ARCH_64_BIT
79};
80
84enum class BridgeMode : std::uint8_t
85{
86 None,
87 UI,
88 Full,
89};
90
110class PluginDescriptor : public QObject
111{
112 Q_OBJECT
113 QML_ELEMENT
114 Q_PROPERTY (QString name READ name CONSTANT FINAL)
115 Q_PROPERTY (QString vendor READ vendor CONSTANT FINAL)
116 Q_PROPERTY (QString format READ format CONSTANT FINAL)
117 Q_PROPERTY (QString category READ category CONSTANT FINAL)
118 QML_UNCREATABLE ("")
119
120public:
121 static std::unique_ptr<PluginDescriptor>
122 from_juce_description (const juce::PluginDescription &juce_desc);
123
124 std::unique_ptr<juce::PluginDescription> to_juce_description () const;
125
126 static PluginCategory string_to_category (const utils::Utf8String &str);
127 static utils::Utf8String category_to_string (PluginCategory category);
128
129 // =========================================================
130 // QML interface
131 // =========================================================
132
133 [[nodiscard]] QString name () const { return name_.to_qstring (); }
134 QString format () const;
135 QString vendor () const;
136 QString category () const;
137
143 Q_INVOKABLE QString serializeToString () const;
144
145 Q_INVOKABLE bool isInstrument () const;
146 Q_INVOKABLE bool isEffect () const;
147 Q_INVOKABLE bool isModulator () const;
148 Q_INVOKABLE bool isMidiModifier () const;
149
150 // =========================================================
151
156 bool is_same_plugin (const PluginDescriptor &other) const;
157
161 bool has_custom_ui () const;
162
166 BridgeMode get_min_bridge_mode () const;
167
172
173 // GMenuModel * generate_context_menu () const;
174
175 friend void init_from (
176 PluginDescriptor &obj,
177 const PluginDescriptor &other,
178 utils::ObjectCloneType clone_type);
179
180private:
181 static constexpr auto kAuthorKey = "author"sv;
182 static constexpr auto kNameKey = "name"sv;
183 static constexpr auto kWebsiteKey = "website"sv;
184 static constexpr auto kCategoryKey = "category"sv;
185 static constexpr auto kCategoryStringKey = "categoryString"sv;
186 static constexpr auto kNumAudioInsKey = "numAudioIns"sv;
187 static constexpr auto kNumAudioOutsKey = "numAudioOuts"sv;
188 static constexpr auto kNumMidiInsKey = "numMidiIns"sv;
189 static constexpr auto kNumMidiOutsKey = "numMidiOuts"sv;
190 static constexpr auto kNumCtrlInsKey = "numCtrlIns"sv;
191 static constexpr auto kNumCtrlOutsKey = "numCtrlOuts"sv;
192 static constexpr auto kNumCvInsKey = "numCvIns"sv;
193 static constexpr auto kNumCvOutsKey = "numCvOuts"sv;
194 static constexpr auto kUniqueIdKey = "uniqueId"sv;
195 static constexpr auto kDeprecatedUniqueIdKey = "deprecatedUniqueId"sv;
196 static constexpr auto kArchitectureKey = "architecture"sv;
197 static constexpr auto kProtocolKey = "protocol"sv;
198 static constexpr auto kPathOrIdKey = "pathOrId"sv;
199 static constexpr auto kMinBridgeModeKey = "minBridgeMode"sv;
200 static constexpr auto kHasCustomUIKey = "hasCustomUI"sv;
201 friend void to_json (nlohmann::json &j, const PluginDescriptor &p);
202 friend void from_json (const nlohmann::json &j, PluginDescriptor &p);
203
204 friend bool operator== (const PluginDescriptor &a, const PluginDescriptor &b)
205 {
206 constexpr auto tie = [] (const auto &p) {
207 return std::tie (
208 p.arch_, p.protocol_, p.path_or_id_, p.unique_id_,
209 p.juce_compat_deprecated_unique_id_, p.min_bridge_mode_,
210 p.has_custom_ui_);
211 };
212 return tie (a) == tie (b);
213 }
214
215public:
216 utils::Utf8String author_;
217 utils::Utf8String name_;
218 utils::Utf8String website_;
219 PluginCategory category_ = PluginCategory::None;
235 int num_cv_ins_ = 0;
239 PluginArchitecture arch_ = PluginArchitecture::ARCH_64_BIT;
242
247 std::variant<fs::path, utils::Utf8String> path_or_id_;
248
250 int64_t unique_id_{};
251
254
256 BridgeMode min_bridge_mode_ = BridgeMode::None;
257
258 bool has_custom_ui_{};
259
260 BOOST_DESCRIBE_CLASS (
262 (),
263 (author_,
264 name_,
265 website_,
266 category_,
268 protocol_,
274 arch_,
276 has_custom_ui_),
277 (),
278 ())
279};
280
281} // namespace zrythm::plugins
282
283namespace std
284{
285template <> struct hash<zrythm::plugins::PluginDescriptor>
286{
287 size_t operator() (const zrythm::plugins::PluginDescriptor &d) const
288 {
289 size_t h{};
290 h = h ^ qHash (d.protocol_);
291 h = h ^ qHash (d.arch_);
292 if (std::holds_alternative<fs::path> (d.path_or_id_))
293 {
294 h = h ^ qHash (std::get<fs::path> (d.path_or_id_).string ());
295 }
296 else
297 {
298 h =
299 h ^ qHash (std::get<zrythm::utils::Utf8String> (d.path_or_id_).str ());
300 }
301 h = h ^ qHash (d.unique_id_);
302 h = h ^ qHash (d.juce_compat_deprecated_unique_id_);
303 return h;
304 }
305};
306}
307
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.
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.
std::variant< fs::path, utils::Utf8String > path_or_id_
Identifier, for plugin formats that use unique identifiers, or path otherwise.
@ Internal
Dummy protocol for tests.
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38