-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathPluginProcessor.cpp
More file actions
285 lines (240 loc) · 9.34 KB
/
Copy pathPluginProcessor.cpp
File metadata and controls
285 lines (240 loc) · 9.34 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
==============================================================================
This file was auto-generated!
It contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "TemperDsp.cpp"
const int kOversampleFactor = 3;
//==============================================================================
TemperAudioProcessor::TemperAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", AudioChannelSet::stereo(), true)
#endif
),
m_params (*this, nullptr)
#else
: m_params (*this, nullptr)
#endif
{
m_restriction = new RestrictionProcessor();
m_bridge = new FaustUIBridge(m_params);
m_lastKnownSampleRate = 0.0;
m_currentProgram = -1;
// Initialize the dsp units
for (int i = 0; i < getTotalNumInputChannels(); ++i)
{
TemperDsp* dsp = new TemperDsp();
dsp->buildUserInterface(m_bridge);
m_dsps.add(dsp);
}
// Initialize the AudioProcessorValueTreeState root
ValueTree root (Identifier("TEMPER"));
m_params.state = root;
}
TemperAudioProcessor::~TemperAudioProcessor()
{
}
//==============================================================================
const String TemperAudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool TemperAudioProcessor::acceptsMidi() const
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool TemperAudioProcessor::producesMidi() const
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
double TemperAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int TemperAudioProcessor::getNumPrograms()
{
return 5; // NB: some hosts don't cope very well if you tell them there are 0 programs,
// so this should be at least 1, even if you're not really implementing programs.
}
int TemperAudioProcessor::getCurrentProgram()
{
return m_currentProgram;
}
void TemperAudioProcessor::setCurrentProgram (int index)
{
switch (index) {
case 0:
setStateInformation(BinaryData::DefaultPreset_xml,
BinaryData::DefaultPreset_xmlSize);
break;
case 1:
setStateInformation(BinaryData::StubbedToePreset_xml,
BinaryData::StubbedToePreset_xmlSize);
break;
case 2:
setStateInformation(BinaryData::BeeStingPreset_xml,
BinaryData::BeeStingPreset_xmlSize);
break;
case 3:
setStateInformation(BinaryData::MorningAtTheDMVPreset_xml,
BinaryData::MorningAtTheDMVPreset_xmlSize);
break;
case 4:
setStateInformation(BinaryData::FlyingUnitedPreset_xml,
BinaryData::FlyingUnitedPreset_xmlSize);
break;
default:
break;
}
m_currentProgram = index;
}
const String TemperAudioProcessor::getProgramName (int index)
{
switch (index) {
case 0:
return String("Default");
case 1:
return String("Stubbed Toe");
case 2:
return String("Bee Sting");
case 3:
return String("Morning at the DMV");
case 4:
return String("Flying United");
default:
return String();
}
}
void TemperAudioProcessor::changeProgramName (int index, const String& newName)
{
}
//==============================================================================
void TemperAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
auto filterType = juce::dsp::Oversampling<float>::filterHalfBandPolyphaseIIR;
m_oversampler = std::make_unique<juce::dsp::Oversampling<float>>(getTotalNumInputChannels(),
kOversampleFactor,
filterType,
false);
// Re-initialize the dsp modules at the upsampled rate.
if (m_lastKnownSampleRate == 0.0)
for (int i = 0; i < m_dsps.size(); ++i)
m_dsps.getUnchecked(i)->init(sampleRate * pow(2, kOversampleFactor));
else
for (int i = 0; i < m_dsps.size(); ++i)
m_dsps.getUnchecked(i)->instanceConstants(sampleRate * pow(2, kOversampleFactor));
m_oversampler->initProcessing(static_cast<size_t> (samplesPerBlock));
m_restriction->prepareToPlay(samplesPerBlock, sampleRate);
m_lastKnownSampleRate = sampleRate;
setLatencySamples(static_cast<int>(m_oversampler->getLatencyInSamples()));
}
void TemperAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool TemperAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
#if JucePlugin_IsMidiEffect
ignoreUnused (layouts);
return true;
#else
// This is the place where you check if the layout is supported.
// In this template code we only support mono or stereo.
if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
return false;
// This checks if the input layout matches the output layout
#if ! JucePlugin_IsSynth
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
#endif
return true;
#endif
}
#endif
void TemperAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();
TemperAudioProcessorEditor* editor = static_cast<TemperAudioProcessorEditor*>(getActiveEditor());
// In case we have more outputs than inputs, this code clears any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
// This is here to avoid people getting screaming feedback
// when they first compile a plugin, but obviously you don't need to keep
// this code if your algorithm always overwrites all the output channels.
for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
// Push input buffer into the Pre spectroscope component.
if (editor)
editor->m_vizPre->pushBuffer(buffer);
// Now the guts of the processing; oversampling and applying the Faust dsp module.
const int numInputChannels = buffer.getNumChannels();
const int numInputSamples = buffer.getNumSamples();
juce::dsp::AudioBlock<float> block (buffer.getArrayOfWritePointers(),
numInputChannels,
numInputSamples);
juce::dsp::AudioBlock<float> oversampledBlock = m_oversampler->processSamplesUp(block);
// Run the faust processors on each channel of the oversampled block.
for (int i = 0; i < numInputChannels; ++i)
{
auto* processor = m_dsps.getUnchecked(i);
auto* data = oversampledBlock.getChannelPointer(i);
int len = static_cast<int>(oversampledBlock.getNumSamples());
processor->compute(len, &data, &data);
}
m_oversampler->processSamplesDown(block);
#ifdef TEMPER_DEMO_BUILD
// After the Faust processing, add the demo restriction to the output stream
m_restriction->processBlock(buffer);
#endif
// Push resulting buffer into the Post spectroscope component.
if (editor)
editor->m_vizPost->pushBuffer(buffer);
}
//==============================================================================
bool TemperAudioProcessor::hasEditor() const
{
return true; // (change this to false if you choose to not supply an editor)
}
AudioProcessorEditor* TemperAudioProcessor::createEditor()
{
return new TemperAudioProcessorEditor (*this, m_params);
}
//==============================================================================
void TemperAudioProcessor::getStateInformation (MemoryBlock& destData)
{
ScopedPointer<XmlElement> xml (m_params.state.createXml());
copyXmlToBinary(*xml, destData);
}
void TemperAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
ScopedPointer<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
if (xmlState != nullptr)
if (xmlState->hasTagName (m_params.state.getType()))
m_params.state = ValueTree::fromXml (*xmlState);
}
//==============================================================================
// This creates new instances of the plugin..
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new TemperAudioProcessor();
}