Allolib
1.0
C++ Components For Interactive Multimedia
|
The PresetHandler class handles sorting and recalling of presets. More...
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 ¶meterStates, 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... | |
PresetHandler & | registerParameter (ParameterMeta ¶meter) |
PresetHandler & | operator<< (ParameterMeta ¶m) |
PresetHandler & | registerParameterBundle (ParameterBundle &bundle) |
PresetHandler & | operator<< (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... | |
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.
al::PresetHandler::PresetHandler | ( | std::string | rootDirectory, |
bool | verbose = false |
||
) |
PresetHandler contructor.
rootDirectory | sets the root directory for preset and preset map storage |
verbose | if true, print diagnostic messages |
al::PresetHandler::PresetHandler | ( | TimeMasterMode | timeMasterMode = TimeMasterMode::TIME_MASTER_CPU , |
std::string | rootDirectory = "presets" , |
||
bool | verbose = false |
||
) |
Constructor with option to set time master mode.
timeMasterMode | Only 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() |
|
static |
Map QWERTY ascii keys to presets 0-49.
ascii | ascii code of the key to mapt |
offset | add an offset on output |
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.
ParameterStates al::PresetHandler::loadPresetValues | ( | std::string | name | ) |
load preset into parameter states data structure without setting values
name | name of the preset to load |
void al::PresetHandler::print | ( | ) |
Display information about preset handler, including path and registered parameters.
std::string al::PresetHandler::recallPreset | ( | int | index | ) |
Recall a preset by index number.
index |
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.
void al::PresetHandler::recallPreset | ( | std::string | name | ) |
Recall a preset by name.
name | The preset should be a file on disk in the PresetHandler's root directory and should have the ".preset" extension. See also setSubDirectory(). |
std::string al::PresetHandler::recallPresetSynchronous | ( | int | index | ) |
recall immediately (not using the morph thread)
index |
void al::PresetHandler::registerMorphTimeCallback | ( | Parameter::ParameterChangeCallback | cb | ) |
Register a callback to be notified when morph time parameter is changed.
cb | The callback function |
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.
cb | The callback function |
userData | data to be passed to the callback |
void al::PresetHandler::registerPresetMapCallback | ( | PresetMapCallback | cb | ) |
Register a callback to be notified when preset map cahges.
cb | The callback function |
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.
cb | The callback function |
userData | data to be passed to the callback |
bool al::PresetHandler::savePresetValues | ( | const ParameterStates & | values, |
std::string | presetName, | ||
bool | overwrite = true |
||
) |
save list of parameter states into text preset file
values | the values of parameters to store |
presetName | name of preset to store |
overwrite | true overwrites otherwise append unique number |
void al::PresetHandler::setInterpolatedPreset | ( | int | index1, |
int | index2, | ||
double | factor | ||
) |
Set parameters to values interpolated between two presets.
index1 | index of the first preset |
index2 | index of the second preset |
factor | A value between 0-1 to determine interpolation |
synchronous | The 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.
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.
parameter | address of parameter to skip |
skip | set to false if you want to remove from skip list |
This is used within loadPresetValues(), so it will affect both synchronous and asynchronous recall.
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
void al::PresetHandler::storePreset | ( | int | index, |
std::string | name = "" , |
||
bool | overwrite = true |
||
) |
Store preset at index. The name argument specifies the preset name.
index | |
name | |
overwrite | if 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()
void al::PresetHandler::storePreset | ( | std::string | name | ) |
Stores preset.
name | the 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.
|
inline |
useCallbacks determines whether to call the internal callbacks
use | The 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.