Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::state::PresetManager Class Reference

Built-in preset manager for Pulp plugins. More...

#include <preset_manager.hpp>

Public Member Functions

 PresetManager (StateStore &store, const std::string &manufacturer, const std::string &plugin_name)
 Construct with a StateStore and plugin identity for path resolution.
bool save (const std::string &name, const std::string &folder="")
 Save current state as a named preset in the user presets folder.
bool load (const PresetInfo &preset)
 Load a preset from a PresetInfo (sets all parameter values).
bool load (const std::filesystem::path &path)
 Load a preset by file path.
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 delete_preset (const PresetInfo &preset)
 Delete a user preset file. Factory presets cannot be deleted.
bool rename (const PresetInfo &preset, const std::string &new_name)
 Rename a user preset.
std::optional< PresetInfo > import_file (const std::filesystem::path &source)
 Import a preset file from an external location into user presets.
std::vector< PresetInfo > all_presets () const
 Get all presets (factory + user), sorted alphabetically.
std::vector< PresetInfo > factory_presets () const
 Get factory presets only.
std::vector< PresetInfo > user_presets () const
 Get user presets only.
std::vector< PresetInfo > content_presets () const
 Get installed content-pack presets matching this plugin's content capabilities.
void set_content_preset_source (ContentPresetSource source)
 Install the reader that lists installed content-pack presets.
void set_content_plugin_id (std::string plugin_id)
 Opt into installed content-pack discovery for this plugin id.
void set_content_capabilities (std::vector< std::string > capabilities)
 Limit installed content packs to matching capabilities such as content.presets.v1.
void set_content_data_root (std::filesystem::path data_root)
 Override the content data root.
void set_content_manifest (const ContentCapabilityManifest &manifest)
 Opt into content discovery from a parsed pulp.plugin-runtime.v1 manifest embedded in the plugin/app bundle.
void refresh ()
 Rescan preset directories (call after external changes).
const std::string & current_preset_name () const
 The currently loaded preset (empty if unsaved/modified).
void set_current_preset_name (const std::string &name)
bool has_unsaved_changes () const
 True if parameters have changed since the last load/save.
void mark_as_changed ()
void mark_as_saved ()
bool load_next ()
 Load the next preset in the list. Wraps around.
bool load_previous ()
 Load the previous preset in the list. Wraps around.
std::filesystem::path user_presets_dir () const
 The user presets directory.
std::filesystem::path factory_presets_dir () const
 The factory presets directory (inside the plugin bundle).
void set_factory_presets_dir (std::filesystem::path dir)
 Point factory-preset discovery at a directory.

Public Attributes

std::function< void(const PresetInfo &)> on_preset_loaded
 Called after a preset is loaded.
std::function< void()> on_list_changed
 Called after the preset list changes (save/delete/rename/import).

Detailed Description

Built-in preset manager for Pulp plugins.

Handles the full preset lifecycle: save, load, delete, rename, import, factory vs user separation, folder scanning, and current-preset tracking.

Preset files are JSON with the plugin's serialized state plus metadata.

Storage locations (platform-standard):

  • macOS: ~/Library/Audio/Presets/<manufacturer>/<plugin_name>/
  • Windows: APPDATA%/<manufacturer>/<plugin_name>/Presets/
  • Linux: ~/.config/<manufacturer>/<plugin_name>/presets/

Factory presets live in the plugin bundle's Resources/Presets/ directory.

PresetManager presets(store, "MyCompany", "MyPlugin");
presets.save("Init");
presets.load(presets.user_presets()[0]);
PresetManager(StateStore &store, const std::string &manufacturer, const std::string &plugin_name)
Construct with a StateStore and plugin identity for path resolution.

Constructor & Destructor Documentation

◆ PresetManager()

pulp::state::PresetManager::PresetManager ( StateStore & store,
const std::string & manufacturer,
const std::string & plugin_name )

Construct with a StateStore and plugin identity for path resolution.

Member Function Documentation

◆ all_presets()

std::vector< PresetInfo > pulp::state::PresetManager::all_presets ( ) const

Get all presets (factory + user), sorted alphabetically.

◆ content_presets()

std::vector< PresetInfo > pulp::state::PresetManager::content_presets ( ) const

Get installed content-pack presets matching this plugin's content capabilities.

These are read-only expansion/factory presets. Empty until both a content plugin id and a content-preset source are set.

◆ current_preset_name()

const std::string & pulp::state::PresetManager::current_preset_name ( ) const
inline

The currently loaded preset (empty if unsaved/modified).

◆ delete_preset()

bool pulp::state::PresetManager::delete_preset ( const PresetInfo & preset)

Delete a user preset file. Factory presets cannot be deleted.

◆ factory_presets()

std::vector< PresetInfo > pulp::state::PresetManager::factory_presets ( ) const

Get factory presets only.

◆ factory_presets_dir()

std::filesystem::path pulp::state::PresetManager::factory_presets_dir ( ) const
inline

The factory presets directory (inside the plugin bundle).

◆ has_unsaved_changes()

bool pulp::state::PresetManager::has_unsaved_changes ( ) const
inline

True if parameters have changed since the last load/save.

◆ import_file()

std::optional< PresetInfo > pulp::state::PresetManager::import_file ( const std::filesystem::path & source)

Import a preset file from an external location into user presets.

◆ load() [1/2]

bool pulp::state::PresetManager::load ( const PresetInfo & preset)

Load a preset from a PresetInfo (sets all parameter values).

Returns
True on success.

◆ load() [2/2]

bool pulp::state::PresetManager::load ( const std::filesystem::path & path)

Load a preset by file path.

◆ load_next()

bool pulp::state::PresetManager::load_next ( )

Load the next preset in the list. Wraps around.

◆ load_previous()

bool pulp::state::PresetManager::load_previous ( )

Load the previous preset in the list. Wraps around.

◆ mark_as_changed()

void pulp::state::PresetManager::mark_as_changed ( )
inline

◆ mark_as_saved()

void pulp::state::PresetManager::mark_as_saved ( )
inline

◆ read_values()

std::optional< std::vector< ParamSetting > > pulp::state::PresetManager::read_values ( const std::filesystem::path & path) const

Read the parameter values a preset file holds without applying them.

Only parameters the store defines and the file names are returned, in store order. Returns nullopt when the file cannot be read or has no parameters section. Lets a caller cache a preset once and apply it later from a thread that must not touch the file system.

◆ refresh()

void pulp::state::PresetManager::refresh ( )

Rescan preset directories (call after external changes).

◆ rename()

bool pulp::state::PresetManager::rename ( const PresetInfo & preset,
const std::string & new_name )

Rename a user preset.

Factory presets cannot be renamed, and the new name must be a single path component (see save()).

◆ save()

bool pulp::state::PresetManager::save ( const std::string & name,
const std::string & folder = "" )

Save current state as a named preset in the user presets folder.

Parameters
namePreset name (used as filename, .json appended)
folderOptional subfolder within user presets directory
Returns
True on success. A name or folder that is not a single path component (contains a separator, is "." or "..", or embeds NUL) is rejected.

◆ set_content_capabilities()

void pulp::state::PresetManager::set_content_capabilities ( std::vector< std::string > capabilities)

Limit installed content packs to matching capabilities such as content.presets.v1.

◆ set_content_data_root()

void pulp::state::PresetManager::set_content_data_root ( std::filesystem::path data_root)

Override the content data root.

Intended for tests and explicit sandboxing; normal plugins use the platform user-data root.

◆ set_content_manifest()

void pulp::state::PresetManager::set_content_manifest ( const ContentCapabilityManifest & manifest)

Opt into content discovery from a parsed pulp.plugin-runtime.v1 manifest embedded in the plugin/app bundle.

◆ set_content_plugin_id()

void pulp::state::PresetManager::set_content_plugin_id ( std::string plugin_id)

Opt into installed content-pack discovery for this plugin id.

◆ set_content_preset_source()

void pulp::state::PresetManager::set_content_preset_source ( ContentPresetSource source)

Install the reader that lists installed content-pack presets.

This state layer carries no content-pack reader of its own; the content-pack layer provides one (content_registry_preset_source()). Code that opts this manager into content discovery installs it together with set_content_plugin_id() or set_content_manifest(); the format adapters do neither, so their managers list no content-pack presets and carry no content-pack link.

◆ set_current_preset_name()

void pulp::state::PresetManager::set_current_preset_name ( const std::string & name)
inline

◆ set_factory_presets_dir()

void pulp::state::PresetManager::set_factory_presets_dir ( std::filesystem::path dir)
inline

Point factory-preset discovery at a directory.

The constructor cannot resolve this on its own: the folder that holds a plug-in's bundled presets is format- and platform-specific (a macOS bundle keeps them under Contents/Resources/Presets, a flat iOS app-extension bundle directly under Presets), and a headless host has no bundle at all. Until a caller sets it, factory_presets() scans an empty path and returns nothing — so a plug-in that ships factory presets must call this, normally from its format adapter.

◆ user_presets()

std::vector< PresetInfo > pulp::state::PresetManager::user_presets ( ) const

Get user presets only.

◆ user_presets_dir()

std::filesystem::path pulp::state::PresetManager::user_presets_dir ( ) const
inline

The user presets directory.

Member Data Documentation

◆ on_list_changed

std::function<void()> pulp::state::PresetManager::on_list_changed

Called after the preset list changes (save/delete/rename/import).

◆ on_preset_loaded

std::function<void(const PresetInfo&)> pulp::state::PresetManager::on_preset_loaded

Called after a preset is loaded.


The documentation for this class was generated from the following file: