|
Krotos Modules 3
|
Holds the overall state of a plugin that uses Kwidgets, including parameters, custom parameters, connection data, and any other needed state items. More...
#include <ParameterManager.h>
Public Member Functions | |
| ParameterManager (AudioProcessor &processor, int numParams=1000, const String &namePrefix="#") | |
| Kwidget * | getKwidget (const String &kwidgetID) |
| bool | addKwidget (Kwidget *kwidget, bool useEndParams=false, bool isChildKwidget=false) |
| Add a new Kwidget to the state. This will add the kwidget to the internal state ValueTree and it's parameters to the AudioProcessorValueTreeState. | |
| void | removeKwidget (const String &kwidgetID) |
| void | clearKwidgets () |
| void | addConnection (const String &sourceID, const String &destinationID) |
| void | removeConnection (const String &sourceID, const String &destinationID) |
| void | removeConnectionsInvolving (const String &kwidgetID) |
| void | clearConnections () |
| bool | connectionExists (const String &sourceID, const String &destID) |
| ValueTree | addModulation (const String &sourceID, int modulatorIdx, const String &destinationID, const String ¶mID, float depth=DefaultModDepth, KAttachment::Polarity=KAttachment::Polarity::Bipolar) |
| void | removeModulation (const String &sourceID, int modulatorIdx, const String &destinationID, const String ¶mID) |
| void | removeModulation (ValueTree modulationChildTree) |
| void | setModulationDepth (const String &sourceID, int modulatorIdx, const String &destinationID, const String ¶mID, float depth) |
| void | setModulationPolarity (const String &src, int modulatorIdx, const String &dest, const String ¶mID, KAttachment::Polarity polarity) |
| void | removeModulationInvolving (const String &kwidgetID) |
| void | clearModulation () |
| void | clearModulationExcept (const String &allowedSource) |
| ValueTree & | getState () |
| const ValueTree & | getModulationTree () |
| const ValueTree & | getKwidgetsTree () |
| const ValueTree & | getConnectionTree () |
| const bool | isAStaticConnectionDestination (const String &destName) |
| Returns true if the destName you supplied is the name of a static connection destination. | |
| void | setCurrentState (const ValueTree &newState) |
| void | addNonStaticConnections (juce::ValueTree &newConnectionTree) |
| AudioProcessor & | getProcessor () |
| AudioProcessorValueTreeState & | getProcessorState () |
| UndoManager * | getUndoManager () |
| void | resetUndoManager () |
| void | debugState () const |
| void | addCustomDataNode (const ValueTree &customDataNode) |
| ValueTree & | getCustomDataTree () |
| bool | validateKwidgetState (ValueTree &kwidgetTree, ValueTree ¶mTree, bool repairEnabled) |
| bool | initialiseLinkIndexUsageTable (const ValueTree &state, bool repairEnabled) |
| bool | initialiseKwidgetIDUsageTable (const ValueTree &state, bool repairEnabled) |
| String | generateKwidgetID (const String &kwidgetType, const String &idModifier="", int typeInstanceLimit=0) |
Static Public Member Functions | |
| static Result | rewriteCustomParameterValue (ValueTree &kwidgetTree, const var ¶meterID, const var &newValue, UndoManager *undoManager=nullptr) |
Static Public Attributes | |
| static const float | DefaultModDepth = 0.2f |
| static const float | OnOffThreshold = 0.5f |
| The threshold at which a toggle, or "on/off" parameter should change from on to off stage. | |
Private Types | |
| using | Property = XmlType::Property |
| using | Tag = XmlType::Tag |
Private Member Functions | |
| int | getUnusedLinkIndex () |
| bool | flagUsedIndexes (juce::ValueTree &kwidget, bool repairEnabled) |
| bool | registerKwidget (juce::ValueTree &kwidget, StringArray &kwidgetIDArray, bool repairEnabled) |
| void | setGenericParameterValue (ValueTree ¶mTreeGeneric, int index, var newValue) |
| void | addGenericParameters () |
| std::vector< int > | findGenericParameters (int numParametersToLink, bool useEndParams) |
| ValueTree | createKwidgetTree (Kwidget *k, bool useEndParams=false) |
| void | attachParameters (Kwidget *kwidget, const ValueTree &kwidgetTree) |
| void | detachParameters (Kwidget *kwidget, const ValueTree &kwidgetTree) |
| ValueTree | getModulationTree (const String &sourceID, int modulatorIdx, const String &destinationID, const String ¶mID) |
| void | copyModulationTree (ValueTree modTree) |
Private Attributes | |
| std::vector< bool > | m_linkIndexAllocation |
| AudioProcessor & | m_processor |
| UndoManager | m_undoManager |
| AudioProcessorValueTreeState | m_vts |
| std::vector< GenericParameter * > | m_genericParameters |
| ValueTree | m_parentTree |
| ValueTree | m_processorTree |
| ValueTree | m_kwidgetTree |
| ValueTree | m_connectionTree |
| ValueTree | m_modulationTree |
| ValueTree | m_customDataTree |
| std::map< Kwidget *, ValueTree > | m_kwidgetData |
| std::map< String, Kwidget * > | m_activeKwidgets |
| const int | m_numGenericParameters |
| const String | m_parameterNamePrefix |
| int | m_numDigitsInGenericParamName |
Static Private Attributes | |
| static const StringArray | StaticConnectionDestinations |
| Contains a list of the names of all the static connection destinations. | |
Holds the overall state of a plugin that uses Kwidgets, including parameters, custom parameters, connection data, and any other needed state items.
The overall state of the plugin, including current Kwidgets, connections, parameter links, etc.
The data handled by this class can be divided into three categories:
This class contains an instance of AudioProcessorValueTreeState, which it loads a large number of GenericParameter instances into. This provides a way for Kwidgets to attach and detach their parameters from the state during runtime.
Each Kwidget owns a ValueTree holding its state. When a Kwidget is added, this ValueTree is appended to the overall plugin state contained in this class. This ValueTree state object is used to save/load the state of the plugin.
|
private |
|
private |
| krotos::ParameterManager::ParameterManager | ( | AudioProcessor & | processor, |
| int | numParams = 1000, | ||
| const String & | namePrefix = "#" ) |
Constructor.
| processor | The AudioProcessor to connect to. |
| numParams | The number of GenericParameters to instantiate. |
| namePrefix | A String to use in the name of each GenericParameter. The full name will be "[namePrefix][parameterIndex]". |
| void krotos::ParameterManager::addConnection | ( | const String & | sourceID, |
| const String & | destinationID ) |
| void krotos::ParameterManager::addCustomDataNode | ( | const ValueTree & | customDataNode | ) |
Add a child to the custom data tree. Use this to save any custom data specific to the plugin to state.
@param customDataNode A ValueTree of your custom data, to be added as a child to
the customDataTree. The custom data tree is intended
to be generic, so this can be in any format you want.
To fetch your tree, @see getCustomDataTree
|
private |
| bool krotos::ParameterManager::addKwidget | ( | Kwidget * | kwidget, |
| bool | useEndParams = false, | ||
| bool | isChildKwidget = false ) |
Add a new Kwidget to the state. This will add the kwidget to the internal state ValueTree and it's parameters to the AudioProcessorValueTreeState.
| kwidget | The kwidget to add to the state. |
| useEndParams | Assigns parameters from the end, rather than the start of the generic parameter array. This is a workaround to prevent parameter collisions with "dynamic" kwidgets. |
| isChildKwidget | Is this kwidget a "child" of another kwidget? Setting this to true will not append the kwidgets state tree to the primary tree, as it is already nested & managed in it's parent tree. |
| ValueTree krotos::ParameterManager::addModulation | ( | const String & | sourceID, |
| int | modulatorIdx, | ||
| const String & | destinationID, | ||
| const String & | paramID, | ||
| float | depth = DefaultModDepth, | ||
| KAttachment::Polarity | polarity = KAttachment::Polarity::Bipolar ) |
| void krotos::ParameterManager::addNonStaticConnections | ( | juce::ValueTree & | newConnectionTree | ) |
|
private |
| void krotos::ParameterManager::clearConnections | ( | ) |
Remove all connections.
| void krotos::ParameterManager::clearKwidgets | ( | ) |
Remove all Kwidgets, essentially resetting everything.
| void krotos::ParameterManager::clearModulation | ( | ) |
Removes all active modulation instances.
| void krotos::ParameterManager::clearModulationExcept | ( | const String & | allowedSource | ) |
Removes all active modulation instances besides the specified.
| bool krotos::ParameterManager::connectionExists | ( | const String & | sourceID, |
| const String & | destID ) |
|
private |
|
private |
| void krotos::ParameterManager::debugState | ( | ) | const |
Prints out an XML String of the current state to the console.
|
private |
|
private |
|
private |
| String krotos::ParameterManager::generateKwidgetID | ( | const String & | kwidgetType, |
| const String & | idModifier = "", | ||
| int | typeInstanceLimit = 0 ) |
Use this method to create new Kwidget IDs. The idea here is to centralise all Kwidget ID generation and keep it consistent, not have is spread out all over the codebase.
| kwidgetType | The main string which forms the Kwidget ID, fka "baseID". Use the Kwidget type. A unique Kwidget ID will be generated based on kwidgetType, idModifier and maxSuffixes |
| idModifier | A short string to add extra info into the eventual Kwidget ID - the ID manager will incorporate this into the ID - eg as a prefix to indicate tab - T1, T2 etc Example of use: baseID = "CoreEngine", idModifier = "Tab1”, maxSuffixes = 100 returns ”Tab1CoreEngine<0-99>” Worth noting that although the example above is typical, this method might choose to apply different schemas to different baseIDs. @param typeInstanceLimit Maximum number of allowed instances of the given Kwidget Type. The value is suffixed onto the kwidget ID. @return Returns the new KwidgetID if succeeds, otherwise returns an empty String "" |
|
inline |
| ValueTree & krotos::ParameterManager::getCustomDataTree | ( | ) |
Attempts to find and return a reference to a custom data in the custom data tree.
| type | The name of the |
| Kwidget * krotos::ParameterManager::getKwidget | ( | const String & | kwidgetID | ) |
Get a pointer to an active Kwidget.
| const ValueTree & krotos::ParameterManager::getKwidgetsTree | ( | ) |
| const ValueTree & krotos::ParameterManager::getModulationTree | ( | ) |
|
private |
| AudioProcessor & krotos::ParameterManager::getProcessor | ( | ) |
Get the AudioProcessor that this ParameterManager & AudioProcessorValueTreeState are attached to (and owned by).
| AudioProcessorValueTreeState & krotos::ParameterManager::getProcessorState | ( | ) |
Get a reference to the AudioProcessorValueTreeState object that holds all of the parameters connected to the DAW.
| ValueTree & krotos::ParameterManager::getState | ( | ) |
Get a reference to the top-level state ValueTree used by this ParameterManager.
| UndoManager * krotos::ParameterManager::getUndoManager | ( | ) |
Get a pointer to the UndoManager, for tracking actions throughout the plugin.
|
private |
| bool krotos::ParameterManager::initialiseKwidgetIDUsageTable | ( | const ValueTree & | state, |
| bool | repairEnabled ) |
Trawls though all the Kwidget IDs in the supplied state and collates them in a StringArray m_kwidgetIDAllocation Where it finds a duplicate ID, it will flag the error When initialised this array will contain an exhaustive list of all kwidget IDs in the supplied state, including child kwidgets.
| state | The state to be trawled |
| repairEnabled | Set true if you want invalid IDs to be repaired (note no action will be taken at present) |
| bool krotos::ParameterManager::initialiseLinkIndexUsageTable | ( | const ValueTree & | state, |
| bool | repairEnabled ) |
Trawls though all the Kwidget params in the supplied state and where it finds a valid link index, sets the corresponing used entry in the m_linkIndexAllocation vector
| state | The state to be trawled |
| repairEnabled | Set true if you want invalid parameters to be repaired |
|
inline |
Returns true if the destName you supplied is the name of a static connection destination.
| destName |
|
private |
| void krotos::ParameterManager::removeConnection | ( | const String & | sourceID, |
| const String & | destinationID ) |
| void krotos::ParameterManager::removeConnectionsInvolving | ( | const String & | kwidgetID | ) |
Remove all connections going in to or coming out of a Kwidget.
| void krotos::ParameterManager::removeKwidget | ( | const String & | kwidgetID | ) |
Remove a Kwidget.
| void krotos::ParameterManager::removeModulation | ( | const String & | sourceID, |
| int | modulatorIdx, | ||
| const String & | destinationID, | ||
| const String & | paramID ) |
| void krotos::ParameterManager::removeModulation | ( | ValueTree | modulationChildTree | ) |
Remove modulation by child modulation tree
| void krotos::ParameterManager::removeModulationInvolving | ( | const String & | kwidgetID | ) |
Removes all modulation instances going to or from a particular Kwidget.
| void krotos::ParameterManager::resetUndoManager | ( | ) |
Resets the UndoManager by clearing any previously tracked actions.
|
static |
| void krotos::ParameterManager::setCurrentState | ( | const ValueTree & | newState | ) |
Load a new ValueTree into the state, such as when changing presets or loading the state from a saved session.
| newState | This should be a 'fresh' ValueTree, meaning it should not have any listeners and nothing else should own a reference to its SharedObject. |
|
private |
| void krotos::ParameterManager::setModulationDepth | ( | const String & | sourceID, |
| int | modulatorIdx, | ||
| const String & | destinationID, | ||
| const String & | paramID, | ||
| float | depth ) |
Sets the depth of a modulation instance.
| sourceID | The ID of the source (modulator) Kwidget. |
| modulatorIdx | The modulator to use from the source Kwidget. |
| destinationID | The ID of the Kwidget whose parameter will be modulated. |
| paramID | The ID of the parameter being modulated. |
| depth | The depth of the modulation, must be in the range [-1, 1]. |
| void krotos::ParameterManager::setModulationPolarity | ( | const String & | src, |
| int | modulatorIdx, | ||
| const String & | dest, | ||
| const String & | paramID, | ||
| KAttachment::Polarity | polarity ) |
Sets the polarity of a modulation instance.
| sourceID | The ID of the source (modulator) Kwidget. |
| modulatorIdx | The modulator to use from the source Kwidget. |
| destinationID | The ID of the Kwidget whose parameter will be modulated. |
| paramID | The ID of the parameter being modulated. |
| polarity | The polarity of modulation, either bipolar or unipolar. |
| bool krotos::ParameterManager::validateKwidgetState | ( | ValueTree & | kwidgetTree, |
| ValueTree & | paramTree, | ||
| bool | repairEnabled = false ) |
Checks a Kwidget state tree for errors
| kwidgetTree | The tree to be tested |
| repairEnabled | Set true if you require broken state to be repaired |
|
static |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
static |
The threshold at which a toggle, or "on/off" parameter should change from on to off stage.
|
staticprivate |
Contains a list of the names of all the static connection destinations.