Base class for the plugin's shared state. More...
#include <mostlyharmless_ISharedState.h>
Public Member Functions | |
ISharedState (SharedStateContext &&context, std::vector< Parameter< float > > &¶ms) | |
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 |
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.
|
explicit |
Constructs an ISharedState - obviously subclasses must call this constructor in their init lists.
context | An 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. |
params | An 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. |
|
virtualdefaultnoexcept |
Virtual destructor.
|
nodiscardnoexcept |
Retrieves the gui->proc parameters spsc, for direct access by either the engine or the editor.
|
nodiscardnoexcept |
Retrieves the number of params registered with the ISharedState instance.
|
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.
|
nodiscard |
Attempts to retrieve a parameter by its raw uint32_t id that was autogenerated for its internal name.
id | The id to attempt to retrieve. |
|
nodiscardnoexcept |
Attempts to retrieve a parameter by index - see Parameter for more details.
index | The index to attempt to retrieve |
|
nodiscardnoexcept |
Retrieves the proc->gui parameter spsc, for direct access by either the engine or the editor.
|
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.
|
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.
loadedData | A non-owning view into the deserialised state provided by the host. |
void mostly_harmless::core::ISharedState::requestParamFlush | ( | ) | const |
Requests a param flush from the host.
void mostly_harmless::core::ISharedState::rescanParams | ( | ) | const |
Asks the host to rescan all param values.
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.
toRun | An rvalue ref to the lambda to invoke on the message thread. |
|
pure virtual |
Called when the host wants to save state, users must override this to describe how serialisation should be performed.
dest | A stringstream to push the serialised data into. |