Krotos Modules 3
Loading...
Searching...
No Matches
krotos::KAttachment Class Reference

Attaches to a KParameter to provide parameter smoothing and modulation. More...

#include <KAttachment.h>

Inheritance diagram for krotos::KAttachment:
krotos::Modulator::Listener

Classes

struct  Depth
 
class  ParameterUpdater
 

Public Types

enum  Polarity { Bipolar , Unipolar }
 

Public Member Functions

 KAttachment (std::shared_ptr< KParameter > paramToAttach, std::function< void(float)> updateFunction=nullptr)
 
 KAttachment (std::shared_ptr< KParameter > paramToAttach, float smoothingTimeSeconds, int updateRate, std::function< void(float)> updateFunction=nullptr)
 
 ~KAttachment () override
 
void prepare (double sampleRate, int samplesPerBlock)
 
bool nextBlock (int numSamples)
 
const float * data ()
 
bool needsUpdate () const
 
ParameterUpdatergetUpdater ()
 
void addModulator (Modulator *m, float depth=1.0f, Polarity polarity=Polarity::Bipolar)
 
void removeModulator (Modulator *m)
 
void setModulatorDepth (Modulator *m, float depth)
 
void setModulatorPolarity (Modulator *m, Polarity polarity)
 
void applyPendingUpdates ()
 
- Public Member Functions inherited from krotos::Modulator::Listener
virtual ~Listener ()=default
 

Private Types

enum  Mode { Discrete , Continuous }
 

Private Member Functions

void parameterValueChanged (int, float newValue) override
 
void parameterGestureChanged (int, bool) override
 
void sendInitialUpdate ()
 
void modulatorChanged (const Modulator *m) override
 
void updateSmoother ()
 

Private Attributes

std::weak_ptr< RangedAudioParameter > const m_parameterPtr
 
RangedAudioParameter * m_cachedParameterPtr
 
float m_parameterValue
 
AudioBuffer< float > m_valueBuffer
 
const Mode m_attachmentMode
 
std::unique_ptr< ParameterUpdaterm_updater
 
SmoothedValue< float > m_smoother {0.0f}
 
float m_smoothingTimeSeconds
 
int m_numSmoothingSamples {0}
 
Array< Modulator * > m_slowModulators
 
Array< Modulator * > m_fastModulators
 
std::map< Modulator *, Depthm_depthMap
 
double m_sampleRate {0.0}
 
int m_maxBlockSize {0}
 
bool m_needsUpdate {false}
 
bool m_wasSmoothing {false}
 
const std::function< void(float)> m_updateFunction
 
int m_updateRate {0}
 

Friends

class ParameterUpdater
 

Detailed Description

Attaches to a KParameter to provide parameter smoothing and modulation.

A helper class for KParameters that smooths parameter changes and provides functionality for easily integrating the new values into the audio processor.

See also
KParameter, KwidgetProcessor

Member Enumeration Documentation

◆ Mode

Enumerator
Discrete 
Continuous 

◆ Polarity

Enumerator
Bipolar 
Unipolar 

Constructor & Destructor Documentation

◆ KAttachment() [1/2]

krotos::KAttachment::KAttachment ( std::shared_ptr< KParameter > paramToAttach,
std::function< void(float)> updateFunction = nullptr )

Creates a discrete parameter attachment. Discrete attachments do not use any smoothing and if their values change, they trigger an update once at the start of the next block.

If updateFunction is nullptr, no automatic parameter updating will occur. You can call data() to get a pointer to the current parameter values.

Parameters
paramToAttachThe KParameter to link this attachment to
updateFunctionFunction that is called to update the processor of the next parameter change

◆ KAttachment() [2/2]

krotos::KAttachment::KAttachment ( std::shared_ptr< KParameter > paramToAttach,
float smoothingTimeSeconds,
int updateRate,
std::function< void(float)> updateFunction = nullptr )

Creates a continuous parameter attachment. Continuous attachments use a linear smoother to gradually integrate parameter changes.

If updateFunction is nullptr, no automatic parameter updating will occur. You can call data() to get a pointer to the current parameter values.

Parameters
paramToAttachThe KParameter to link this attachment to
smoothingTimeSecondsDuration of linear smoother
updateRateNumber of samples between processor updates
updateFunctionFunction that is called to update the processor of the next parameter change

◆ ~KAttachment()

krotos::KAttachment::~KAttachment ( )
override

Destructor

Member Function Documentation

◆ addModulator()

void krotos::KAttachment::addModulator ( Modulator * m,
float depth = 1.0f,
Polarity polarity = Polarity::Bipolar )

Add a new modulator for this parameter.

◆ applyPendingUpdates()

void krotos::KAttachment::applyPendingUpdates ( )

This function clears any pending smoother updates by filling the value buffer with the target value, and applying this value immediately to the processor.

If the smoother is already at its target value, nothing happens.

◆ data()

const float * krotos::KAttachment::data ( )

Get a pointer to the parameter value buffer.

◆ getUpdater()

KAttachment::ParameterUpdater * krotos::KAttachment::getUpdater ( )

Used by continuous attachments to provide an easy way of updating the parameter value within a processing loop.

Returns
Pointer to m_updater. Call needsUpdate() first to check if it is valid.

◆ modulatorChanged()

void krotos::KAttachment::modulatorChanged ( const Modulator * m)
overrideprivatevirtual

◆ needsUpdate()

bool krotos::KAttachment::needsUpdate ( ) const

Returns true if this object's ParameterUpdater should be active for the next block.

◆ nextBlock()

bool krotos::KAttachment::nextBlock ( int numSamples)

Update the parameter value buffer for each block. For discrete parameters, changes in value are sent to the processor in this function. For continuous parameters, changes in value should be handled using the result of getUpdater() in the audio processing loop.

Parameters
numSamplesNumber of samples to move forward
Returns
True if a ParameterUpdater is needed for the next block

◆ parameterGestureChanged()

void krotos::KAttachment::parameterGestureChanged ( int ,
bool  )
inlineoverrideprivate

◆ parameterValueChanged()

void krotos::KAttachment::parameterValueChanged ( int ,
float newValue )
overrideprivate

◆ prepare()

void krotos::KAttachment::prepare ( double sampleRate,
int samplesPerBlock )

This function must be called before the first call to nextBlock(), and also whenever the sample rate or block size changes.

◆ removeModulator()

void krotos::KAttachment::removeModulator ( Modulator * m)

Remove a modulator.

◆ sendInitialUpdate()

void krotos::KAttachment::sendInitialUpdate ( )
private

◆ setModulatorDepth()

void krotos::KAttachment::setModulatorDepth ( Modulator * m,
float depth )

Set the depth of a modulator.

Parameters
depthThe magnitude of modulation, must be in the range [-1, 1].

◆ setModulatorPolarity()

void krotos::KAttachment::setModulatorPolarity ( Modulator * m,
Polarity polarity )

Set the polarity of a modulator.

Parameters
polarityThe polarity of modulation, either Bipolar [-1, 1] or Unipolar [0, 1].

◆ updateSmoother()

void krotos::KAttachment::updateSmoother ( )
private

Friends And Related Symbol Documentation

◆ ParameterUpdater

friend class ParameterUpdater
friend

Member Data Documentation

◆ m_attachmentMode

const Mode krotos::KAttachment::m_attachmentMode
private

◆ m_cachedParameterPtr

RangedAudioParameter* krotos::KAttachment::m_cachedParameterPtr
private

◆ m_depthMap

std::map<Modulator*, Depth> krotos::KAttachment::m_depthMap
private

◆ m_fastModulators

Array<Modulator*> krotos::KAttachment::m_fastModulators
private

◆ m_maxBlockSize

int krotos::KAttachment::m_maxBlockSize {0}
private

◆ m_needsUpdate

bool krotos::KAttachment::m_needsUpdate {false}
private

◆ m_numSmoothingSamples

int krotos::KAttachment::m_numSmoothingSamples {0}
private

◆ m_parameterPtr

std::weak_ptr<RangedAudioParameter> const krotos::KAttachment::m_parameterPtr
private

◆ m_parameterValue

float krotos::KAttachment::m_parameterValue
private

◆ m_sampleRate

double krotos::KAttachment::m_sampleRate {0.0}
private

◆ m_slowModulators

Array<Modulator*> krotos::KAttachment::m_slowModulators
private

◆ m_smoother

SmoothedValue<float> krotos::KAttachment::m_smoother {0.0f}
private

◆ m_smoothingTimeSeconds

float krotos::KAttachment::m_smoothingTimeSeconds
private

◆ m_updateFunction

const std::function<void(float)> krotos::KAttachment::m_updateFunction
private

◆ m_updater

std::unique_ptr<ParameterUpdater> krotos::KAttachment::m_updater
private

◆ m_updateRate

int krotos::KAttachment::m_updateRate {0}
private

◆ m_valueBuffer

AudioBuffer<float> krotos::KAttachment::m_valueBuffer
private

◆ m_wasSmoothing

bool krotos::KAttachment::m_wasSmoothing {false}
private

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