MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
mostly_harmless::core::ISharedState Class Referenceabstract

Base class for the plugin's shared state. More...

#include <mostlyharmless_ISharedState.h>

Public Member Functions

 ISharedState (SharedStateContext &&context, std::vector< Parameter< float > > &&params)
 
virtual ~ISharedState () noexcept=default
 
std::span< Parameter< float > > getRawParameterView () noexcept
 
Parameter< float > * getParameterByIndex (std::uint32_t index) noexcept
 
Parameter< float > * getParameterById (mostly_harmless::ParameterID parameterId)
 
Parameter< float > * getParameterById (std::uint32_t pid)
 
std::uint32_t getNumParams () const noexcept
 
virtual void loadState (std::string_view loadedData)=0
 
virtual void saveState (std::ostringstream &dest)=0
 
marvin::containers::fifos::SPSC< events::ProcToGuiParamEvent > & getProcToGuiQueue () noexcept
 
marvin::containers::fifos::SPSC< events::GuiToProcParamEvent > & getGuiToProcQueue () noexcept
 
void runOnMainThread (std::function< void(void)> &&toRun) const
 
void requestParamFlush () const
 
void rescanParams () const
 

Detailed Description

Base class for the plugin's shared state.

As detailed in the FX Plugin tutorial, users must implement this, IEngine, IPluginEntry, and optionally IEditor, and register their subclasses with the framework to create an audio plugin. These will also be created if using the provided create.py script.

Designed such that the Engine and Editor can be completely unaware of eachother, all communications between the two should go through this class.

Handles and owns all things shared between the gui and the engine - things like parameters, queues, and state restoration. Custom shared state should also be implemented in this class.

Constructor & Destructor Documentation

◆ ISharedState()

mostly_harmless::core::ISharedState::ISharedState ( SharedStateContext && context,
std::vector< Parameter< float > > && params )
explicit

Constructs an ISharedState - obviously subclasses must call this constructor in their init lists.

Parameters
contextAn rvalue ref to a SharedStateContext, containing functionality needed by SharedState (callOnMainThread, and the ability to request parameter flushes). In practice, an instance of this class will be passed to IPluginEntry::createState, and the user can forward this argument to this constructor.
paramsAn rvalue ref to a vector containing all the plugin's parameters - ISharedState takes ownership of the parameters and manages them, but needs to know what the parameters are in the first place.

◆ ~ISharedState()

virtual mostly_harmless::core::ISharedState::~ISharedState ( )
virtualdefaultnoexcept

Virtual destructor.

Member Function Documentation

◆ getGuiToProcQueue()

marvin::containers::fifos::SPSC< events::GuiToProcParamEvent > & mostly_harmless::core::ISharedState::getGuiToProcQueue ( )
nodiscardnoexcept

Retrieves the gui->proc parameters spsc, for direct access by either the engine or the editor.

Returns
A ref to the gui->proc parameter queue.

◆ getNumParams()

std::uint32_t mostly_harmless::core::ISharedState::getNumParams ( ) const
nodiscardnoexcept

Retrieves the number of params registered with the ISharedState instance.

Returns
The number of parameters.

◆ getParameterById() [1/2]

Parameter< float > * mostly_harmless::core::ISharedState::getParameterById ( mostly_harmless::ParameterID parameterId)
nodiscard

Attempts to retrieve a parameter by its internal name. Note that while the string the PID is constructed with isn't stored or copied, it IS hashed, which may make this function unsuitable for use in a realtime context. See the FXPluginTutorial for a secondary approach for accessing parameters.

◆ getParameterById() [2/2]

Parameter< float > * mostly_harmless::core::ISharedState::getParameterById ( std::uint32_t pid)
nodiscard

Attempts to retrieve a parameter by its raw uint32_t id that was autogenerated for its internal name.

Parameters
idThe id to attempt to retrieve.
Returns
A raw pointer to the parameter with id if found, nullptr otherwise.

◆ getParameterByIndex()

Parameter< float > * mostly_harmless::core::ISharedState::getParameterByIndex ( std::uint32_t index)
nodiscardnoexcept

Attempts to retrieve a parameter by index - see Parameter for more details.

Parameters
indexThe index to attempt to retrieve
Returns
A raw pointer to the parameter with index if found, nullptr otherwise.

◆ getProcToGuiQueue()

marvin::containers::fifos::SPSC< events::ProcToGuiParamEvent > & mostly_harmless::core::ISharedState::getProcToGuiQueue ( )
nodiscardnoexcept

Retrieves the proc->gui parameter spsc, for direct access by either the engine or the editor.

Returns
A ref to the proc->gui parameter queue.

◆ getRawParameterView()

std::span< Parameter< float > > mostly_harmless::core::ISharedState::getRawParameterView ( )
nodiscardnoexcept

Retrieves a non-owning view into the internal (index ordered) parameter vector. Useful if you want to iterate over all parameters in state restoration, etc.

Returns
A non-owning view into the internal parameter vector.

◆ loadState()

virtual void mostly_harmless::core::ISharedState::loadState ( std::string_view loadedData)
pure virtual

Called when the host wants to load state, users must override this to describe how deserialisation should be performed, and update their parameters accordingly.

Parameters
loadedDataA non-owning view into the deserialised state provided by the host.

◆ requestParamFlush()

void mostly_harmless::core::ISharedState::requestParamFlush ( ) const

Requests a param flush from the host.

◆ rescanParams()

void mostly_harmless::core::ISharedState::rescanParams ( ) const

Asks the host to rescan all param values.

◆ runOnMainThread()

void mostly_harmless::core::ISharedState::runOnMainThread ( std::function< void(void)> && toRun) const

Schedules a lambda to be called on the main/message thread. Note that this call won't be immediate, and it's up to the host to call it in a timely manner.

Parameters
toRunAn rvalue ref to the lambda to invoke on the message thread.

◆ saveState()

virtual void mostly_harmless::core::ISharedState::saveState ( std::ostringstream & dest)
pure virtual

Called when the host wants to save state, users must override this to describe how serialisation should be performed.

Parameters
destA stringstream to push the serialised data into.

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