Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
preset_manager.hpp
Go to the documentation of this file.
1#pragma once
2
6
9#include <string>
10#include <vector>
11#include <functional>
12#include <filesystem>
13#include <optional>
14
15namespace pulp::state {
16
17
19struct PresetInfo {
20 std::string name;
21 std::filesystem::path path;
22 bool is_factory = false;
23 std::string folder;
24 std::string author;
25 std::string description;
26 std::vector<std::string> tags;
27};
28
31 ParamID id = 0;
32 float value = 0.0f;
33};
34
38using ContentPresetSource = std::function<std::vector<PresetInfo>(
39 const ContentCapabilityManifest& manifest, const std::filesystem::path& data_root)>;
40
61public:
63 PresetManager(StateStore& store, const std::string& manufacturer,
64 const std::string& plugin_name);
65
66 // ── Save/Load ────────────────────────────────────────────────────────
67
74 bool save(const std::string& name, const std::string& folder = "");
75
78 bool load(const PresetInfo& preset);
79
81 bool load(const std::filesystem::path& path);
82
88 std::optional<std::vector<ParamSetting>> read_values(const std::filesystem::path& path) const;
89
91 bool delete_preset(const PresetInfo& preset);
92
95 bool rename(const PresetInfo& preset, const std::string& new_name);
96
98 std::optional<PresetInfo> import_file(const std::filesystem::path& source);
99
100 // ── Discovery ────────────────────────────────────────────────────────
101
103 std::vector<PresetInfo> all_presets() const;
104
106 std::vector<PresetInfo> factory_presets() const;
107
109 std::vector<PresetInfo> user_presets() const;
110
114 std::vector<PresetInfo> content_presets() const;
115
123
125 void set_content_plugin_id(std::string plugin_id);
126
129 void set_content_capabilities(std::vector<std::string> capabilities);
130
133 void set_content_data_root(std::filesystem::path data_root);
134
138
140 void refresh();
141
142 // ── Current preset tracking ──────────────────────────────────────────
143
145 const std::string& current_preset_name() const { return current_name_; }
146 void set_current_preset_name(const std::string& name) { current_name_ = name; }
147
149 bool has_unsaved_changes() const { return unsaved_changes_; }
150 void mark_as_changed() { unsaved_changes_ = true; }
151 void mark_as_saved() { unsaved_changes_ = false; }
152
153 // ── Navigation ───────────────────────────────────────────────────────
154
156 bool load_next();
159
160 // ── Callbacks ────────────────────────────────────────────────────────
161
163 std::function<void(const PresetInfo&)> on_preset_loaded;
164
166 std::function<void()> on_list_changed;
167
168 // ── Paths ────────────────────────────────────────────────────────────
169
171 std::filesystem::path user_presets_dir() const { return user_dir_; }
172
174 std::filesystem::path factory_presets_dir() const { return factory_dir_; }
175
185 void set_factory_presets_dir(std::filesystem::path dir) {
186 factory_dir_ = std::move(dir);
187 cache_valid_ = false;
188 }
189
190private:
191 StateStore& store_;
192 std::string manufacturer_;
193 std::string plugin_name_;
194 std::filesystem::path user_dir_;
195 std::filesystem::path factory_dir_;
196 std::filesystem::path content_data_root_;
197 std::string content_plugin_id_;
198 std::vector<std::string> content_capabilities_;
199 std::vector<std::string> content_kinds_;
200 ContentPresetSource content_source_;
201
202 std::string current_name_;
203 bool unsaved_changes_ = false;
204
205 std::vector<PresetInfo> cached_presets_;
206 bool cache_valid_ = false;
207
208 void scan_directory(const std::filesystem::path& dir, bool is_factory,
209 std::vector<PresetInfo>& out) const;
210 void ensure_user_dir();
211 static std::filesystem::path platform_presets_root();
212};
213
214} // namespace pulp::state
bool load(const std::filesystem::path &path)
Load a preset by file path.
void set_content_data_root(std::filesystem::path data_root)
Override the content data root.
std::optional< PresetInfo > import_file(const std::filesystem::path &source)
Import a preset file from an external location into user presets.
const std::string & current_preset_name() const
The currently loaded preset (empty if unsaved/modified).
Definition preset_manager.hpp:145
void refresh()
Rescan preset directories (call after external changes).
bool has_unsaved_changes() const
True if parameters have changed since the last load/save.
Definition preset_manager.hpp:149
void mark_as_changed()
Definition preset_manager.hpp:150
bool save(const std::string &name, const std::string &folder="")
Save current state as a named preset in the user presets folder.
bool delete_preset(const PresetInfo &preset)
Delete a user preset file. Factory presets cannot be deleted.
std::vector< PresetInfo > factory_presets() const
Get factory presets only.
std::vector< PresetInfo > user_presets() const
Get user presets only.
std::filesystem::path factory_presets_dir() const
The factory presets directory (inside the plugin bundle).
Definition preset_manager.hpp:174
std::function< void()> on_list_changed
Called after the preset list changes (save/delete/rename/import).
Definition preset_manager.hpp:166
std::optional< std::vector< ParamSetting > > read_values(const std::filesystem::path &path) const
Read the parameter values a preset file holds without applying them.
bool rename(const PresetInfo &preset, const std::string &new_name)
Rename a user preset.
void set_content_manifest(const ContentCapabilityManifest &manifest)
Opt into content discovery from a parsed pulp.plugin-runtime.v1 manifest embedded in the plugin/app b...
void set_content_capabilities(std::vector< std::string > capabilities)
Limit installed content packs to matching capabilities such as content.presets.v1.
void set_factory_presets_dir(std::filesystem::path dir)
Point factory-preset discovery at a directory.
Definition preset_manager.hpp:185
std::vector< PresetInfo > content_presets() const
Get installed content-pack presets matching this plugin's content capabilities.
void mark_as_saved()
Definition preset_manager.hpp:151
bool load_next()
Load the next preset in the list. Wraps around.
std::vector< PresetInfo > all_presets() const
Get all presets (factory + user), sorted alphabetically.
PresetManager(StateStore &store, const std::string &manufacturer, const std::string &plugin_name)
Construct with a StateStore and plugin identity for path resolution.
void set_current_preset_name(const std::string &name)
Definition preset_manager.hpp:146
bool load(const PresetInfo &preset)
Load a preset from a PresetInfo (sets all parameter values).
std::function< void(const PresetInfo &)> on_preset_loaded
Called after a preset is loaded.
Definition preset_manager.hpp:163
void set_content_preset_source(ContentPresetSource source)
Install the reader that lists installed content-pack presets.
std::filesystem::path user_presets_dir() const
The user presets directory.
Definition preset_manager.hpp:171
bool load_previous()
Load the previous preset in the list. Wraps around.
void set_content_plugin_id(std::string plugin_id)
Opt into installed content-pack discovery for this plugin id.
Centralized parameter storage with lock-free value access.
Definition store.hpp:164
The capabilities a plugin declares before consuming installed content packs, and the pulp....
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
std::function< std::vector< PresetInfo >( const ContentCapabilityManifest &manifest, const std::filesystem::path &data_root)> ContentPresetSource
Lists installed content-pack presets for a plugin's content manifest.
Definition preset_manager.hpp:38
uint32_t ParamID
Unique parameter identifier, stable across plugin versions.
Definition parameter.hpp:55
Capabilities a plugin declares before consuming installed content packs.
Definition content_capability_manifest.hpp:19
One parameter value read from a preset file.
Definition preset_manager.hpp:30
float value
Definition preset_manager.hpp:32
Metadata for a single preset file.
Definition preset_manager.hpp:19
std::string name
Display name (filename without extension).
Definition preset_manager.hpp:20
std::filesystem::path path
Full path to the preset file.
Definition preset_manager.hpp:21
bool is_factory
True if this is a bundled factory preset.
Definition preset_manager.hpp:22
std::string author
Optional author name.
Definition preset_manager.hpp:24
std::string folder
Relative folder path (empty for root).
Definition preset_manager.hpp:23
std::string description
Optional description.
Definition preset_manager.hpp:25
std::vector< std::string > tags
Optional category tags.
Definition preset_manager.hpp:26