fsh::stk
fantastic spatial holophonic synthesis toolkit
Loading...
Searching...
No Matches
StateManager.h
1/***************************************************************************************************
2 ██████ █████ █████ █████
3 ███░░███ ░░███ ░░███ ░░███
4 ░███ ░░░ █████ ░███████ ██ ██ █████ ███████ ░███ █████
5 ███████ ███░░ ░███░░███ ░░ ░░ ███░░ ░░░███░ ░███░░███
6 ░░░███░ ░░█████ ░███ ░███ ░░█████ ░███ ░██████░
7 ░███ ░░░░███ ░███ ░███ ░░░░███ ░███ ███ ░███░░███
8 █████ ██████ ████ █████ ██ ██ ██████ ░░█████ ████ █████
9 ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░ ░░ ░░░░░░ ░░░░░ ░░░░ ░░░░░
10
11 fantastic spatial holophonic synthesis tool kit
12
13 copyright (c) fabian hummel
14 www.github.com/fshstk
15 www.fshstk.com
16
17 this file is part of the fantastic spatial holophonic synthesis toolkit (fsh::stk)
18 fsh::stk is free software: it is provided under the terms of the gnu general public license v3.0
19 www.gnu.org/licenses/gpl-3.0
20***************************************************************************************************/
21
22#pragma once
23#include <juce_audio_processors/juce_audio_processors.h>
24#include <spdlog/spdlog.h>
25
26namespace fsh::plugin
27{
38class StateManager : private juce::AudioProcessorValueTreeState
39{
40public:
42 using SliderAttachment = juce::AudioProcessorValueTreeState::SliderAttachment;
43
45 using ButtonAttachment = juce::AudioProcessorValueTreeState::ButtonAttachment;
46
48 using Params = juce::AudioProcessorValueTreeState::ParameterLayout;
49
53 StateManager(juce::AudioProcessor& parent, Params&& params);
54
56 auto getState() -> juce::XmlElement;
57
59 void setState(const juce::XmlElement& xml);
60
64 auto getReferenceToBaseClass() -> juce::AudioProcessorValueTreeState&;
65
66protected:
71 template<typename T>
72 auto getParameter(const juce::ParameterID& id) const -> T
73 {
74 const auto* const param = getRawParameterValue(id.getParamID());
75
76 if (param == nullptr)
77 {
78 spdlog::critical("PluginStateBase: trying to access parameter '{}' which does not exist",
79 id.getParamID().toStdString());
80 return {};
81 }
82
83 // This part is necessary since both casts from float to bool and float equality comparisons
84 // (`param->load() == 0.0f`) trigger warnings in gcc:
85 if constexpr (std::is_same<T, bool>::value)
86 return juce::exactlyEqual(param->load(), 0.0f);
87 else
88 return static_cast<T>(param->load());
89 }
90};
91} // namespace fsh::plugin
Base class for storing plugin state.
Definition StateManager.h:39
juce::AudioProcessorValueTreeState::SliderAttachment SliderAttachment
Helper alias for juce::AudioProcessorValueTreeState::SliderAttachment.
Definition StateManager.h:42
auto getState() -> juce::XmlElement
Called by the PluginBase class to save the plugin state.
Definition StateManager.cpp:31
juce::AudioProcessorValueTreeState::ButtonAttachment ButtonAttachment
Helper alias for juce::AudioProcessorValueTreeState::SliderAttachment.
Definition StateManager.h:45
juce::AudioProcessorValueTreeState::ParameterLayout Params
Helper alias for juce::AudioProcessorValueTreeState::ParameterLayout.
Definition StateManager.h:48
auto getParameter(const juce::ParameterID &id) const -> T
Get a parameter by its ID string.
Definition StateManager.h:72
StateManager(juce::AudioProcessor &parent, Params &&params)
Construct a PluginStateBase object.
Definition StateManager.cpp:26
void setState(const juce::XmlElement &xml)
Called by the PluginBase class to restore the plugin state.
Definition StateManager.cpp:40
auto getReferenceToBaseClass() -> juce::AudioProcessorValueTreeState &
Can be used by GUI objects, e.g.
Definition StateManager.cpp:48