fsh::stk
fantastic spatial holophonic synthesis toolkit
Loading...
Searching...
No Matches
Processor.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
25// The following macros are here just to appease the compiler. When including this file in a plugin,
26// the `JucePlugin_*` constants will always be defined by juce_add_plugin() in CMakeLists.txt.
27
28#ifndef JucePlugin_IsSynth
29#error "JucePlugin_IsSynth must be defined. Use this class inside of a JUCE project."
30const auto JucePlugin_IsSynth = false;
31#endif
32
33#ifndef JucePlugin_Name
34#error "JucePlugin_Name must be defined. Use this class inside of a JUCE project."
35const auto JucePlugin_Name = "";
36#endif
37
38#ifndef JucePlugin_WantsMidiInput
39#error "JucePlugin_WantsMidiInput must be defined. Use this class inside of a JUCE project."
40const auto JucePlugin_WantsMidiInput = false;
41#endif
42
43#ifndef JucePlugin_ProducesMidiOutput
44#error "JucePlugin_ProducesMidiOutput must be defined. Use this class inside of a JUCE project."
45const auto JucePlugin_ProducesMidiOutput = false;
46#endif
47
48#ifndef JucePlugin_IsMidiEffect
49#error "JucePlugin_IsMidiEffect must be defined. Use this class inside of a JUCE project."
50const auto JucePlugin_IsMidiEffect = false;
51#endif
52
53namespace fsh::plugin
54{
97template<class StateManager>
98class Processor : public juce::AudioProcessor
99{
100public:
102 struct Config
103 {
105 juce::AudioChannelSet outputs;
106
108 juce::AudioChannelSet inputs = juce::AudioChannelSet::disabled();
109
111 auto hasInputs() const -> bool { return inputs != juce::AudioChannelSet::disabled(); }
112 };
113
115 explicit Processor(const Config& conf)
116 : AudioProcessor(conf.hasInputs() ? BusesProperties()
117 .withInput("Input", conf.inputs, true)
118 .withOutput("Output", conf.outputs, true)
119 : BusesProperties().withOutput("Output", conf.outputs, true))
120 , _params(*this)
121 , _conf(conf)
122 {
123 }
124
128 bool isBusesLayoutSupported(const BusesLayout& layouts) const override
129 {
130 return layouts.getMainInputChannelSet().size() == _conf.inputs.size() &&
131 layouts.getMainOutputChannelSet().size() == _conf.outputs.size();
132 }
133
141 void prepareToPlay(double sampleRate, int maxSamplesPerBlock) override
142 {
143 juce::ignoreUnused(sampleRate);
144 juce::ignoreUnused(maxSamplesPerBlock);
145 }
146
150 void releaseResources() override
151 {
152 // Intentionally empty default implementation.
153 }
154
156 const juce::String getName() const override { return _name; }
157
159 double getTailLengthSeconds() const override { return 0.0; }
160
162 bool hasEditor() const override { return true; }
163
167 virtual std::unique_ptr<juce::AudioProcessorEditor> customEditor() { return {}; }
168
170 bool acceptsMidi() const override { return _wantsMidi; }
171
173 bool producesMidi() const override { return _producesMidi; }
174
176 bool isMidiEffect() const override { return _isMidiEffect; }
177
181 int getNumPrograms() override { return 1; }
182
185 int getCurrentProgram() override { return 0; }
186
189 const juce::String getProgramName(int) override { return "unnamed"; }
190
193 void setCurrentProgram(int) override
194 {
195 // Intentionally empty override
196 }
197
200 void changeProgramName(int, const juce::String&) override
201 {
202 // Intentionally empty override
203 }
204
207 void getStateInformation(juce::MemoryBlock& destData) override
208 {
209 copyXmlToBinary(_params.getState(), destData);
210 }
211
215 void setStateInformation(const void* data, int sizeInBytes) override
216 {
217 if (const auto xml = getXmlFromBinary(data, sizeInBytes))
218 _params.setState(*xml);
219 }
220
221protected:
225
226private:
231 juce::AudioProcessorEditor* createEditor() final
232 {
233 if (auto editor = customEditor(); editor)
234 return editor.release();
235 return new juce::GenericAudioProcessorEditor(*this);
236 }
237
238 inline static const auto _isSynth = bool{ JucePlugin_IsSynth };
239 inline static const auto _name = juce::String{ JucePlugin_Name };
240 inline static const auto _wantsMidi = bool{ JucePlugin_WantsMidiInput };
241 inline static const auto _producesMidi = bool{ JucePlugin_ProducesMidiOutput };
242 inline static const auto _isMidiEffect = bool{ JucePlugin_IsMidiEffect };
243 Config _conf;
244 juce::ScopedNoDenormals _disableDenormals;
245};
246} // namespace fsh::plugin
The base class for all fsh::stk plugins.
Definition Processor.h:99
void releaseResources() override
Called by the DAW when the user stops playback.
Definition Processor.h:150
int getCurrentProgram() override
Returns the index of the current program (preset).
Definition Processor.h:185
void getStateInformation(juce::MemoryBlock &destData) override
Saves the entire plugin state to a binary blob.
Definition Processor.h:207
const juce::String getProgramName(int) override
Returns the name of the program at the given index.
Definition Processor.h:189
int getNumPrograms() override
Returns the number of programs (presets) supported by the plugin.
Definition Processor.h:181
bool hasEditor() const override
Returns whether the plugin has an editor. (It does, by default.)
Definition Processor.h:162
StateManager _params
Use this to access the plugin's parameters.
Definition Processor.h:224
bool isBusesLayoutSupported(const BusesLayout &layouts) const override
Used to tell the DAW whether a given channel layout is supported by the plugin.
Definition Processor.h:128
bool acceptsMidi() const override
Returns whether the plugin accepts MIDI input (as specified in the JUCE project settings)
Definition Processor.h:170
bool producesMidi() const override
Returns whether the plugin produces MIDI output (as specified in the JUCE project settings)
Definition Processor.h:173
void setCurrentProgram(int) override
Returns the name of the current program (preset).
Definition Processor.h:193
void prepareToPlay(double sampleRate, int maxSamplesPerBlock) override
Called by the DAW when the user starts playback.
Definition Processor.h:141
bool isMidiEffect() const override
Returns whether the plugin is a MIDI effect (as specified in the JUCE project settings)
Definition Processor.h:176
Processor(const Config &conf)
Construct a plugin instance.
Definition Processor.h:115
void changeProgramName(int, const juce::String &) override
Renames the program at the given index.
Definition Processor.h:200
const juce::String getName() const override
Get the plugin name (as specified in the JUCE project settings)
Definition Processor.h:156
void setStateInformation(const void *data, int sizeInBytes) override
Recalls the entire plugin state from a (valid) binary blob.
Definition Processor.h:215
double getTailLengthSeconds() const override
Return the plugin's audio tail length. The default implementation returns 0.0.
Definition Processor.h:159
virtual std::unique_ptr< juce::AudioProcessorEditor > customEditor()
Provide custom editor instead of GenericAudioProcessorEditor.
Definition Processor.h:167
Base class for storing plugin state.
Definition StateManager.h:39
auto getState() -> juce::XmlElement
Called by the PluginBase class to save the plugin state.
Definition StateManager.cpp:31
void setState(const juce::XmlElement &xml)
Called by the PluginBase class to restore the plugin state.
Definition StateManager.cpp:40
The input/output configuration struct for the plugin. This is passed to the constructor.
Definition Processor.h:103
juce::AudioChannelSet inputs
Input channel set (optional)
Definition Processor.h:108
auto hasInputs() const -> bool
Returns true if the configuration has enabled inputs.
Definition Processor.h:111
juce::AudioChannelSet outputs
Output channel set.
Definition Processor.h:105