-
Notifications
You must be signed in to change notification settings - Fork 1
/
PluginProcessor.h
93 lines (71 loc) · 3.73 KB
/
PluginProcessor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <juce_audio_basics/juce_audio_basics.h>
#include <juce_audio_processors/juce_audio_processors.h>
#include <choc_javascript.h>
#include <Runtime.h>
//==============================================================================
class EffectsPluginProcessor
: public juce::AudioProcessor,
public juce::AudioProcessorParameter::Listener,
private juce::AsyncUpdater
{
public:
//==============================================================================
EffectsPluginProcessor();
~EffectsPluginProcessor() override;
//==============================================================================
juce::AudioProcessorEditor* createEditor() override;
bool hasEditor() const override;
//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
bool isBusesLayoutSupported (const juce::AudioProcessor::BusesLayout& layouts) const override;
void processBlock (juce::AudioBuffer<float>&, juce::MidiBuffer&) override;
//==============================================================================
const juce::String getName() const override;
bool acceptsMidi() const override;
bool producesMidi() const override;
bool isMidiEffect() const override;
double getTailLengthSeconds() const override;
//==============================================================================
int getNumPrograms() override;
int getCurrentProgram() override;
void setCurrentProgram (int index) override;
const juce::String getProgramName (int index) override;
void changeProgramName (int index, const juce::String& newName) override;
//==============================================================================
void getStateInformation (juce::MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override;
//==============================================================================
/** Implement the AudioProcessorParameter::Listener interface. */
void parameterValueChanged (int parameterIndex, float newValue) override;
void parameterGestureChanged (int parameterIndex, bool gestureIsStarting) override;
//==============================================================================
/** Implement the AsyncUpdater interface. */
void handleAsyncUpdate() override;
//==============================================================================
/** Internal helper for propagating processor state changes. */
void dispatchStateChange();
private:
//==============================================================================
// A. THis is where we hld the state of or audio processor
// Ableton line wants to know
elem::js::Object state;
// B. Embedded Javascript engine (from choc)
choc::javascript::Context jsContext;
juce::AudioBuffer<float> scratchBuffer;
// C. This is where things get interesting.
std::unique_ptr<elem::Runtime<float>> runtime;
//==============================================================================
// A simple "dirty list" abstraction here for propagating realtime parameter
// value changes
// D. Whenever the HOST get a parameter change, we get a callback to indicate things are changing
struct ParameterReadout {
float value = 0;
bool dirty = false;
};
std::list<std::atomic<ParameterReadout>> paramReadouts;
static_assert(std::atomic<ParameterReadout>::is_always_lock_free);
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EffectsPluginProcessor)
};