-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginProcessor.cpp
More file actions
322 lines (285 loc) · 9.94 KB
/
Copy pathPluginProcessor.cpp
File metadata and controls
322 lines (285 loc) · 9.94 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "global.hpp"
#include "BinaryData.h"
//==============================================================================
EmptyAudioProcessor::EmptyAudioProcessor()
: AudioProcessor(BusesProperties()
#if !JucePlugin_IsMidiEffect
#if !JucePlugin_IsSynth
.withInput("Input", juce::AudioChannelSet::stereo(), true)
#endif
.withOutput("Output", juce::AudioChannelSet::stereo(), true)
#endif
) {
dsp_processor_ = warpcore::GetProcessorDsp();
juce::AudioProcessorValueTreeState::ParameterLayout layout;
{
auto p = std::make_unique<juce::AudioParameterInt>(
juce::ParameterID{"warp", 1},
"warp",
1, global::kMaxBands, 50
);
param_listener_.Add(p, [this](int v) {
param_.bands = v;
param_changed_ = true;
});
layout.add(std::move(p));
}
{
auto p = std::make_unique<juce::AudioParameterFloat>(
juce::ParameterID{"f_high", 1},
"f_high",
juce::NormalisableRange<float>{4000.0f, 20010.0f, 0.4f}, 20010.0f,
juce::AudioParameterFloatAttributes{}.withStringFromValueFunction([](auto x, auto maxlen) -> juce::String {
if (x >= 20000.0f) {
return "Full";
}
else {
return juce::String(x, maxlen);
}
})
);
param_listener_.Add(p, [this](float v) {
param_.f_high = v;
param_changed_ = true;
});
layout.add(std::move(p));
}
{
auto p = std::make_unique<juce::AudioParameterFloat>(
juce::ParameterID{"scale", 1},
"scale",
juce::NormalisableRange<float>{0.1f, 3.0f, 0.01f}, 1.0f
);
param_listener_.Add(p, [this](float v) {
param_.filter_scale = v;
param_changed_ = true;
});
layout.add(std::move(p));
}
{
auto p = std::make_unique<juce::AudioParameterFloat>(
juce::ParameterID{"pitch", 1},
"pitch",
juce::NormalisableRange<float>{-24.0f, 24.0f, 0.01f}, 0.0f
);
param_listener_.Add(p, [this](float v) {
param_.pitch_shift = v;
param_changed_ = true;
});
layout.add(std::move(p));
}
{
auto p = std::make_unique<juce::AudioParameterBool>(
juce::ParameterID{"pitch_affect", 1},
"pitch_affect",
true
);
param_listener_.Add(p, [this](bool v) {
param_.pitch_affect = v;
param_changed_ = true;
});
layout.add(std::move(p));
}
{
auto p = std::make_unique<juce::AudioParameterBool>(
juce::ParameterID{"fill_gap", 1},
"fill_gap",
false
);
param_listener_.Add(p, [this](bool v) {
param_.fill_gap = v;
param_changed_ = true;
});
layout.add(std::move(p));
}
{
auto p = std::make_unique<juce::AudioParameterFloat>(
juce::ParameterID{"drywet", 1},
"drywet",
juce::NormalisableRange<float>{0.0f, 1.0f, 0.01f}, 1.0f
);
param_listener_.Add(p, [this](float v) {
param_.drywet = v;
param_changed_ = true;
});
layout.add(std::move(p));
}
{
auto p = std::make_unique<juce::AudioParameterInt>(
juce::ParameterID{"poles", 1},
"poles",
1, global::kMaxPoles, 2
);
param_listener_.Add(p, [this](int v) {
param_.filter_order = v;
param_changed_ = true;
});
layout.add(std::move(p));
}
{
auto p = std::make_unique<juce::AudioParameterChoice>(
juce::ParameterID{"freq_mode", 1},
"freq_mode",
juce::StringArray{
"voice: 0 + n",
"voice: 1 + n",
"music: 0 + 2n",
"music: 1 + 2n",
},
2
);
param_listener_.Add(p, [this](int v) {
param_.freq_distribution = static_cast<warpcore::FreqDistrbution>(v);
param_changed_ = true;
});
layout.add(std::move(p));
}
value_tree_ = std::make_unique<juce::AudioProcessorValueTreeState>(*this, nullptr, kParameterValueTreeIdentify,
std::move(layout));
preset_manager_ = std::make_unique<pluginshared::PresetManager>(*value_tree_, *this, pluginshared::UpdateData::GithubInfo{
global::kPluginRepoOwnerName, global::kPluginRepoName
});
preset_manager_->AddFactoryPreset(BinaryData::PiWarpLike_xml, BinaryData::PiWarpLike_xmlSize, "PiWarp Like");
preset_manager_->AddFactoryPreset(BinaryData::WormholeLike_xml, BinaryData::WormholeLike_xmlSize, "Wormhole Like");
}
EmptyAudioProcessor::~EmptyAudioProcessor() {
param_listener_.Clear();
preset_manager_ = nullptr;
value_tree_ = nullptr;
}
//==============================================================================
const juce::String EmptyAudioProcessor::getName() const {
return JucePlugin_Name;
}
bool EmptyAudioProcessor::acceptsMidi() const {
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool EmptyAudioProcessor::producesMidi() const {
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
bool EmptyAudioProcessor::isMidiEffect() const {
#if JucePlugin_IsMidiEffect
return true;
#else
return false;
#endif
}
double EmptyAudioProcessor::getTailLengthSeconds() const {
return 0.0;
}
int EmptyAudioProcessor::getNumPrograms() {
return 1; // 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 EmptyAudioProcessor::getCurrentProgram() {
return 0;
}
void EmptyAudioProcessor::setCurrentProgram(int index) {
juce::ignoreUnused(index);
}
const juce::String EmptyAudioProcessor::getProgramName(int index) {
juce::ignoreUnused(index);
return {};
}
void EmptyAudioProcessor::changeProgramName(int index, const juce::String& newName) {
juce::ignoreUnused(index, newName);
}
//==============================================================================
void EmptyAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) {
juce::ignoreUnused(samplesPerBlock);
float fs = static_cast<float>(sampleRate);
if (dsp_processor_.IsValid()) {
dsp_processor_.init(dsp_state_, fs);
dsp_processor_.reset(dsp_state_);
}
param_listener_.MarkAll();
}
void EmptyAudioProcessor::reset() {
if (dsp_processor_.IsValid()) {
dsp_processor_.reset(dsp_state_);
}
}
void EmptyAudioProcessor::releaseResources() {
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
bool EmptyAudioProcessor::isBusesLayoutSupported(const BusesLayout& layouts) const {
#if JucePlugin_IsMidiEffect
juce::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.
// Some plugin hosts, such as certain GarageBand versions, will only
// load plugins that support stereo bus layouts.
if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != juce::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
}
void EmptyAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) {
juce::ignoreUnused(midiMessages);
if (!dsp_processor_.IsValid()) return;
juce::ScopedNoDenormals noDenormals;
param_listener_.HandleDirty();
if (param_changed_.exchange(false)) {
use_param_ = param_;
dsp_processor_.update(dsp_state_, use_param_);
}
int const num_samples = buffer.getNumSamples();
float* left_ptr = buffer.getWritePointer(0);
float* right_ptr = nullptr;
if (buffer.getNumChannels() == 2) {
right_ptr = buffer.getWritePointer(1);
}
dsp_processor_.process(dsp_state_,left_ptr, right_ptr, num_samples);
}
//==============================================================================
bool EmptyAudioProcessor::hasEditor() const {
return true; // (change this to false if you choose to not supply an editor)
}
juce::AudioProcessorEditor* EmptyAudioProcessor::createEditor() {
return new EmptyAudioProcessorEditor(*this);
// return new juce::GenericAudioProcessorEditor(*this);
}
//==============================================================================
void EmptyAudioProcessor::getStateInformation(juce::MemoryBlock& destData) {
suspendProcessing(true);
juce::ValueTree plugin_state{"PLUGIN_STATE"};
plugin_state.appendChild(value_tree_->copyState(), nullptr);
if (auto xml = plugin_state.createXml(); xml != nullptr) {
copyXmlToBinary(*xml, destData);
}
suspendProcessing(false);
}
void EmptyAudioProcessor::setStateInformation(const void* data, int sizeInBytes) {
suspendProcessing(true);
auto xml = *getXmlFromBinary(data, sizeInBytes);
auto plugin_state = juce::ValueTree::fromXml(xml);
if (plugin_state.isValid()) {
auto parameter = plugin_state.getChildWithName(kParameterValueTreeIdentify);
value_tree_->replaceState(parameter);
}
reset();
suspendProcessing(false);
}
//==============================================================================
// This creates new instances of the plugin..
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() {
return new EmptyAudioProcessor();
}