Allolib  1.0
C++ Components For Interactive Multimedia
al::PresetHandler Class Reference

The PresetHandler class handles sorting and recalling of presets. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/ui/al_PresetHandler.hpp>

Public Types

typedef std::map< std::string, std::vector< ParameterField > > ParameterStates
 
typedef const std::function< void(std::string)> PresetMapCallback
 

Public Member Functions

 PresetHandler (std::string rootDirectory, bool verbose=false)
 PresetHandler contructor. More...
 
 PresetHandler (TimeMasterMode timeMasterMode=TimeMasterMode::TIME_MASTER_CPU, std::string rootDirectory="presets", bool verbose=false)
 Constructor with option to set time master mode. More...
 
void storePreset (std::string name)
 Stores preset. More...
 
void storePreset (int index, std::string name="", bool overwrite=true)
 Store preset at index. The name argument specifies the preset name. More...
 
void recallPreset (std::string name)
 Recall a preset by name. More...
 
std::string recallPreset (int index)
 Recall a preset by index number. More...
 
void recallPresetSynchronous (std::string name)
 
std::string recallPresetSynchronous (int index)
 recall immediately (not using the morph thread) More...
 
void setInterpolatedPreset (int index1, int index2, double factor)
 Set parameters to values interpolated between two presets. More...
 
void setInterpolatedPreset (std::string presetName1, std::string presetName2, double factor)
 
void setInterpolatedValues (ParameterStates &startValues, ParameterStates &endValues, double factor=1.0)
 Interpolate between start and end values according to factor.
 
std::map< int, std::string > availablePresets ()
 
std::string getPresetName (int index)
 
std::string getCurrentPresetName ()
 
void skipParameter (std::string parameterAddr, bool skip=true)
 Add or remove a parameter address from group that will be skipped when recalling presets. More...
 
int getCurrentPresetIndex ()
 
float getMorphTime ()
 
void setMorphTime (float time)
 
void setMaxMorphTime (float time)
 
void stopMorphing ()
 
void morphTo (ParameterStates &parameterStates, float morphTime)
 
void morphTo (std::string presetName, float morphTime)
 
void setMorphStepTime (float stepTime)
 
void stepMorphing (double stepTime)
 
void stepMorphing ()
 
void setSubDirectory (std::string directory)
 
std::string getSubDirectory ()
 
std::string getCurrentPath ()
 Path including subdirectory if any.
 
void setRootPath (std::string path)
 
std::string getRootPath ()
 Base path without appending sub directory.
 
void print ()
 
void registerPresetCallback (std::function< void(int index, void *sender, void *userData)> cb, void *userData=nullptr)
 Register a callback to be notified when a preset is loaded. More...
 
void registerStoreCallback (std::function< void(int index, std::string name, void *userData)> cb, void *userData=nullptr)
 Register a callback to be notified when a preset is stored. More...
 
void registerMorphTimeCallback (Parameter::ParameterChangeCallback cb)
 Register a callback to be notified when morph time parameter is changed. More...
 
void registerPresetMapCallback (PresetMapCallback cb)
 Register a callback to be notified when preset map cahges. More...
 
PresetHandlerregisterParameter (ParameterMeta &parameter)
 
PresetHandleroperator<< (ParameterMeta &param)
 
PresetHandlerregisterParameterBundle (ParameterBundle &bundle)
 
PresetHandleroperator<< (ParameterBundle &bundle)
 
std::vector< ParameterMeta * > parameters ()
 
std::string buildMapPath (std::string mapName, bool useSubDirectory=false)
 
std::vector< std::string > availablePresetMaps ()
 
std::map< int, std::string > readPresetMap (std::string mapName="default")
 
void setCurrentPresetMap (std::string mapName="default", bool autoCreate=false)
 
void setPresetMap (std::map< int, std::string > presetsMap)
 
void storeCurrentPresetMap (std::string mapName="", bool useSubDirectory=false)
 
void useCallbacks (bool use)
 useCallbacks determines whether to call the internal callbacks More...
 
void changeParameterValue (std::string presetName, std::string parameterPath, float newValue)
 
void verbose (bool isVerbose)
 
void setVerbose (bool isVerbose=true)
 
bool verbose ()
 
ParameterStates loadPresetValues (std::string name)
 load preset into parameter states data structure without setting values More...
 
bool savePresetValues (const ParameterStates &values, std::string presetName, bool overwrite=true)
 save list of parameter states into text preset file More...
 
void setTimeMaster (TimeMasterMode masterMode)
 
void startCpuThread ()
 
void stopCpuThread ()
 

Static Public Member Functions

static int asciiToPresetIndex (int ascii, int offset=0)
 Map QWERTY ascii keys to presets 0-49. More...
 

Detailed Description

The PresetHandler class handles sorting and recalling of presets.

Presets are saved by name with the ".preset" suffix.

Definition at line 66 of file al_PresetHandler.hpp.

Constructor & Destructor Documentation

◆ PresetHandler() [1/2]

al::PresetHandler::PresetHandler ( std::string  rootDirectory,
bool  verbose = false 
)

PresetHandler contructor.

Parameters
rootDirectorysets the root directory for preset and preset map storage
verboseif true, print diagnostic messages

◆ PresetHandler() [2/2]

al::PresetHandler::PresetHandler ( TimeMasterMode  timeMasterMode = TimeMasterMode::TIME_MASTER_CPU,
std::string  rootDirectory = "presets",
bool  verbose = false 
)

Constructor with option to set time master mode.

Parameters
timeMasterModeOnly two modes are currently valid for PresetHandler: TIME_MASTER_CPU and TIME_MASTER_ASYNC. The first will start a CPU thread that handles morphing and setting values, the second does not start the thread, so user must manually call tick()

Member Function Documentation

◆ asciiToPresetIndex()

static int al::PresetHandler::asciiToPresetIndex ( int  ascii,
int  offset = 0 
)
static

Map QWERTY ascii keys to presets 0-49.

Parameters
asciiascii code of the key to mapt
offsetadd an offset on output
Returns
the mapped value 0-39 plus offset. Returns -1 on failure to map.

This maps four rows of 10 keys on the ASCII keyboard (regular QWERTY US keys) to numbers 0-39. This can be useful for quick preset mapping using the whole keyboard.

◆ loadPresetValues()

ParameterStates al::PresetHandler::loadPresetValues ( std::string  name)

load preset into parameter states data structure without setting values

Parameters
namename of the preset to load
Returns
the state of the parameters in the loaded prese

◆ print()

void al::PresetHandler::print ( )

Display information about preset handler, including path and registered parameters.

◆ recallPreset() [1/2]

std::string al::PresetHandler::recallPreset ( int  index)

Recall a preset by index number.

Parameters
index
Returns
the name of the preset corresponding to index. Empty if index not valid.

The preset map file (by default called default.presetMap) is used to map preset names on disk to indeces. You can set alternative preset map files using setCurrentPresetMap(). See also PresetMapper for handling and archiving preset maps.

◆ recallPreset() [2/2]

void al::PresetHandler::recallPreset ( std::string  name)

Recall a preset by name.

Parameters
nameThe preset should be a file on disk in the PresetHandler's root directory and should have the ".preset" extension. See also setSubDirectory().

◆ recallPresetSynchronous()

std::string al::PresetHandler::recallPresetSynchronous ( int  index)

recall immediately (not using the morph thread)

Parameters
index

◆ registerMorphTimeCallback()

void al::PresetHandler::registerMorphTimeCallback ( Parameter::ParameterChangeCallback  cb)

Register a callback to be notified when morph time parameter is changed.

Parameters
cbThe callback function

◆ registerPresetCallback()

void al::PresetHandler::registerPresetCallback ( std::function< void(int index, void *sender, void *userData)>  cb,
void *  userData = nullptr 
)

Register a callback to be notified when a preset is loaded.

Parameters
cbThe callback function
userDatadata to be passed to the callback

◆ registerPresetMapCallback()

void al::PresetHandler::registerPresetMapCallback ( PresetMapCallback  cb)

Register a callback to be notified when preset map cahges.

Parameters
cbThe callback function

◆ registerStoreCallback()

void al::PresetHandler::registerStoreCallback ( std::function< void(int index, std::string name, void *userData)>  cb,
void *  userData = nullptr 
)

Register a callback to be notified when a preset is stored.

Parameters
cbThe callback function
userDatadata to be passed to the callback

◆ savePresetValues()

bool al::PresetHandler::savePresetValues ( const ParameterStates &  values,
std::string  presetName,
bool  overwrite = true 
)

save list of parameter states into text preset file

Parameters
valuesthe values of parameters to store
presetNamename of preset to store
overwritetrue overwrites otherwise append unique number
Returns
true if no errors.

◆ setInterpolatedPreset()

void al::PresetHandler::setInterpolatedPreset ( int  index1,
int  index2,
double  factor 
)

Set parameters to values interpolated between two presets.

Parameters
index1index of the first preset
index2index of the second preset
factorA value between 0-1 to determine interpolation
synchronousThe values are set instantly and synchronous to this call

A factor of 0 uses preset 1 and a factor of 1 uses preset 2. Values in between result in linear interpolation of the values.

◆ skipParameter()

void al::PresetHandler::skipParameter ( std::string  parameterAddr,
bool  skip = true 
)

Add or remove a parameter address from group that will be skipped when recalling presets.

Parameters
parameteraddress of parameter to skip
skipset to false if you want to remove from skip list

This is used within loadPresetValues(), so it will affect both synchronous and asynchronous recall.

◆ stepMorphing()

void al::PresetHandler::stepMorphing ( )

Step morphing to adjust parameter values to next step. You need to call this function only if TimeMasterMode is TIME_MASTER_ASYNC

◆ storePreset() [1/2]

void al::PresetHandler::storePreset ( int  index,
std::string  name = "",
bool  overwrite = true 
)

Store preset at index. The name argument specifies the preset name.

Parameters
index
name
overwriteif false, and preset file exists it is not overwritten and a number is appended

The preset name also determines the filename under which the preset is saved, so it must be unique. If name is empty, a unique name is generated. If name exists, a number is appended to the preset name. The link between preset index and preset name is store within the preset map file that is stored in the path for the PresetHandler, see getCurrentPath()

◆ storePreset() [2/2]

void al::PresetHandler::storePreset ( std::string  name)

Stores preset.

Parameters
namethe name of the preset

Since all presets are assinged an index, calling this function will give the preset a free index and then call storePreset(index, name). If the preset name already exists, it will overwrite the existing preset without assigning a new index.

◆ useCallbacks()

void al::PresetHandler::useCallbacks ( bool  use)
inline

useCallbacks determines whether to call the internal callbacks

Parameters
useThe callbacks set by registerStoreCallback() and registerPresetCallback() are only called if this is set to true. The value is true by default.

Definition at line 293 of file al_PresetHandler.hpp.


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