Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
plugin_collections.h
1// SPDX-FileCopyrightText: © 2020-2021, 2023-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <vector>
7
8#include "plugins/plugin_descriptor.h"
9
15
16namespace zrythm::gui::old_dsp::plugins
17{
18
23{
24public:
25 using PluginDescriptor = zrythm::plugins::PluginDescriptor;
26
27 std::string get_name () const { return name_; }
28
29 void set_name (std::string_view name) { name_ = name; }
30
31 void clear () { descriptors_.clear (); }
32
36 bool contains_descriptor (const PluginDescriptor &descr) const;
37
41 void add_descriptor (const PluginDescriptor &descr);
42
46 void remove_descriptor (const PluginDescriptor &descr);
47
51 // Glib::RefPtr<Gio::MenuModel> generate_context_menu () const;
52
53 friend void init_from (
55 const PluginCollection &other,
56 utils::ObjectCloneType clone_type);
57
58private:
59 static constexpr auto kNameKey = "name"sv;
60 static constexpr auto kDescriptionKey = "description"sv;
61 static constexpr auto kDescriptorsKey = "descriptors"sv;
62 friend void to_json (nlohmann::json &j, const PluginCollection &p)
63 {
64 j = nlohmann::json{
65 { kNameKey, p.name_ },
66 { kDescriptionKey, p.description_ },
67 { kDescriptorsKey, p.descriptors_ },
68 };
69 }
70 friend void from_json (const nlohmann::json &j, PluginCollection &p)
71 {
72 j.at (kNameKey).get_to (p.name_);
73 j.at (kDescriptionKey).get_to (p.description_);
74 j.at (kDescriptorsKey).get_to (p.descriptors_);
75 }
76
77public:
79 std::string name_;
80
82 std::string description_;
83
85 std::vector<std::unique_ptr<PluginDescriptor>> descriptors_;
86};
87
92{
93public:
100 static std::unique_ptr<PluginCollections> read_or_new ();
101
107 void serialize_to_file () const;
108
114 {
115 try
116 {
118 }
119 catch (const ZrythmException &e)
120 {
121 z_warning (e.what ());
122 }
123 }
124
125 std::string get_document_type () const { return "Zrythm Plugin Collections"; }
126 int get_format_major_version () const { return 3; }
127 int get_format_minor_version () const { return 0; }
128
135 void add (const PluginCollection &collection, bool serialize);
136
140 const PluginCollection * find_from_name (std::string_view name) const;
141
148 void remove (PluginCollection &collection, bool serialize);
149
150private:
151 static constexpr auto kCollectionsKey = "collections"sv;
152 friend void to_json (nlohmann::json &j, const PluginCollections &pc)
153 {
154 j[kCollectionsKey] = pc.collections_;
155 }
156 friend void from_json (const nlohmann::json &j, PluginCollections &pc)
157 {
158 j.at (kCollectionsKey).get_to (pc.collections_);
159 }
160
166 static void delete_file ();
167
168 static fs::path get_file_path ();
169
170public:
172 std::vector<std::unique_ptr<PluginCollection>> collections_;
173};
174
175} // namespace zrythm::gui::old_dsp::plugins
176
Plugin collection used in the plugin browser.
friend void init_from(PluginCollection &obj, const PluginCollection &other, utils::ObjectCloneType clone_type)
Generates a context menu for the collection.
void remove_descriptor(const PluginDescriptor &descr)
Removes the descriptor matching the given one from the collection.
std::vector< std::unique_ptr< PluginDescriptor > > descriptors_
Plugin descriptors.
std::string description_
Description of the collection (optional).
void add_descriptor(const PluginDescriptor &descr)
Appends a descriptor to the collection.
bool contains_descriptor(const PluginDescriptor &descr) const
Returns whether the collection contains the given descriptor.
static std::unique_ptr< PluginCollections > read_or_new()
Returns a new instance with the cache pre-filled from the cache file, or an empty instance if there i...
std::vector< std::unique_ptr< PluginCollection > > collections_
Plugin collections.
void serialize_to_file() const
Serializes the cached descriptors to the standard file.
void add(const PluginCollection &collection, bool serialize)
Appends a collection.
void remove(PluginCollection &collection, bool serialize)
Removes the given collection.
const PluginCollection * find_from_name(std::string_view name) const
Finds a collection by name.
void serialize_to_file_no_throw() const
Wrapper over serialize_to_file that ignores exceptions.
The PluginDescriptor class provides a set of static utility functions and member functions to work wi...
Base class for exceptions in Zrythm.
Definition exceptions.h:20