Skip to content

GuitarPrometheus::Profiles::ProfileStore

GuitarPrometheus::Profiles::ProfileStore

Central store for VST keyswitch profiles. More…

#include <ProfileStore.h>

Public Classes

Name
structArchiveResult
Aggregate result of exportAllToZip / importAllFromZip.
structImportPreview
Outcome of a non-committing import probe.

Public Types

Name
enum classCollisionChoice { Replace, Copy, Cancel}
using std::function< CollisionChoice(const Profile &incoming, const Profile &existing)>CollisionResolver

Public Functions

Name
ProfileStore(juce::File userProfilesDirectory, std::unique_ptr< ClipboardPort > clipboardPort)
Construct with injected dependencies.
ProfileLoadResultloadAll()
Load bundled defaults + every JSON in the user profiles directory, merging with user shadowing bundled on UUID match.
intrestoreBundledPresets()
Re-save any bundled presets whose UUID is not already on disk.
std::optional< juce::Uuid >duplicateProfile(const Profile & source)
Create a copy of source with a new UUID and “(Copy)” appended to the name.
voidsave(const Profile & profile)
Save a profile.
ProfileLoadResultimportFromFile(const juce::File & path, const CollisionResolver & collisionResolver)
Import from file.
ProfileLoadResultimportFromClipboard(const CollisionResolver & collisionResolver)
Import from the clipboard via the injected port.
ImportPreviewpreviewImportFromFile(const juce::File & path)
Parse + validate an import candidate without committing it.
ImportPreviewpreviewImportFromClipboard()
Parse + validate the clipboard payload without committing it.
ArchiveResultexportAllToZip(const juce::File & path)
Bundle every profile currently loaded by the store into a .zip archive at path.
ArchiveResultimportAllFromZip(const juce::File & path, const CollisionResolver & collisionResolver)
Read every .json entry in a .zip archive at path, parse + validate each, route through the same collision resolver as importFromFile, and persist the survivors.
voidexportToFile(const Profile & profile, const juce::File & path) const
Export a profile to file as pretty-printed JSON.
voidexportToClipboard(const Profile & profile)
Export a profile to the clipboard as JSON.
boolremove(const juce::Uuid & id)
Delete a profile’s on-disk file.
const juce::File &getProfilesDirectory() const
juce::StringfilenameFor(const Profile & profile)
Compute the on-disk filename for a profile (without directory).
std::stringserializeToJson(const Profile & profile)
Serialize a profile to its canonical JSON form.

Detailed Description

class GuitarPrometheus::Profiles::ProfileStore;

Central store for VST keyswitch profiles.

Loads bundled defaults and user profiles from the user’s application support directory; merges them (user profiles shadow bundled on UUID match); saves updated profiles back with atomic write-rename semantics. Filenames follow {slug(name)}-{hash}.json derived from UUID + salt.

Import/export (file and clipboard) go through the same validation pipeline as load.

Public Types Documentation

enum CollisionChoice

EnumeratorValueDescription
ReplaceOverwrite the existing profile with the incoming one (same UUID).
CopyRe-mint the incoming profile’s UUID and append “(copy)” so both are kept.
CancelSkip the import entirely.

using CollisionResolver

using GuitarPrometheus::Profiles::ProfileStore::CollisionResolver = std::function<CollisionChoice(const Profile& incoming, const Profile& existing)>;

Public Functions Documentation

function ProfileStore

ProfileStore(
juce::File userProfilesDirectory,
std::unique_ptr< ClipboardPort > clipboardPort
)

Construct with injected dependencies.

Parameters:

  • userProfilesDirectory Directory where user profiles live. Created if it doesn’t exist.
  • clipboardPort Clipboard abstraction for import/export; inject a fake in tests.

function loadAll

ProfileLoadResult loadAll()

Load bundled defaults + every JSON in the user profiles directory, merging with user shadowing bundled on UUID match.

function restoreBundledPresets

int restoreBundledPresets()

Re-save any bundled presets whose UUID is not already on disk.

Return: Count of newly saved profiles.

function duplicateProfile

std::optional< juce::Uuid > duplicateProfile(
const Profile & source
)

Create a copy of source with a new UUID and “(Copy)” appended to the name.

Return: The new profile’s UUID, or nullopt on failure.

function save

void save(
const Profile & profile
)

Save a profile.

Computes target filename from current name/uuid/salt; if different from the previously-tracked location for this UUID, the old file is deleted after the new one writes. Uses write-to-temporary-then-rename for atomicity.

function importFromFile

ProfileLoadResult importFromFile(
const juce::File & path,
const CollisionResolver & collisionResolver
)

Import from file.

Validates, handles UUID collisions (callback decides replace, copy, or cancel), persists via save. Returning Cancel from the resolver leaves the store untouched.

function importFromClipboard

ProfileLoadResult importFromClipboard(
const CollisionResolver & collisionResolver
)

Import from the clipboard via the injected port.

function previewImportFromFile

ImportPreview previewImportFromFile(
const juce::File & path
)

Parse + validate an import candidate without committing it.

Surfaces the prospective profile, any existing profile sharing its UUID, and the validation issues so callers (e.g. the editor) can show a collision dialog before deciding what to do.

function previewImportFromClipboard

ImportPreview previewImportFromClipboard()

Parse + validate the clipboard payload without committing it.

Mirrors previewImportFromFile for clipboard-driven imports.

function exportAllToZip

ArchiveResult exportAllToZip(
const juce::File & path
)

Bundle every profile currently loaded by the store into a .zip archive at path.

Each profile lands at <slug>-<hash>.json inside the zip — same naming as on-disk storage so a power user can unzip the archive directly into their profiles directory. Returns the list of profiles written plus any per-profile issues; the archive itself is created even when individual profiles error.

function importAllFromZip

ArchiveResult importAllFromZip(
const juce::File & path,
const CollisionResolver & collisionResolver
)

Read every .json entry in a .zip archive at path, parse + validate each, route through the same collision resolver as importFromFile, and persist the survivors.

Useful for restoring a profile library onto a fresh machine. The resolver receives (incoming, existing) per colliding entry; returning Cancel skips that entry without aborting the whole archive.

function exportToFile

void exportToFile(
const Profile & profile,
const juce::File & path
) const

Export a profile to file as pretty-printed JSON.

function exportToClipboard

void exportToClipboard(
const Profile & profile
)

Export a profile to the clipboard as JSON.

function remove

bool remove(
const juce::Uuid & id
)

Delete a profile’s on-disk file.

Bundled defaults aren’t deleted from the in-process registry, so a removed bundled UUID will reappear on the next [loadAll()](/api-reference/classes/classguitarprometheus_1_1profiles_1_1profilestore/#function-loadall). User profiles vanish permanently. Returns true when a file was actually removed; false when the UUID isn’t tracked or the underlying file is gone.

function getProfilesDirectory

inline const juce::File & getProfilesDirectory() const

function filenameFor

static juce::String filenameFor(
const Profile & profile
)

Compute the on-disk filename for a profile (without directory).

Exposed for tests and UI preview.

function serializeToJson

static std::string serializeToJson(
const Profile & profile
)

Serialize a profile to its canonical JSON form.

Used by both save and export.


Updated on 2026-05-29 at 07:39:52 +0000