Krotos Modules 3
Loading...
Searching...
No Matches
krotos::Kwidget Class Referenceabstract

#include <Kwidget.h>

Inheritance diagram for krotos::Kwidget:
krotos::ResourceLock krotos::Kwidget_Adsr krotos::Kwidget_AudioOut krotos::Kwidget_ConvolutionReverb krotos::Kwidget_CoreEngine krotos::Kwidget_Filter krotos::Kwidget_Lfo krotos::Kwidget_MacroControls krotos::Kwidget_MacroSlider krotos::Kwidget_MoogVcf krotos::Kwidget_OfflineAnalyser krotos::Kwidget_Pan krotos::Kwidget_PhaseVocoder krotos::Kwidget_Recorder krotos::Kwidget_Reformer krotos::Kwidget_SAFilter krotos::Kwidget_Saturation krotos::Kwidget_Sawtooth krotos::Kwidget_Scaledadsr krotos::Kwidget_Sine krotos::Kwidget_Template krotos::Kwidget_TriggerButton krotos::Kwidget_XyPad

Classes

struct  Constants
 
class  ParameterInfo
 Holds the information needed to create a new Kwidget parameter. More...
 

Public Types

enum  DragID_Index { KwidgetID = 0 , ParameterID = 1 }
 

Public Member Functions

 Kwidget (const String &kwidgetType, const String &kwidgetID)
 
virtual ~Kwidget ()=default
 
void init ()
 
std::unique_ptr< KwidgetProcessorcreateVoice ()
 
std::unique_ptr< KwidgetGUIcreateControls ()
 
KwidgetProcessorgetVoice (int idx) const
 
int getNumVoices () const
 
KwidgetProcessorgetActiveVoice () const
 
virtual void noteOn (int voiceIdx, int midiNote, float velocity)
 
virtual void noteOff (int voiceIdx, float velocity)
 
virtual void noteCleared (int voiceIdx)
 
virtual bool isActive (int voiceIdx)
 
void addModulator (const String &paramID, Kwidget *modulator, int modulatorIdx, float depth=0.99f, KAttachment::Polarity=KAttachment::Polarity::Bipolar)
 
void removeModulator (const String &paramID, Kwidget *modulator, int modulatorIdx)
 
void setModulatorDepth (const String &paramID, Kwidget *modulator, int modulatorIdx, float depth)
 
void setModulatorPolarity (const String &paramID, Kwidget *modulator, int modulatorIdx, KAttachment::Polarity polarity)
 
const std::vector< std::shared_ptr< KParameter > > & getParameters () const
 
KParametergetParameter (const String &parameterID) const noexcept
 Get a raw pointer to a KParameter belonging to this Kwidget's KwidgetProcessor. Useful for low overhead direct parameter access.
 
std::shared_ptr< KParametergetParameterToAttach (const String &parameterID) const noexcept
 Get a shared pointer to a KParameter, for use with KParameter::Listener objects and situations where the parameter lifetime goes beyond local scope.
 
CustomParametergetCustomParameter (const String &parameterID)
 
CustomParameterTreegetCustomParameterTree (const Identifier &type)
 Get a CustomParameterTree belonging to this Kwidget.
 
template<typename T >
T * getCustomParameter (const Identifier &type)
 Get the CustomParameterTree subclass object of the specified type.
 
void notifyAllParametersListeners ()
 Call every parameter's value changed listeners with their current values.
 
const ValueTree & getState ()
 
virtual void setState (const ValueTree &newState, KwidgetAudioProcessor &processor)
 
void flushState ()
 
bool isModulator () const
 
int getNumModulators () const
 
const String & getKwidgetType () const
 
const String & getKwidgetID () const
 
const String & getKwidgetVersionFromCurrentState () const
 
String getKwidgetVersion () const
 
virtual const String & getKwidgetLabel ()
 
StringArray getDragID (const String &parameterID)
 
virtual size_t numGUIImplementations ()
 
virtual String getGuiName (int)
 
virtual void createNestedKwidgets (KwidgetAudioProcessor &)
 
bool isAChildKwidget ()
 
std::vector< Kwidget * > & getChildKwidgets ()
 
bool isStateChanging ()
 
void addChildKwidget (Kwidget *child)
 
void removeChildKwidgetFromTree (String kwidgetID)
 
KwidgetfindChildKwidget (String kiwdgetID)
 
void addParameterCallback (const String &paramID, std::function< void(float)> callback)
 
void addVersionedParameterCallback (StringRef kwidgetVersionTheParameterChangedIn, const String &paramID, std::function< void(float)> callback)
 Add an action to be performed when a specified parameter of a specific kwidget version changes value. This can be used to implement backwards compatibility when older versions of the kwidget state are loaded, and the parameters in newer versions may have been changed or removed.
 
int getTemplateID ()
 
- Public Member Functions inherited from krotos::ResourceLock
 ResourceLock ()
 
bool requestAccess (const StringRef id)
 Called by a client to request access to the resource.
 
bool hasAccess (const StringRef id) const
 Called by a client to enquire whether it has access to the resource.
 
void finishedAccessing (const StringRef id)
 Called by a client to inform the resource that it no longer needs access.
 
void setAccessible (bool isAccessible)
 Called by the resource to grant or deny access to clients.
 

Static Public Member Functions

static String getParentID (String childKwidgetID)
 

Protected Member Functions

virtual std::vector< ParameterInfocreateParameters ()=0
 
virtual std::unique_ptr< KwidgetProcessorcreateProcessor ()=0
 
virtual std::unique_ptr< KwidgetGUIcreateGUI ()=0
 
void addChildGuis (std::unique_ptr< KwidgetGUI > &parentGui)
 
CustomParametercreateAndAddCustomParameter (const String &paramID, const var &value)
 
template<typename T >
T * createAndAddCustomParameter (const Identifier &type)
 Create a highly customizable piece of state for this Kwidget by appending a subclass of CustomParameterTree to this Kwidget's state.
 
void setKwidgetVersion (const String &kwidgetVersionString)
 

Protected Attributes

std::vector< Kwidget * > m_childKwidgets
 

Private Member Functions

KParametercreateAndAddParameter (const ParameterInfo &info)
 

Private Attributes

const String m_kwidgetType
 
const String m_kwidgetID
 
String m_kwidgetStateVersion
 
ValueTree m_kwidgetTree
 
ValueTree m_paramTree
 
ValueTree m_customParamTree
 
ValueTree m_childTree
 
ValueTree m_customDataTree
 
std::vector< std::shared_ptr< KParameter > > m_parameters
 
std::map< String, int > m_parameterIDs
 
Array< KwidgetProcessor * > m_processors
 
KwidgetProcessorm_activeVoice {nullptr}
 
std::unique_ptr< KwidgetProcessorm_initialVoice
 
OwnedArray< CustomParameterm_customParameters
 
std::map< String, int > m_customParameterIDs
 
OwnedArray< CustomParameterTreem_customParameterTrees
 
std::map< Identifier, int > m_customParameterTreeTypes
 
OwnedArray< KParameter::AudioListenerObjectm_parameterCallbacks
 
bool m_stateChanging {false}
 

Member Enumeration Documentation

◆ DragID_Index

Enumerator
KwidgetID 
ParameterID 

Constructor & Destructor Documentation

◆ Kwidget()

krotos::Kwidget::Kwidget ( const String & kwidgetType,
const String & kwidgetID )

Kwidget constructor. This must be called in the constructor of any child classes.

Parameters
kwidgetTypeA unique name for the type of Kwidget (e.g. "Sine").
kwidgetIDA unique name for this particular Kwidget instance (e.g. "Sine0").

◆ ~Kwidget()

virtual krotos::Kwidget::~Kwidget ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addChildGuis()

void krotos::Kwidget::addChildGuis ( std::unique_ptr< KwidgetGUI > & parentGui)
protected

◆ addChildKwidget()

void krotos::Kwidget::addChildKwidget ( Kwidget * child)

◆ addModulator()

void krotos::Kwidget::addModulator ( const String & paramID,
Kwidget * modulator,
int modulatorIdx,
float depth = 0.99f,
KAttachment::Polarity polarity = KAttachment::Polarity::Bipolar )

Add a modulator to one of the parameters owned by this Kwidget.

◆ addParameterCallback()

void krotos::Kwidget::addParameterCallback ( const String & paramID,
std::function< void(float)> callback )

Add an action to be performed when a specified parameter changes value.

Parameters
paramIDThe ID of the parameter to listen to.
callbackThe action to be performed when the parameter changes value.

◆ addVersionedParameterCallback()

void krotos::Kwidget::addVersionedParameterCallback ( StringRef kwidgetVersionTheParameterChangedIn,
const String & paramID,
std::function< void(float)> callback )

Add an action to be performed when a specified parameter of a specific kwidget version changes value. This can be used to implement backwards compatibility when older versions of the kwidget state are loaded, and the parameters in newer versions may have been changed or removed.

Parameters
kwidgetVersionTheParameterChangedInThe version of the Kwidget that introduced the parameter change. For example, if version "1.1" were the new version of the kwidget wherein the parameter was changed, the kwidgetVersion would be "1.1"
paramIDThe ID of the parameter to listen to.
callbackThe action to be performed when the parameter changes value.

◆ createAndAddCustomParameter() [1/2]

template<typename T >
T * krotos::Kwidget::createAndAddCustomParameter ( const Identifier & type)
protected

Create a highly customizable piece of state for this Kwidget by appending a subclass of CustomParameterTree to this Kwidget's state.

Your subclass should provide the high level methods, type safety and listener actions that your custom data structure needs. You can also use the base CustomParameterTree, however this should only be for simple uses, as the base class only offers a limited selection of wrapper methods around the underlying ValueTree.

Template Parameters
TThe type of the CustomParameterTree subclass to be created.
Parameters
typeA unique Identifier for the custom tree type.
Returns
A pointer to the created CustomParameterTree subclass object. This can be used to get and set tree properties and to set up change listeners.
Note
T must be a subclass of CustomParameterTree.
CustomParameterTrees should have unique types. If you need multiple instances of the same child, create a CustomParameterTree and add them as children.

◆ createAndAddCustomParameter() [2/2]

CustomParameter * krotos::Kwidget::createAndAddCustomParameter ( const String & paramID,
const var & value )
protected

Create a custom piece of state for this Kwidget. This will create a new ValueTree and append it to this Kwidget's state.

Parameters
paramIDA unique String identifying the new parameter.
valueThe initial value of the new parameter.
Returns
A pointer to the new CustomParameter object. This can be used to get and set the parameter value, and to listen for parameter changes.

◆ createAndAddParameter()

KParameter * krotos::Kwidget::createAndAddParameter ( const ParameterInfo & info)
private

◆ createControls()

std::unique_ptr< KwidgetGUI > krotos::Kwidget::createControls ( )

Creates an instance of this Kwidget's UI, which can be added to the main plugin UI to control the parameters of this Kwidget.

◆ createGUI()

◆ createNestedKwidgets()

virtual void krotos::Kwidget::createNestedKwidgets ( KwidgetAudioProcessor & )
inlinevirtual

override so your kwidget can create its own nested kwidgets

Reimplemented in krotos::Kwidget_CoreEngine, and krotos::Kwidget_Reformer.

◆ createParameters()

◆ createProcessor()

◆ createVoice()

std::unique_ptr< KwidgetProcessor > krotos::Kwidget::createVoice ( )

Creates a voice and exports the KwidgetProcessor object for use in an AudioProcessorGraph.

◆ findChildKwidget()

Kwidget * krotos::Kwidget::findChildKwidget ( String kiwdgetID)

◆ flushState()

void krotos::Kwidget::flushState ( )

This function updates this Kwidget's ValueTree object with the current parameter values. It should be called directly before obtaining a copy of the Kwidget's state, such as when saving a preset.

◆ getActiveVoice()

KwidgetProcessor * krotos::Kwidget::getActiveVoice ( ) const
inline

Get a pointer to the most recently used voice.

◆ getChildKwidgets()

std::vector< Kwidget * > & krotos::Kwidget::getChildKwidgets ( )
inline

◆ getCustomParameter() [1/2]

template<typename T >
T * krotos::Kwidget::getCustomParameter ( const Identifier & type)

Get the CustomParameterTree subclass object of the specified type.

Template Parameters
TThe type of the CustomParameterTree subclass to retrieve.
Parameters
typeA unique Identifier for the custom tree type.
Returns
A pointer to the CustomParameterTree subclass object of the specified type, or nullptr if the type is not found.
Note
T must be a subclass of CustomParameterTree.

◆ getCustomParameter() [2/2]

CustomParameter * krotos::Kwidget::getCustomParameter ( const String & parameterID)

Get a CustomParameter belonging to this Kwidget's KwidgetProcessor.

◆ getCustomParameterTree()

CustomParameterTree * krotos::Kwidget::getCustomParameterTree ( const Identifier & type)

Get a CustomParameterTree belonging to this Kwidget.

Parameters
typeThe name ("type") of the CustomParameterTree to find
Returns
A pointer to the CustomParameterTree object. You can use this to assign listeners etc.

◆ getDragID()

StringArray krotos::Kwidget::getDragID ( const String & parameterID)

Returns a String Array containing the current KwidgetID and ParameterID. The enum DragID_Index should be used to index the elements within this array

◆ getGuiName()

virtual String krotos::Kwidget::getGuiName ( int )
inlinevirtual

override to return the names of the Gui representation

Reimplemented in krotos::Kwidget_CoreEngine, and krotos::Kwidget_Reformer.

◆ getKwidgetID()

const String & krotos::Kwidget::getKwidgetID ( ) const

Get a reference to the unique Kwidget ID.

◆ getKwidgetLabel()

const String & krotos::Kwidget::getKwidgetLabel ( )
virtual

Returns a user facing label for the kwidget. By default, this returns the kwidget type. Override this to return a neatly formatted string for a kwidget.

Reimplemented in krotos::Kwidget_MacroSlider.

◆ getKwidgetType()

const String & krotos::Kwidget::getKwidgetType ( ) const

Get a reference to the type of the Kwidget.

◆ getKwidgetVersion()

String krotos::Kwidget::getKwidgetVersion ( ) const

◆ getKwidgetVersionFromCurrentState()

const String & krotos::Kwidget::getKwidgetVersionFromCurrentState ( ) const

Get the version number of the current loaded state of this kwidget

Returns
string of the two digit kwidget version number e.g. "1.0"

◆ getNumModulators()

int krotos::Kwidget::getNumModulators ( ) const

Get the number of Modulator objects used by this Kwidget.

◆ getNumVoices()

int krotos::Kwidget::getNumVoices ( ) const

Get the total number of voices.

◆ getParameter()

KParameter * krotos::Kwidget::getParameter ( const String & parameterID) const
noexcept

Get a raw pointer to a KParameter belonging to this Kwidget's KwidgetProcessor. Useful for low overhead direct parameter access.

Parameters
parameterIDThe ID of the parameter to retrieve.
Returns
A raw pointer to the KParameter.
Warning
The returned pointer is owned by this Kwidget. Avoid using it in any context outside of the Kwidget lifetime, for example attaching Listeners. For that, use getParameterToAttach and std::weak_ptr instead.

◆ getParameters()

const std::vector< std::shared_ptr< KParameter > > & krotos::Kwidget::getParameters ( ) const

Get the list of KParameters owned by this Kwidget.

◆ getParameterToAttach()

std::shared_ptr< KParameter > krotos::Kwidget::getParameterToAttach ( const String & parameterID) const
noexcept

Get a shared pointer to a KParameter, for use with KParameter::Listener objects and situations where the parameter lifetime goes beyond local scope.

Parameters
parameterIDThe ID of the parameter to retrieve.
Returns
A shared_ptr to the KParameter.

◆ getParentID()

String krotos::Kwidget::getParentID ( String childKwidgetID)
static

Get the ID of the parent of a nested kwidget

Parameters
[in]childKwidgetIDString ID of the child kwidget
Returns
The ID for the parent kwidget, or empty if no parent was found

◆ getState()

const ValueTree & krotos::Kwidget::getState ( )

Get a const reference to the ValueTree that this Kwidget is using to hold its state.

◆ getTemplateID()

int krotos::Kwidget::getTemplateID ( )

Returns the ID of this kwidgets parent template, if it has one. If not, returns -1.

◆ getVoice()

KwidgetProcessor * krotos::Kwidget::getVoice ( int idx) const

Get a pointer to one of this Kwidget's voices.

◆ init()

void krotos::Kwidget::init ( )

Initialises the parameters of the Kwidget. This should be called in the first line of the constructor of any concrete child classes.

◆ isAChildKwidget()

bool krotos::Kwidget::isAChildKwidget ( )

◆ isActive()

bool krotos::Kwidget::isActive ( int voiceIdx)
virtual

◆ isModulator()

bool krotos::Kwidget::isModulator ( ) const

Returns true if this Kwidget is a modulator.

◆ isStateChanging()

bool krotos::Kwidget::isStateChanging ( )
inline

override to return a pointer to the primary Gui for this kwidget

◆ noteCleared()

void krotos::Kwidget::noteCleared ( int voiceIdx)
virtual

Send a message to a particular voice that it has been turned off and will receive no more calls to its process function.

Parameters
voiceIdxThe index of the voice that is being cleared.

Reimplemented in krotos::Kwidget_CoreEngine, and krotos::Kwidget_Reformer.

◆ noteOff()

void krotos::Kwidget::noteOff ( int voiceIdx,
float velocity )
virtual

Send a 'note off' message to a particular voice. Note: Note on and off messages do not by default get sent to child Kwidgets parents of child kwidgets can override these methods and pass the messages to their childern if required If you do override, remember to call the base class first from your new overridden method

Parameters
voiceIdxThe index of the voice you would like to turn on.
velocityThe velocity of the note event.

Reimplemented in krotos::Kwidget_CoreEngine, and krotos::Kwidget_Reformer.

◆ noteOn()

void krotos::Kwidget::noteOn ( int voiceIdx,
int midiNote,
float velocity )
virtual

Send a 'note on' message to a particular voice. Note: Note on and off messages do not by default get sent to child Kwidgets parents of child kwidgets can override these methods and pass the messages to their childern if required If you do override, remember to call the base class first from your new overridden method

Parameters
voiceIdxThe index of the voice you would like to turn on.
midiNoteThe integer value of the MIDI note to use.
velocityThe velocity of the note event.

Reimplemented in krotos::Kwidget_CoreEngine, and krotos::Kwidget_Reformer.

◆ notifyAllParametersListeners()

void krotos::Kwidget::notifyAllParametersListeners ( )

Call every parameter's value changed listeners with their current values.

◆ numGUIImplementations()

virtual size_t krotos::Kwidget::numGUIImplementations ( )
inlinevirtual

◆ removeChildKwidgetFromTree()

void krotos::Kwidget::removeChildKwidgetFromTree ( String kwidgetID)

◆ removeModulator()

void krotos::Kwidget::removeModulator ( const String & paramID,
Kwidget * modulator,
int modulatorIdx )

Remove a modulator from one of the parameters owned by this Kwidget.

◆ setKwidgetVersion()

void krotos::Kwidget::setKwidgetVersion ( const String & kwidgetVersionString)
protected

Set the kwidget version, by default this is "1.0" This should be used when a kwidget is changed in such a way that it is no longer compatible with a previous version.

  • Parameters
    kwidgetVersionStringa version number with two digits separated by a period e.g. "1.1"

◆ setModulatorDepth()

void krotos::Kwidget::setModulatorDepth ( const String & paramID,
Kwidget * modulator,
int modulatorIdx,
float depth )

◆ setModulatorPolarity()

void krotos::Kwidget::setModulatorPolarity ( const String & paramID,
Kwidget * modulator,
int modulatorIdx,
KAttachment::Polarity polarity )

◆ setState()

void krotos::Kwidget::setState ( const ValueTree & newState,
KwidgetAudioProcessor & processor )
virtual

Set the state of the Kwidget using a ValueTree (probably one obtained from the getState() function).

Member Data Documentation

◆ m_activeVoice

KwidgetProcessor* krotos::Kwidget::m_activeVoice {nullptr}
private

◆ m_childKwidgets

std::vector<Kwidget*> krotos::Kwidget::m_childKwidgets
protected

◆ m_childTree

ValueTree krotos::Kwidget::m_childTree
private

◆ m_customDataTree

ValueTree krotos::Kwidget::m_customDataTree
private

◆ m_customParameterIDs

std::map<String, int> krotos::Kwidget::m_customParameterIDs
private

◆ m_customParameters

OwnedArray<CustomParameter> krotos::Kwidget::m_customParameters
private

◆ m_customParameterTrees

OwnedArray<CustomParameterTree> krotos::Kwidget::m_customParameterTrees
private

◆ m_customParameterTreeTypes

std::map<Identifier, int> krotos::Kwidget::m_customParameterTreeTypes
private

◆ m_customParamTree

ValueTree krotos::Kwidget::m_customParamTree
private

◆ m_initialVoice

std::unique_ptr<KwidgetProcessor> krotos::Kwidget::m_initialVoice
private

◆ m_kwidgetID

const String krotos::Kwidget::m_kwidgetID
private

◆ m_kwidgetStateVersion

String krotos::Kwidget::m_kwidgetStateVersion
private

◆ m_kwidgetTree

ValueTree krotos::Kwidget::m_kwidgetTree
private

◆ m_kwidgetType

const String krotos::Kwidget::m_kwidgetType
private

◆ m_parameterCallbacks

OwnedArray<KParameter::AudioListenerObject> krotos::Kwidget::m_parameterCallbacks
private

◆ m_parameterIDs

std::map<String, int> krotos::Kwidget::m_parameterIDs
private

◆ m_parameters

std::vector<std::shared_ptr<KParameter> > krotos::Kwidget::m_parameters
private

◆ m_paramTree

ValueTree krotos::Kwidget::m_paramTree
private

◆ m_processors

Array<KwidgetProcessor*> krotos::Kwidget::m_processors
private

◆ m_stateChanging

bool krotos::Kwidget::m_stateChanging {false}
private

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