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

An interface for an audio processor designed for modular use. More...

#include <KwidgetProcessor.h>

Inheritance diagram for krotos::KwidgetProcessor:
krotos::KwidgetProcessor_Adsr krotos::KwidgetProcessor_AudioOut krotos::KwidgetProcessor_ConvolutionReverb krotos::KwidgetProcessor_CoreEngine krotos::KwidgetProcessor_Filter krotos::KwidgetProcessor_Lfo krotos::KwidgetProcessor_MacroControls krotos::KwidgetProcessor_MacroSlider krotos::KwidgetProcessor_MoogVcf krotos::KwidgetProcessor_OfflineAnalyser krotos::KwidgetProcessor_Pan krotos::KwidgetProcessor_PhaseVocoder krotos::KwidgetProcessor_Recorder krotos::KwidgetProcessor_Reformer krotos::KwidgetProcessor_SAFilter krotos::KwidgetProcessor_Saturation krotos::KwidgetProcessor_Sawtooth krotos::KwidgetProcessor_Scaledadsr krotos::KwidgetProcessor_Sine krotos::KwidgetProcessor_Template krotos::KwidgetProcessor_TriggerButton krotos::KwidgetProcessor_XyPad

Classes

class  AttachmentInfo
 Holds the info required to create a new KAttachment for a Kwidget parameter. More...
 

Public Member Functions

 KwidgetProcessor (Kwidget &owner)
 
 ~KwidgetProcessor () override=default
 
void prepareToPlay (double, int) override final
 
void processBlock (AudioBuffer< float > &buffer, MidiBuffer &) override final
 
virtual void prepare (double sampleRate, int samplesPerBlock)=0
 
virtual void process (AudioBuffer< float > &buffer)=0
 
virtual void noteOn (int midiNoteNumber, float velocity, int voiceIndex=-1)
 
virtual void noteOff (float velocity)
 
virtual bool isActive ()
 
virtual void noteCleared ()
 
std::shared_ptr< KAttachmentgetAttachment (const String &paramID)
 
int getNumModulators () const
 
ModulatorgetModulator (int index)
 
const String & getKwidgetType () const
 
const String & getKwidgetID () const
 
void updateAttachments ()
 

Protected Member Functions

void nextBlock (int numSamples)
 
void nextSample ()
 
void addModulator (bool useAudioRate)
 
void addParameterAttachments (std::vector< AttachmentInfo >)
 
void addParameterCallback (const String &paramID, std::function< void(float)> callback)
 
KwidgetgetOwner () const
 

Private Member Functions

const String getName () const override
 
AudioProcessorEditor * createEditor () override
 
bool hasEditor () const override
 
double getTailLengthSeconds () const override
 
bool acceptsMidi () const override
 
bool producesMidi () const override
 
int getNumPrograms () override
 
int getCurrentProgram () override
 
void setCurrentProgram (int) override
 
const String getProgramName (int) override
 
void changeProgramName (int, const String &) override
 
void getStateInformation (MemoryBlock &) override
 
void setStateInformation (const void *, int) override
 
void releaseResources () override
 

Private Attributes

const double m_smoothingTimeSeconds {20e-3f}
 
Kwidgetm_owner
 
std::vector< std::shared_ptr< KAttachment > > m_attachments
 
std::unordered_map< String, std::shared_ptr< KAttachment > > m_attachmentMap
 
std::vector< KAttachment::ParameterUpdater * > m_activeUpdaters
 
OwnedArray< KParameter::AudioListenerObjectm_parameterCallbacks
 
OwnedArray< Modulatorm_modulators
 

Detailed Description

An interface for an audio processor designed for modular use.

Constructor & Destructor Documentation

◆ KwidgetProcessor()

krotos::KwidgetProcessor::KwidgetProcessor ( Kwidget & owner)

Constructor.

◆ ~KwidgetProcessor()

krotos::KwidgetProcessor::~KwidgetProcessor ( )
overridedefault

Destructor.

Member Function Documentation

◆ acceptsMidi()

bool krotos::KwidgetProcessor::acceptsMidi ( ) const
inlineoverrideprivate

◆ addModulator()

void krotos::KwidgetProcessor::addModulator ( bool useAudioRate)
inlineprotected

Child classes that are capable of sending out modulation signals should use this method to add all of the Modulator objects that it will use.

Parameters
useAudioRateIf true, the new modulator will use sample-accurate modulation. If false, the new modulator will use block-rate modulation.

◆ addParameterAttachments()

void krotos::KwidgetProcessor::addParameterAttachments ( std::vector< AttachmentInfo > attachments)
protected

Creates new KAttachment objects for a list of Kwidget parameters. After the KAttachment objects are constructed, they will begin receiving updates from their parameters and dispatching them to this processor via the provided lambda functions.

If you don't want to provide a callback, you can instead choose to access a buffer of parameter values for each sample in the current block:

const float* paramValues = getAttachment(paramID)->data();
std::shared_ptr< KAttachment > getAttachment(const String &paramID)
Definition KwidgetProcessor.cpp:26
See also
AttachmentInfo for more information on setting up attachments.

◆ addParameterCallback()

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

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.

◆ changeProgramName()

void krotos::KwidgetProcessor::changeProgramName ( int ,
const String &  )
inlineoverrideprivate

◆ createEditor()

AudioProcessorEditor * krotos::KwidgetProcessor::createEditor ( )
inlineoverrideprivate

◆ getAttachment()

std::shared_ptr< KAttachment > krotos::KwidgetProcessor::getAttachment ( const String & paramID)

Get a pointer to a KAttachment belonging to this processor.

◆ getCurrentProgram()

int krotos::KwidgetProcessor::getCurrentProgram ( )
inlineoverrideprivate

◆ getKwidgetID()

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

Get the ID of the Kwidget represented by this UI object (ex. "Sine0").

◆ getKwidgetType()

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

Get the type of Kwidget represented by this UI object (ex. "Sine").

◆ getModulator()

Modulator * krotos::KwidgetProcessor::getModulator ( int index)

Get a pointer to a Modulator object owned by this processor.

◆ getName()

const String krotos::KwidgetProcessor::getName ( ) const
inlineoverrideprivate

◆ getNumModulators()

int krotos::KwidgetProcessor::getNumModulators ( ) const

Get the total number of Modulator objects used by this processor.

◆ getNumPrograms()

int krotos::KwidgetProcessor::getNumPrograms ( )
inlineoverrideprivate

◆ getOwner()

Kwidget & krotos::KwidgetProcessor::getOwner ( ) const
inlineprotected

Get a reference to the Kwidget that created this processor.

◆ getProgramName()

const String krotos::KwidgetProcessor::getProgramName ( int )
inlineoverrideprivate

◆ getStateInformation()

void krotos::KwidgetProcessor::getStateInformation ( MemoryBlock & )
inlineoverrideprivate

◆ getTailLengthSeconds()

double krotos::KwidgetProcessor::getTailLengthSeconds ( ) const
inlineoverrideprivate

◆ hasEditor()

bool krotos::KwidgetProcessor::hasEditor ( ) const
inlineoverrideprivate

◆ isActive()

bool krotos::KwidgetProcessor::isActive ( )
virtual

◆ nextBlock()

void krotos::KwidgetProcessor::nextBlock ( int numSamples)
protected

Call at the start of each block to update the parameter values of any parameters that have changed since the last block.

Parameters
numSamplesThe current block size

To apply the changes:

void processBlock(float* buffer, int numSamples)
{
nextBlock(numSamples);
for (int i = 0; i < numSamples; i++)
{
// process audio
}
}
void processBlock(AudioBuffer< float > &buffer, MidiBuffer &) override final
Definition KwidgetProcessor.cpp:18
void nextBlock(int numSamples)
Definition KwidgetProcessor.cpp:50
void nextSample()
Definition KwidgetProcessor.cpp:59

◆ nextSample()

void krotos::KwidgetProcessor::nextSample ( )
protected

Call this once for each sample in the block.

◆ noteCleared()

virtual void krotos::KwidgetProcessor::noteCleared ( )
inlinevirtual

◆ noteOff()

void krotos::KwidgetProcessor::noteOff ( float velocity)
virtual

Override this method to process a note off event, if necessary.

Parameters
velocityThe relative velocity of the note event (between 0 and 1).

Reimplemented in krotos::KwidgetProcessor_Adsr, krotos::KwidgetProcessor_CoreEngine, krotos::KwidgetProcessor_Recorder, krotos::KwidgetProcessor_Reformer, krotos::KwidgetProcessor_Scaledadsr, krotos::KwidgetProcessor_Template, and krotos::KwidgetProcessor_TriggerButton.

◆ noteOn()

void krotos::KwidgetProcessor::noteOn ( int midiNoteNumber,
float velocity,
int voiceIndex = -1 )
virtual

Override this method to process a note on event, if necessary.

Parameters
midiNoteNumberThe integer value of the MIDI note.
See also
juce::MidiMessage::getMidiNoteInHertz()

velocity The relative velocity of the note event (between 0 and 1). voiceIndex Optionally pass in a voice index, used ultimately to identify the voice associated with a playing note Defaults to -1 if unused

Reimplemented in krotos::KwidgetProcessor_Adsr, krotos::KwidgetProcessor_CoreEngine, krotos::KwidgetProcessor_Recorder, krotos::KwidgetProcessor_Reformer, krotos::KwidgetProcessor_Sawtooth, krotos::KwidgetProcessor_Scaledadsr, krotos::KwidgetProcessor_Sine, krotos::KwidgetProcessor_Template, and krotos::KwidgetProcessor_TriggerButton.

◆ prepare()

◆ prepareToPlay()

void krotos::KwidgetProcessor::prepareToPlay ( double sampleRate,
int samplePerBlock )
finaloverride

Do not override prepareToPlay()! Use prepare() instead in child classes.

◆ process()

◆ processBlock()

void krotos::KwidgetProcessor::processBlock ( AudioBuffer< float > & buffer,
MidiBuffer &  )
finaloverride

Do not override processBlock()! Use process() instead in child classes.

◆ producesMidi()

bool krotos::KwidgetProcessor::producesMidi ( ) const
inlineoverrideprivate

◆ releaseResources()

void krotos::KwidgetProcessor::releaseResources ( )
inlineoverrideprivate

◆ setCurrentProgram()

void krotos::KwidgetProcessor::setCurrentProgram ( int )
inlineoverrideprivate

◆ setStateInformation()

void krotos::KwidgetProcessor::setStateInformation ( const void * ,
int  )
inlineoverrideprivate

◆ updateAttachments()

void krotos::KwidgetProcessor::updateAttachments ( )

Call this function to ensure that all KAttachment objects are fully up to date, and their values have been applied to the processor.

This function is used in Kwidgets with multiple voices to make sure that a voice is up to date with the latest parameter values before it begins processing after previously being in an 'off' state.

This is necessary because parameter smoothing only occurs when a voice is active, so if this function is not called, then any smoothed parameters with pending updates will ramp from their previous value to the current value in the first few moments of audio processing.

Member Data Documentation

◆ m_activeUpdaters

std::vector<KAttachment::ParameterUpdater*> krotos::KwidgetProcessor::m_activeUpdaters
private

◆ m_attachmentMap

std::unordered_map<String, std::shared_ptr<KAttachment> > krotos::KwidgetProcessor::m_attachmentMap
private

◆ m_attachments

std::vector<std::shared_ptr<KAttachment> > krotos::KwidgetProcessor::m_attachments
private

◆ m_modulators

OwnedArray<Modulator> krotos::KwidgetProcessor::m_modulators
private

◆ m_owner

Kwidget& krotos::KwidgetProcessor::m_owner
private

◆ m_parameterCallbacks

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

◆ m_smoothingTimeSeconds

const double krotos::KwidgetProcessor::m_smoothingTimeSeconds {20e-3f}
private

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