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

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="#")
 
KwidgetgetKwidget (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 &paramID, float depth=DefaultModDepth, KAttachment::Polarity=KAttachment::Polarity::Bipolar)
 
void removeModulation (const String &sourceID, int modulatorIdx, const String &destinationID, const String &paramID)
 
void removeModulation (ValueTree modulationChildTree)
 
void setModulationDepth (const String &sourceID, int modulatorIdx, const String &destinationID, const String &paramID, float depth)
 
void setModulationPolarity (const String &src, int modulatorIdx, const String &dest, const String &paramID, 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 &paramTree, 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 &parameterID, 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 &paramTreeGeneric, 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 &paramID)
 
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.
 

Detailed Description

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:

  1. Audio parameters - ex. Dry/wet mix, oscillator frequency
  2. Custom Kwidget data - ex. Reverb IR path
  3. Audio and modulation connections

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.

Member Typedef Documentation

◆ Property

◆ Tag

Constructor & Destructor Documentation

◆ ParameterManager()

krotos::ParameterManager::ParameterManager ( AudioProcessor & processor,
int numParams = 1000,
const String & namePrefix = "#" )

Constructor.

Parameters
processorThe AudioProcessor to connect to.
numParamsThe number of GenericParameters to instantiate.
namePrefixA String to use in the name of each GenericParameter. The full name will be "[namePrefix][parameterIndex]".

Member Function Documentation

◆ addConnection()

void krotos::ParameterManager::addConnection ( const String & sourceID,
const String & destinationID )

Try to connect the audio of two Kwidgets.

Parameters
sourceIDThe KwidgetID of the source Kwidget.
destinationIDThe KwidgetID of the destination Kwidget.

◆ addCustomDataNode()

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

◆ addGenericParameters()

void krotos::ParameterManager::addGenericParameters ( )
private

◆ addKwidget()

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.

Parameters
kwidgetThe kwidget to add to the state.
useEndParamsAssigns parameters from the end, rather than the start of the generic parameter array. This is a workaround to prevent parameter collisions with "dynamic" kwidgets.
isChildKwidgetIs 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.
Returns
Operation was successful.

◆ addModulation()

ValueTree krotos::ParameterManager::addModulation ( const String & sourceID,
int modulatorIdx,
const String & destinationID,
const String & paramID,
float depth = DefaultModDepth,
KAttachment::Polarity polarity = KAttachment::Polarity::Bipolar )

Adds a new modulation instance.

Parameters
sourceIDThe ID of the source (modulator) Kwidget.
modulatorIdxThe modulator to use from the source Kwidget.
destinationIDThe ID of the Kwidget whose parameter will be modulated.
paramIDThe ID of the parameter being modulated.

◆ addNonStaticConnections()

void krotos::ParameterManager::addNonStaticConnections ( juce::ValueTree & newConnectionTree)

◆ attachParameters()

void krotos::ParameterManager::attachParameters ( Kwidget * kwidget,
const ValueTree & kwidgetTree )
private

◆ clearConnections()

void krotos::ParameterManager::clearConnections ( )

Remove all connections.

◆ clearKwidgets()

void krotos::ParameterManager::clearKwidgets ( )

Remove all Kwidgets, essentially resetting everything.

◆ clearModulation()

void krotos::ParameterManager::clearModulation ( )

Removes all active modulation instances.

◆ clearModulationExcept()

void krotos::ParameterManager::clearModulationExcept ( const String & allowedSource)

Removes all active modulation instances besides the specified.

◆ connectionExists()

bool krotos::ParameterManager::connectionExists ( const String & sourceID,
const String & destID )

Test to see if a connection between the supplied source and destination ids exists

Parameters
sourceIDThe KwidgetID of the source Kwidget.
destinationIDThe KwidgetID of the destination Kwidget.
Returns
bool Returns true if the connection exists

◆ copyModulationTree()

void krotos::ParameterManager::copyModulationTree ( ValueTree modTree)
private

◆ createKwidgetTree()

ValueTree krotos::ParameterManager::createKwidgetTree ( Kwidget * k,
bool useEndParams = false )
private

◆ debugState()

void krotos::ParameterManager::debugState ( ) const

Prints out an XML String of the current state to the console.

◆ detachParameters()

void krotos::ParameterManager::detachParameters ( Kwidget * kwidget,
const ValueTree & kwidgetTree )
private

◆ findGenericParameters()

std::vector< int > krotos::ParameterManager::findGenericParameters ( int numParametersToLink,
bool useEndParams )
private

◆ flagUsedIndexes()

bool krotos::ParameterManager::flagUsedIndexes ( juce::ValueTree & kwidget,
bool repairEnabled )
private

◆ generateKwidgetID()

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.

Parameters
kwidgetTypeThe 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
idModifierA 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 ""

◆ getConnectionTree()

const ValueTree & krotos::ParameterManager::getConnectionTree ( )
inline

◆ getCustomDataTree()

ValueTree & krotos::ParameterManager::getCustomDataTree ( )

Attempts to find and return a reference to a custom data in the custom data tree.

Parameters
typeThe name of the

◆ getKwidget()

Kwidget * krotos::ParameterManager::getKwidget ( const String & kwidgetID)

Get a pointer to an active Kwidget.

◆ getKwidgetsTree()

const ValueTree & krotos::ParameterManager::getKwidgetsTree ( )

◆ getModulationTree() [1/2]

const ValueTree & krotos::ParameterManager::getModulationTree ( )

◆ getModulationTree() [2/2]

ValueTree krotos::ParameterManager::getModulationTree ( const String & sourceID,
int modulatorIdx,
const String & destinationID,
const String & paramID )
private

◆ getProcessor()

AudioProcessor & krotos::ParameterManager::getProcessor ( )

Get the AudioProcessor that this ParameterManager & AudioProcessorValueTreeState are attached to (and owned by).

◆ getProcessorState()

AudioProcessorValueTreeState & krotos::ParameterManager::getProcessorState ( )

Get a reference to the AudioProcessorValueTreeState object that holds all of the parameters connected to the DAW.

◆ getState()

ValueTree & krotos::ParameterManager::getState ( )

Get a reference to the top-level state ValueTree used by this ParameterManager.

◆ getUndoManager()

UndoManager * krotos::ParameterManager::getUndoManager ( )

Get a pointer to the UndoManager, for tracking actions throughout the plugin.

◆ getUnusedLinkIndex()

int krotos::ParameterManager::getUnusedLinkIndex ( )
private

◆ initialiseKwidgetIDUsageTable()

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.

Parameters
stateThe state to be trawled
repairEnabledSet true if you want invalid IDs to be repaired (note no action will be taken at present)
Returns
returns bool indicating whether link indices are valid

◆ initialiseLinkIndexUsageTable()

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

Parameters
stateThe state to be trawled
repairEnabledSet true if you want invalid parameters to be repaired
Returns
returns bool indicating whether link indices are valid

◆ isAStaticConnectionDestination()

const bool krotos::ParameterManager::isAStaticConnectionDestination ( const String & destName)
inline

Returns true if the destName you supplied is the name of a static connection destination.

Parameters
destName
Returns

◆ registerKwidget()

bool krotos::ParameterManager::registerKwidget ( juce::ValueTree & kwidget,
StringArray & kwidgetIDArray,
bool repairEnabled )
private

◆ removeConnection()

void krotos::ParameterManager::removeConnection ( const String & sourceID,
const String & destinationID )

Remove a single connection between two Kwidgets.

Parameters
sourceIDThe KwidgetID of the source Kwidget.
destinationIDThe KwidgetID of the destination Kwidget.

◆ removeConnectionsInvolving()

void krotos::ParameterManager::removeConnectionsInvolving ( const String & kwidgetID)

Remove all connections going in to or coming out of a Kwidget.

◆ removeKwidget()

void krotos::ParameterManager::removeKwidget ( const String & kwidgetID)

Remove a Kwidget.

◆ removeModulation() [1/2]

void krotos::ParameterManager::removeModulation ( const String & sourceID,
int modulatorIdx,
const String & destinationID,
const String & paramID )

Removes a modulation instance.

Parameters
sourceIDThe ID of the source (modulator) Kwidget.
modulatorIdxThe modulator to use from the source Kwidget.
destinationIDThe ID of the Kwidget whose parameter will be modulated.
paramIDThe ID of the parameter being modulated.

◆ removeModulation() [2/2]

void krotos::ParameterManager::removeModulation ( ValueTree modulationChildTree)

Remove modulation by child modulation tree

◆ removeModulationInvolving()

void krotos::ParameterManager::removeModulationInvolving ( const String & kwidgetID)

Removes all modulation instances going to or from a particular Kwidget.

◆ resetUndoManager()

void krotos::ParameterManager::resetUndoManager ( )

Resets the UndoManager by clearing any previously tracked actions.

◆ rewriteCustomParameterValue()

static Result krotos::ParameterManager::rewriteCustomParameterValue ( ValueTree & kwidgetTree,
const var & parameterID,
const var & newValue,
UndoManager * undoManager = nullptr )
static

◆ setCurrentState()

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.

Parameters
newStateThis should be a 'fresh' ValueTree, meaning it should not have any listeners and nothing else should own a reference to its SharedObject.
See also
ValueTree::createCopy

◆ setGenericParameterValue()

void krotos::ParameterManager::setGenericParameterValue ( ValueTree & paramTreeGeneric,
int index,
var newValue )
private

◆ setModulationDepth()

void krotos::ParameterManager::setModulationDepth ( const String & sourceID,
int modulatorIdx,
const String & destinationID,
const String & paramID,
float depth )

Sets the depth of a modulation instance.

Parameters
sourceIDThe ID of the source (modulator) Kwidget.
modulatorIdxThe modulator to use from the source Kwidget.
destinationIDThe ID of the Kwidget whose parameter will be modulated.
paramIDThe ID of the parameter being modulated.
depthThe depth of the modulation, must be in the range [-1, 1].

◆ setModulationPolarity()

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.

Parameters
sourceIDThe ID of the source (modulator) Kwidget.
modulatorIdxThe modulator to use from the source Kwidget.
destinationIDThe ID of the Kwidget whose parameter will be modulated.
paramIDThe ID of the parameter being modulated.
polarityThe polarity of modulation, either bipolar or unipolar.

◆ validateKwidgetState()

bool krotos::ParameterManager::validateKwidgetState ( ValueTree & kwidgetTree,
ValueTree & paramTree,
bool repairEnabled = false )

Checks a Kwidget state tree for errors

Parameters
kwidgetTreeThe tree to be tested
repairEnabledSet true if you require broken state to be repaired
Returns
Returns true if state is valid or has been made valid by repair

Member Data Documentation

◆ DefaultModDepth

const float krotos::ParameterManager::DefaultModDepth = 0.2f
static

◆ m_activeKwidgets

std::map<String, Kwidget*> krotos::ParameterManager::m_activeKwidgets
private

◆ m_connectionTree

ValueTree krotos::ParameterManager::m_connectionTree
private

◆ m_customDataTree

ValueTree krotos::ParameterManager::m_customDataTree
private

◆ m_genericParameters

std::vector<GenericParameter*> krotos::ParameterManager::m_genericParameters
private

◆ m_kwidgetData

std::map<Kwidget*, ValueTree> krotos::ParameterManager::m_kwidgetData
private

◆ m_kwidgetTree

ValueTree krotos::ParameterManager::m_kwidgetTree
private

◆ m_linkIndexAllocation

std::vector<bool> krotos::ParameterManager::m_linkIndexAllocation
private

◆ m_modulationTree

ValueTree krotos::ParameterManager::m_modulationTree
private

◆ m_numDigitsInGenericParamName

int krotos::ParameterManager::m_numDigitsInGenericParamName
private

◆ m_numGenericParameters

const int krotos::ParameterManager::m_numGenericParameters
private

◆ m_parameterNamePrefix

const String krotos::ParameterManager::m_parameterNamePrefix
private

◆ m_parentTree

ValueTree krotos::ParameterManager::m_parentTree
private

◆ m_processor

AudioProcessor& krotos::ParameterManager::m_processor
private

◆ m_processorTree

ValueTree krotos::ParameterManager::m_processorTree
private

◆ m_undoManager

UndoManager krotos::ParameterManager::m_undoManager
private

◆ m_vts

AudioProcessorValueTreeState krotos::ParameterManager::m_vts
private

◆ OnOffThreshold

const float krotos::ParameterManager::OnOffThreshold = 0.5f
static

The threshold at which a toggle, or "on/off" parameter should change from on to off stage.

◆ StaticConnectionDestinations

const StringArray krotos::ParameterManager::StaticConnectionDestinations
staticprivate
Initial value:
= {"Master", "AudioOut1", "AudioOut2", "AudioOut3",
"AudioOut4"}

Contains a list of the names of all the static connection destinations.


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