Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
cached_plugin_descriptors.h
1// SPDX-FileCopyrightText: © 2020-2021, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5#include "gui/dsp/plugin_descriptor.h"
6#include "utils/serialization.h"
7
13
14namespace zrythm::gui::old_dsp::plugins
15{
16
21{
22public:
29 static std::unique_ptr<CachedPluginDescriptors> read_or_new ();
30
37
43 {
44 try
45 {
47 }
48 catch (const ZrythmException &e)
49 {
50 z_warning (e.what ());
51 }
52 }
53
54 static constexpr int get_format_major_version () { return 6; }
55 static constexpr int get_format_minor_version () { return 0; }
56 static constexpr auto get_document_type ()
57 {
58 return "CachedPluginDescriptors"sv;
59 }
60
64 bool is_blacklisted (std::string_view sha1);
65
69 std::vector<std::unique_ptr<PluginDescriptor>>
70 get_valid_descriptors_for_sha1 (std::string_view sha1);
71
77 bool
78 contains_sha1 (std::string_view sha1, bool check_valid, bool check_blacklisted);
79
80 bool contains_valid_sha1 (auto sha1)
81 {
82 return contains_sha1 (sha1, true, false);
83 }
84
85 bool contains_blacklisted_sha1 (auto sha1)
86 {
87 return contains_sha1 (sha1, false, true);
88 }
89
95 void blacklist (std::string_view sha1, bool serialize);
96
103 void add (const PluginDescriptor &descr, bool serialize);
104
108 void clear ();
109
110 static constexpr auto kDescriptorsKey = "descriptors"sv;
111 static constexpr auto kBlacklistedSha1sKey = "blacklistedSha1s"sv;
112
113private:
114 friend void to_json (nlohmann::json &j, const CachedPluginDescriptors &p)
115 {
116 j = nlohmann::json{
117 { utils::serialization::kDocumentTypeKey, get_document_type () },
118 { utils::serialization::kFormatMajorKey, get_format_major_version () },
119 { utils::serialization::kFormatMinorKey, get_format_minor_version () },
120 { kDescriptorsKey, p.descriptors_ },
121 { kBlacklistedSha1sKey, p.blacklisted_sha1s_ },
122 };
123 }
124 friend void from_json (const nlohmann::json &j, CachedPluginDescriptors &p);
125
131 static void delete_file ();
132
133 static fs::path get_file_path ();
134
135public:
137 std::vector<std::unique_ptr<PluginDescriptor>> descriptors_;
138
140 std::vector<std::string> blacklisted_sha1s_;
141};
142
143} // namespace zrythm::gui::old_dsp::plugins
144
std::vector< std::unique_ptr< PluginDescriptor > > descriptors_
Valid descriptors.
std::vector< std::unique_ptr< PluginDescriptor > > get_valid_descriptors_for_sha1(std::string_view sha1)
Returns found non-blacklisted descriptors.
void serialize_to_file()
Serializes the cached descriptors to the standard file.
void serialize_to_file_no_throw()
Wrapper over serialize_to_file that ignores exceptions.
static std::unique_ptr< CachedPluginDescriptors > 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::string > blacklisted_sha1s_
Blacklisted hashes, to skip when scanning.
bool contains_sha1(std::string_view sha1, bool check_valid, bool check_blacklisted)
Returns whether the given sha1 is in the cache.
void add(const PluginDescriptor &descr, bool serialize)
Appends a descriptor to the cache.
void blacklist(std::string_view sha1, bool serialize)
Appends a descriptor to the cache.
void clear()
Clears the descriptors and removes the cache file.
bool is_blacklisted(std::string_view sha1)
Returns if the plugin with the given sha1 is blacklisted or not.
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