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 "zrythm-config.h"
7
8#include "plugins/plugin_protocol.h"
9#include "utils/icloneable.h"
10
11#include <QObject>
12
13#include <boost/describe.hpp>
14
20
21namespace zrythm::plugins
22{
23
27enum class PluginCategory : std::uint_fast8_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::uint_fast8_t
76{
77 ARCH_32_BIT,
78 ARCH_64_BIT
79};
80
84enum class BridgeMode : std::uint_fast8_t
85{
86 None,
87 UI,
88 Full,
89};
90
110class PluginDescriptor final : public QObject, public ICloneable<PluginDescriptor>
111{
112 Q_OBJECT
113 QML_ELEMENT
114 Q_PROPERTY (QString name READ getName CONSTANT FINAL)
115 Q_PROPERTY (QString format READ getFormat CONSTANT FINAL)
116
117public:
118 static std::unique_ptr<PluginDescriptor>
119 from_juce_description (const juce::PluginDescription &juce_desc);
120
121 std::unique_ptr<juce::PluginDescription> to_juce_description () const;
122
123 static PluginCategory string_to_category (const utils::Utf8String &str);
124 static utils::Utf8String category_to_string (PluginCategory category);
125
126 bool is_instrument () const;
127 bool is_effect () const;
128 bool is_modulator () const;
129 bool is_midi_modifier () const;
130
135 bool is_same_plugin (const PluginDescriptor &other) const;
136
140 bool has_custom_ui () const;
141
145 BridgeMode get_min_bridge_mode () const;
146
151
152 // GMenuModel * generate_context_menu () const;
153
154 [[nodiscard]] QString getName () const { return name_.to_qstring (); }
155 QString getFormat () const;
156
157 void
158 init_after_cloning (const PluginDescriptor &other, ObjectCloneType clone_type)
159 override;
160
161private:
162 static constexpr auto kAuthorKey = "author"sv;
163 static constexpr auto kNameKey = "name"sv;
164 static constexpr auto kWebsiteKey = "website"sv;
165 static constexpr auto kCategoryKey = "category"sv;
166 static constexpr auto kCategoryStringKey = "categoryString"sv;
167 static constexpr auto kNumAudioInsKey = "numAudioIns"sv;
168 static constexpr auto kNumAudioOutsKey = "numAudioOuts"sv;
169 static constexpr auto kNumMidiInsKey = "numMidiIns"sv;
170 static constexpr auto kNumMidiOutsKey = "numMidiOuts"sv;
171 static constexpr auto kNumCtrlInsKey = "numCtrlIns"sv;
172 static constexpr auto kNumCtrlOutsKey = "numCtrlOuts"sv;
173 static constexpr auto kNumCvInsKey = "numCvIns"sv;
174 static constexpr auto kNumCvOutsKey = "numCvOuts"sv;
175 static constexpr auto kUniqueIdKey = "uniqueId"sv;
176 static constexpr auto kDeprecatedUniqueIdKey = "deprecatedUniqueId"sv;
177 static constexpr auto kArchitectureKey = "architecture"sv;
178 static constexpr auto kProtocolKey = "protocol"sv;
179 static constexpr auto kPathOrIdKey = "pathOrId"sv;
180 static constexpr auto kMinBridgeModeKey = "minBridgeMode"sv;
181 static constexpr auto kHasCustomUIKey = "hasCustomUI"sv;
182 friend void to_json (nlohmann::json &j, const PluginDescriptor &p)
183 {
184 j = nlohmann::json{
185 { kAuthorKey, p.author_ },
186 { kNameKey, p.name_ },
187 { kWebsiteKey, p.website_ },
188 { kCategoryKey, p.category_ },
189 { kCategoryStringKey, p.category_str_ },
190 { kNumAudioInsKey, p.num_audio_ins_ },
191 { kNumAudioOutsKey, p.num_audio_outs_ },
192 { kNumMidiInsKey, p.num_midi_ins_ },
193 { kNumMidiOutsKey, p.num_midi_outs_ },
194 { kNumCtrlInsKey, p.num_ctrl_ins_ },
195 { kNumCtrlOutsKey, p.num_ctrl_outs_ },
196 { kNumCvInsKey, p.num_cv_ins_ },
197 { kNumCvOutsKey, p.num_cv_outs_ },
198 { kUniqueIdKey, p.unique_id_ },
199 { kDeprecatedUniqueIdKey, p.juce_compat_deprecated_unique_id_ },
200 { kArchitectureKey, p.arch_ },
201 { kProtocolKey, p.protocol_ },
202 { kPathOrIdKey, p.path_or_id_ },
203 { kMinBridgeModeKey, p.min_bridge_mode_ },
204 { kHasCustomUIKey, p.has_custom_ui_ },
205 };
206 }
207 friend void from_json (const nlohmann::json &j, PluginDescriptor &p)
208 {
209 j.at (kAuthorKey).get_to (p.author_);
210 j.at (kNameKey).get_to (p.name_);
211 j.at (kWebsiteKey).get_to (p.website_);
212 j.at (kCategoryKey).get_to (p.category_);
213 j.at (kCategoryStringKey).get_to (p.category_str_);
214 j.at (kNumAudioInsKey).get_to (p.num_audio_ins_);
215 j.at (kNumAudioOutsKey).get_to (p.num_audio_outs_);
216 j.at (kNumMidiInsKey).get_to (p.num_midi_ins_);
217 j.at (kNumMidiOutsKey).get_to (p.num_midi_outs_);
218 j.at (kNumCtrlInsKey).get_to (p.num_ctrl_ins_);
219 j.at (kNumCtrlOutsKey).get_to (p.num_ctrl_outs_);
220 j.at (kNumCvInsKey).get_to (p.num_cv_ins_);
221 j.at (kNumCvOutsKey).get_to (p.num_cv_outs_);
222 j.at (kUniqueIdKey).get_to (p.unique_id_);
223 j.at (kArchitectureKey).get_to (p.arch_);
224 j.at (kProtocolKey).get_to (p.protocol_);
225 {
226 const auto val = j.at (kPathOrIdKey);
227 if (val[zrythm::utils::serialization::kVariantIndexKey] == 0)
228 {
229 p.path_or_id_ =
230 val[zrythm::utils::serialization::kVariantValueKey].get<fs::path> ();
231 }
232 else
233 {
234 p.path_or_id_ =
235 val[zrythm::utils::serialization::kVariantValueKey]
236 .get<utils::Utf8String> ();
237 }
238 }
239 j.at (kMinBridgeModeKey).get_to (p.min_bridge_mode_);
240 j.at (kHasCustomUIKey).get_to (p.has_custom_ui_);
241 }
242
243 friend bool operator== (const PluginDescriptor &a, const PluginDescriptor &b)
244 {
245 constexpr auto tie = [] (const auto &p) {
246 return std::tie (
247 p.arch_, p.protocol_, p.path_or_id_, p.unique_id_,
248 p.juce_compat_deprecated_unique_id_, p.min_bridge_mode_,
249 p.has_custom_ui_);
250 };
251 return tie (a) == tie (b);
252 }
253
254public:
255 utils::Utf8String author_;
256 utils::Utf8String name_;
257 utils::Utf8String website_;
258 PluginCategory category_ = PluginCategory::None;
274 int num_cv_ins_ = 0;
278 PluginArchitecture arch_ = PluginArchitecture::ARCH_64_BIT;
281
286 std::variant<fs::path, utils::Utf8String> path_or_id_;
287
289 int64_t unique_id_{};
290
293
295 BridgeMode min_bridge_mode_ = BridgeMode::None;
296
297 bool has_custom_ui_{};
298
299 BOOST_DESCRIBE_CLASS (
301 (),
302 (author_,
303 name_,
304 website_,
305 category_,
307 protocol_,
313 arch_,
315 has_custom_ui_),
316 (),
317 ())
318};
319
320} // namespace zrythm::plugins
321
322namespace std
323{
324template <> struct hash<zrythm::plugins::PluginDescriptor>
325{
326 size_t operator() (const zrythm::plugins::PluginDescriptor &d) const
327 {
328 size_t h{};
329 h = h ^ qHash (d.protocol_);
330 h = h ^ qHash (d.arch_);
331 if (std::holds_alternative<fs::path> (d.path_or_id_))
332 {
333 h = h ^ qHash (std::get<fs::path> (d.path_or_id_).string ());
334 }
335 else
336 {
337 h = h ^ qHash (std::get<utils::Utf8String> (d.path_or_id_).str ());
338 }
339 h = h ^ qHash (d.unique_id_);
340 h = h ^ qHash (d.juce_compat_deprecated_unique_id_);
341 return h;
342 }
343};
344}
345
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.
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 string.h:39
ObjectCloneType
Definition icloneable.h:25