fsh::stk
fantastic spatial holophonic synthesis toolkit
All Classes Functions Variables Typedefs Enumerations Enumerator Pages
fsh::plugin::Processor< StateManager > Class Template Reference

The base class for all fsh::stk plugins. More...

#include <Processor.h>

Inheritance diagram for fsh::plugin::Processor< StateManager >:

Classes

struct  Config
 The input/output configuration struct for the plugin. This is passed to the constructor. More...
 

Public Member Functions

 Processor (const Config &conf)
 Construct a plugin instance.
 
bool isBusesLayoutSupported (const BusesLayout &layouts) const override
 Used to tell the DAW whether a given channel layout is supported by the plugin.
 
void prepareToPlay (double sampleRate, int maxSamplesPerBlock) override
 Called by the DAW when the user starts playback.
 
void releaseResources () override
 Called by the DAW when the user stops playback.
 
const juce::String getName () const override
 Get the plugin name (as specified in the JUCE project settings)
 
double getTailLengthSeconds () const override
 Return the plugin's audio tail length. The default implementation returns 0.0.
 
bool hasEditor () const override
 Returns whether the plugin has an editor. (It does, by default.)
 
virtual std::unique_ptr< juce::AudioProcessorEditor > customEditor ()
 Provide custom editor instead of GenericAudioProcessorEditor.
 
bool acceptsMidi () const override
 Returns whether the plugin accepts MIDI input (as specified in the JUCE project settings)
 
bool producesMidi () const override
 Returns whether the plugin produces MIDI output (as specified in the JUCE project settings)
 
bool isMidiEffect () const override
 Returns whether the plugin is a MIDI effect (as specified in the JUCE project settings)
 
int getNumPrograms () override
 Returns the number of programs (presets) supported by the plugin.
 
int getCurrentProgram () override
 Returns the index of the current program (preset).
 
const juce::String getProgramName (int) override
 Returns the name of the program at the given index.
 
void setCurrentProgram (int) override
 Returns the name of the current program (preset).
 
void changeProgramName (int, const juce::String &) override
 Renames the program at the given index.
 
void getStateInformation (juce::MemoryBlock &destData) override
 Saves the entire plugin state to a binary blob.
 
void setStateInformation (const void *data, int sizeInBytes) override
 Recalls the entire plugin state from a (valid) binary blob.
 

Protected Attributes

StateManager _params
 Use this to access the plugin's parameters.
 

Detailed Description

template<class StateManager>
class fsh::plugin::Processor< StateManager >

The base class for all fsh::stk plugins.

‍PluginBase provides a default implementation for all methods of juce::AudioProcessor, except processBlock(), which is always required for a plugin to work. It also provides a default implementation for getStateInformation() and setStateInformation(), so plugins can save/recall state and presets out of the box, and provides a default GUI editor.

To create a plugin, all you have to do is create two classes and override one method:

PluginState & PluginProcessor

  • Create a PluginState class that inherits from StateManager,
  • then create a PluginProcessor class that inherits from Processor<PluginState>.

‍You will need to specify the number of outputs (and optionally inputs) in the constructor. Do this inside your child class constructor, so your own class can have a default constructor with no parameters.

  • Next, create a processBlock() method in the child class, and
  • provide a main.cpp file with a boilerplate main function (see existing plugins).

That's it!

‍In many cases you will need to override additional methods, such as prepareToPlay() if you have components that need to know the sample rate or buffer size.

Custom editor

The default implementation creates a juce::GenericAudioProcessorEditor, which will display an unstyled list of your plugin's parameters. This is good enough to start, but if you want to create a custom editor, you will need to override customEditor(), e.g.:

auto customEditor() -> std::unique_ptr<juce::AudioProcessorEditor> override
{
return std::make_unique<PluginEditor>(*this, _params);
}
StateManager _params
Use this to access the plugin's parameters.
Definition Processor.h:224
virtual std::unique_ptr< juce::AudioProcessorEditor > customEditor()
Provide custom editor instead of GenericAudioProcessorEditor.
Definition Processor.h:167

The JUCE tutorials/docs describe how editors work in detail.

Member Function Documentation

◆ changeProgramName()

template<class StateManager >
void fsh::plugin::Processor< StateManager >::changeProgramName ( int ,
const juce::String &  )
inlineoverride

Renames the program at the given index.

The default implementation has no effect, as no programs are implemented.

◆ customEditor()

template<class StateManager >
virtual std::unique_ptr< juce::AudioProcessorEditor > fsh::plugin::Processor< StateManager >::customEditor ( )
inlinevirtual

Provide custom editor instead of GenericAudioProcessorEditor.

Override this if you have a custom editor. It will get passed to the base class's createEditor() method. This wrapper is here to prevent accidental memory leaks.

◆ getCurrentProgram()

template<class StateManager >
int fsh::plugin::Processor< StateManager >::getCurrentProgram ( )
inlineoverride

Returns the index of the current program (preset).

The default implementation returns 0, as no programs are implemented.

◆ getNumPrograms()

template<class StateManager >
int fsh::plugin::Processor< StateManager >::getNumPrograms ( )
inlineoverride

Returns the number of programs (presets) supported by the plugin.

The default implementation returns 1, even though no presets are impleneted, since some DAWs don't like it when you return 0 (or so the JUCE documentation says).

◆ getProgramName()

template<class StateManager >
const juce::String fsh::plugin::Processor< StateManager >::getProgramName ( int )
inlineoverride

Returns the name of the program at the given index.

The default implementation returns "unnamed". (Some plugin validators will complain if we return an empty string.)

◆ getStateInformation()

template<class StateManager >
void fsh::plugin::Processor< StateManager >::getStateInformation ( juce::MemoryBlock & destData)
inlineoverride

Saves the entire plugin state to a binary blob.

You will not need to override this method, or call it directly. This method is called by the DAW when the user saves a project or preset.

◆ isBusesLayoutSupported()

template<class StateManager >
bool fsh::plugin::Processor< StateManager >::isBusesLayoutSupported ( const BusesLayout & layouts) const
inlineoverride

Used to tell the DAW whether a given channel layout is supported by the plugin.

The default implementation checks whether the number of inputs/outputs matches the configuration passed to it, but you may choose to override this if you have a more complex setup.

◆ prepareToPlay()

template<class StateManager >
void fsh::plugin::Processor< StateManager >::prepareToPlay ( double sampleRate,
int maxSamplesPerBlock )
inlineoverride

Called by the DAW when the user starts playback.

The default implementation does nothing, but you may choose to override this if you have components that need to know the sample rate or buffer size. Note that maxSamplesPerBlock is the maximum number of samples that can be passed to your processBlock() method, but the actual number of samples may be less. Logic Pro, for example, always returns 1024 samples, even if the actual buffer size is less. The only reliable way to know the actual number of samples is to check the size of the AudioBuffer object in processBlock().

◆ releaseResources()

template<class StateManager >
void fsh::plugin::Processor< StateManager >::releaseResources ( )
inlineoverride

Called by the DAW when the user stops playback.

The default implementation does nothing, but you may choose to override this if you have components that need to release resources at the end of a playback cycle.

◆ setCurrentProgram()

template<class StateManager >
void fsh::plugin::Processor< StateManager >::setCurrentProgram ( int )
inlineoverride

Returns the name of the current program (preset).

The default implementation has no effect, as no programs are implemented.

◆ setStateInformation()

template<class StateManager >
void fsh::plugin::Processor< StateManager >::setStateInformation ( const void * data,
int sizeInBytes )
inlineoverride

Recalls the entire plugin state from a (valid) binary blob.

You will not need to override this method, or call it directly. This method is called by the DAW when the user recalls a project or preset.

Member Data Documentation

◆ _params

template<class StateManager >
StateManager fsh::plugin::Processor< StateManager >::_params
protected

Use this to access the plugin's parameters.

This is an instance of the PluginState object that is passed as a template parameter to PluginBase.


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