Krotos Modules 3
Loading...
Searching...
No Matches
krotos::PresetManager Class Referencefinal

Helper class for saving and loading presets. More...

#include <PresetManager.h>

Classes

struct  Preset
 

Public Member Functions

 PresetManager ()
 
const PresetgetCurrentPreset () const
 
void setCurrentPreset (const File &presetFile)
 
PopupMenu getCurrentPopupMenu ()
 

Static Public Member Functions

static bool checkPresetVersion (const File &presetFile, const String &pluginVersion, const bool showAlertWindow)
 
static String getPresetVersion (const ValueTree &state)
 
static String getPresetVersion (const File &presetFile)
 
static void writePresetVersion (ValueTree &state, const String &versionNumber)
 
static File getFactoryTemplateDirectory ()
 
static File getUserTemplateDirectory ()
 
static File getFactoryPresetDirectory ()
 
static File getUserPresetDirectory ()
 
static ValueTree getValueTreeFromFile (const File &presetFile)
 
static void writeValueTreeToFile (const ValueTree &valueTree, const File &outputFile)
 
static Preset getPresetFromFile (const File &file)
 
static File getInitPresetFile ()
 
static void checkReformerVersion (ValueTree &state)
 Checks the Reformer version within a ValueTree.
 
static void checkReformerVersion (File &preset)
 Checks the Reformer version within a File.
 
static void writeReformerVersion (ValueTree &state)
 Writes the Reformer version to a ValueTree.
 
static String getReformerVersion (ValueTree &state)
 Retrieves the Reformer version from a ValueTree.
 

Public Attributes

std::function< void(const ValueTree &)> presetChanged {nullptr}
 

Private Member Functions

PopupMenu getPopupMenuFromDirectory (const File &presetDirectory)
 
void initializePresetDirectories ()
 

Static Private Member Functions

static void checkReformerVersionInternal (ValueTree &state)
 

Private Attributes

Preset m_currentPreset
 

Static Private Attributes

static const String m_cutoffVersion
 
static const String m_factoryPresetFolderName = "Factory"
 
static const String m_userPresetFolderName = "User"
 
static const String m_presetFileExtension = "ksp"
 
static const String m_initFileName = "init"
 

Detailed Description

Helper class for saving and loading presets.

This class contains functions for saving and loading ValueTree objects as presets.

A single lambda can be registered with this class to perform the necessary actions after a change in preset.

This class can also export a PopupMenu containing a list of all the presets, which can then be used by a ComboBox to create a preset selection menu.

Constructor & Destructor Documentation

◆ PresetManager()

krotos::PresetManager::PresetManager ( )

Constructor.

Member Function Documentation

◆ checkPresetVersion()

bool krotos::PresetManager::checkPresetVersion ( const File & presetFile,
const String & pluginVersion,
const bool showAlertWindow )
static

Check plugin version number from a Preset. Returns true if version number is compatible with the current version

◆ checkReformerVersion() [1/2]

void krotos::PresetManager::checkReformerVersion ( File & preset)
static

Checks the Reformer version within a File.

This function reads a ValueTree from a File, checks if it contains a Reformer Kwidget, and compares its version to the current Reformer version. If the version is different or not present, it writes the Reformer version to the ValueTree.

Parameters
presetThe File containing the ValueTree to check and potentially update.

◆ checkReformerVersion() [2/2]

void krotos::PresetManager::checkReformerVersion ( ValueTree & state)
static

Checks the Reformer version within a ValueTree.

This function checks if a ValueTree contains a Reformer Kwidget and compares its version to the current Reformer version. If the version is different or not present, it writes the Reformer version to the ValueTree.

Parameters
stateThe ValueTree to check and potentially update.

◆ checkReformerVersionInternal()

void krotos::PresetManager::checkReformerVersionInternal ( ValueTree & state)
staticprivate

◆ getCurrentPopupMenu()

PopupMenu krotos::PresetManager::getCurrentPopupMenu ( )

Get a PopupMenu that can be added to a ComboBox & contains the entire preset list, with each PopupMenu::Item owning a function that will cause the preset to change when the menu item is selected.

Basically, just use this menu for your ComboBox, and no other message setup is needed.

◆ getCurrentPreset()

const PresetManager::Preset & krotos::PresetManager::getCurrentPreset ( ) const

Returns the current Preset.

◆ getFactoryPresetDirectory()

File krotos::PresetManager::getFactoryPresetDirectory ( )
static

Get the system-specific factory preset directory.

◆ getFactoryTemplateDirectory()

File krotos::PresetManager::getFactoryTemplateDirectory ( )
static

Get the system-specific factory template directory.

◆ getInitPresetFile()

File krotos::PresetManager::getInitPresetFile ( )
static

Getter for the init.ksp preset file

◆ getPopupMenuFromDirectory()

PopupMenu krotos::PresetManager::getPopupMenuFromDirectory ( const File & presetDirectory)
private

◆ getPresetFromFile()

PresetManager::Preset krotos::PresetManager::getPresetFromFile ( const File & file)
static

Get a Preset struct containing the name and file for a particular preset file.

◆ getPresetVersion() [1/2]

String krotos::PresetManager::getPresetVersion ( const File & presetFile)
static

Get the plugin version number from a preset file

◆ getPresetVersion() [2/2]

String krotos::PresetManager::getPresetVersion ( const ValueTree & state)
static

Get the plugin version number from a ValueTree

◆ getReformerVersion()

String krotos::PresetManager::getReformerVersion ( ValueTree & state)
static

Retrieves the Reformer version from a ValueTree.

This function retrieves the Reformer version from a given ValueTree.

Parameters
stateThe ValueTree from which the Reformer version will be retrieved.
Returns
The Reformer version as a String.

◆ getUserPresetDirectory()

File krotos::PresetManager::getUserPresetDirectory ( )
static

Get the system-specific user preset directory.

◆ getUserTemplateDirectory()

File krotos::PresetManager::getUserTemplateDirectory ( )
static

Get the system-specific user template directory.

◆ getValueTreeFromFile()

ValueTree krotos::PresetManager::getValueTreeFromFile ( const File & presetFile)
static

Get the ValueTree contained in a preset file.

◆ initializePresetDirectories()

void krotos::PresetManager::initializePresetDirectories ( )
private

◆ setCurrentPreset()

void krotos::PresetManager::setCurrentPreset ( const File & presetFile)

Set the preset, triggering a message that updates the whole plugin state.

◆ writePresetVersion()

void krotos::PresetManager::writePresetVersion ( ValueTree & state,
const String & versionNumber )
static

Write the current plugin version number to an incoming ValueTree, designed to be used when preset is saved

◆ writeReformerVersion()

void krotos::PresetManager::writeReformerVersion ( ValueTree & state)
static

Writes the Reformer version to a ValueTree.

This function writes the current Reformer version to a given ValueTree.

Parameters
stateThe ValueTree to which the Reformer version will be written.

◆ writeValueTreeToFile()

void krotos::PresetManager::writeValueTreeToFile ( const ValueTree & valueTree,
const File & outputFile )
static

Save a preset file from an existing ValueTree.

Member Data Documentation

◆ m_currentPreset

Preset krotos::PresetManager::m_currentPreset
private

◆ m_cutoffVersion

const String krotos::PresetManager::m_cutoffVersion
staticprivate
Initial value:
=
"0.0.17"

◆ m_factoryPresetFolderName

const String krotos::PresetManager::m_factoryPresetFolderName = "Factory"
staticprivate

◆ m_initFileName

const String krotos::PresetManager::m_initFileName = "init"
staticprivate

◆ m_presetFileExtension

const String krotos::PresetManager::m_presetFileExtension = "ksp"
staticprivate

◆ m_userPresetFolderName

const String krotos::PresetManager::m_userPresetFolderName = "User"
staticprivate

◆ presetChanged

std::function<void(const ValueTree&)> krotos::PresetManager::presetChanged {nullptr}

Register a function here to be called when the preset changes.


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