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-2026 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
16using namespace std::string_view_literals;
17
18namespace zrythm::gui::old_dsp::plugins
19{
20
25{
26public:
27 using PluginDescriptor = zrythm::plugins::PluginDescriptor;
28
29 std::string get_name () const { return name_; }
30
31 void set_name (std::string_view name) { name_ = name; }
32
33 void clear () { descriptors_.clear (); }
34
38 bool contains_descriptor (const PluginDescriptor &descr) const;
39
43 void add_descriptor (const PluginDescriptor &descr);
44
48 void remove_descriptor (const PluginDescriptor &descr);
49
53 // Glib::RefPtr<Gio::MenuModel> generate_context_menu () const;
54
55 friend void init_from (
57 const PluginCollection &other,
58 utils::ObjectCloneType clone_type);
59
60private:
61 static constexpr auto kNameKey = "name"sv;
62 static constexpr auto kDescriptionKey = "description"sv;
63 static constexpr auto kDescriptorsKey = "descriptors"sv;
64 friend void to_json (nlohmann::json &j, const PluginCollection &p);
65 friend void from_json (const nlohmann::json &j, PluginCollection &p);
66
67public:
69 std::string name_;
70
72 std::string description_;
73
75 std::vector<std::unique_ptr<PluginDescriptor>> descriptors_;
76};
77
82{
83public:
90 static std::unique_ptr<PluginCollections> read_or_new ();
91
97 void serialize_to_file () const;
98
104
105 std::string get_document_type () const { return "Zrythm Plugin Collections"; }
106 int get_format_major_version () const { return 3; }
107 int get_format_minor_version () const { return 0; }
108
115 void add (const PluginCollection &collection, bool serialize);
116
120 const PluginCollection * find_from_name (std::string_view name) const;
121
128 void remove (PluginCollection &collection, bool serialize);
129
130private:
131 static constexpr auto kCollectionsKey = "collections"sv;
132 friend void to_json (nlohmann::json &j, const PluginCollections &pc);
133 friend void from_json (const nlohmann::json &j, PluginCollections &pc);
134
140 static void delete_file ();
141
142 static std::filesystem::path get_file_path ();
143
144public:
146 std::vector<std::unique_ptr<PluginCollection>> collections_;
147};
148
149} // namespace zrythm::gui::old_dsp::plugins
150
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...