This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathPluginProcessor.cpp
156 lines (120 loc) · 5.65 KB
/
PluginProcessor.cpp
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
/*
==============================================================================
This file was auto-generated!
It contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PresetListBox.h"
//==============================================================================
juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout()
{
juce::AudioProcessorValueTreeState::ParameterLayout layout;
FoleysSynth::addADSRParameters (layout);
FoleysSynth::addOvertoneParameters (layout);
FoleysSynth::addGainParameters (layout);
return layout;
}
//==============================================================================
FoleysSynthAudioProcessor::FoleysSynthAudioProcessor()
: foleys::MagicProcessor (juce::AudioProcessor::BusesProperties()
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)),
treeState (*this, nullptr, ProjectInfo::projectName, createParameterLayout())
{
FOLEYS_SET_SOURCE_PATH (__FILE__);
auto file = juce::File::getSpecialLocation (juce::File::currentApplicationFile)
.getChildFile ("Contents")
.getChildFile ("Resources")
.getChildFile ("magic.xml");
if (file.existsAsFile())
magicState.setGuiValueTree (file);
else
magicState.setGuiValueTree (BinaryData::magic_xml, BinaryData::magic_xmlSize);
// MAGIC GUI: add a meter at the output
outputMeter = magicState.createAndAddObject<foleys::MagicLevelSource>("output");
oscilloscope = magicState.createAndAddObject<foleys::MagicOscilloscope>("waveform");
analyser = magicState.createAndAddObject<foleys::MagicAnalyser>("analyser");
magicState.addBackgroundProcessing (analyser);
presetList = magicState.createAndAddObject<PresetListBox>("presets");
presetList->onSelectionChanged = [&](int number)
{
loadPresetInternal (number);
};
magicState.addTrigger ("save-preset", [this]
{
savePresetInternal();
});
magicState.setApplicationSettingsFile (juce::File::getSpecialLocation (juce::File::userApplicationDataDirectory)
.getChildFile (ProjectInfo::companyName)
.getChildFile (ProjectInfo::projectName + juce::String (".settings")));
magicState.setPlayheadUpdateFrequency (30);
FoleysSynth::FoleysSound::Ptr sound (new FoleysSynth::FoleysSound (treeState));
synthesiser.addSound (sound);
for (int i=0; i < 16; ++i)
synthesiser.addVoice (new FoleysSynth::FoleysVoice (treeState));
}
//==============================================================================
void FoleysSynthAudioProcessor::prepareToPlay (double sampleRate, int blockSize)
{
// Use this method as the place to do any pre-playback
// initialisation that you need..
synthesiser.setCurrentPlaybackSampleRate (sampleRate);
// MAGIC GUI: setup the output meter
outputMeter->setupSource (getTotalNumOutputChannels(), sampleRate, 500);
oscilloscope->prepareToPlay (sampleRate, blockSize);
analyser->prepareToPlay (sampleRate, blockSize);
}
void FoleysSynthAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
bool FoleysSynthAudioProcessor::isBusesLayoutSupported (const juce::AudioProcessor::BusesLayout& layouts) const
{
// This synth only supports mono or stereo.
return (layouts.getMainOutputChannelSet() == juce::AudioChannelSet::mono()
|| layouts.getMainOutputChannelSet() == juce::AudioChannelSet::stereo());
}
void FoleysSynthAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
// MAGIC GUI: send midi messages to the keyboard state and MidiLearn
magicState.processMidiBuffer (midiMessages, buffer.getNumSamples(), true);
// MAGIC GUI: send playhead information to the GUI
magicState.updatePlayheadInformation (getPlayHead());
synthesiser.renderNextBlock (buffer, midiMessages, 0, buffer.getNumSamples());
for (int i = 1; i < buffer.getNumChannels(); ++i)
buffer.copyFrom (i, 0, buffer.getReadPointer (0), buffer.getNumSamples());
// MAGIC GUI: send the finished buffer to the level meter
outputMeter->pushSamples (buffer);
oscilloscope->pushSamples (buffer);
analyser->pushSamples (buffer);
}
//==============================================================================
void FoleysSynthAudioProcessor::savePresetInternal()
{
presetNode = magicState.getSettings().getOrCreateChildWithName ("presets", nullptr);
juce::ValueTree preset { "Preset" };
preset.setProperty ("name", "Preset " + juce::String (presetNode.getNumChildren() + 1), nullptr);
foleys::ParameterManager manager (*this);
manager.saveParameterValues (preset);
presetNode.appendChild (preset, nullptr);
}
void FoleysSynthAudioProcessor::loadPresetInternal(int index)
{
presetNode = magicState.getSettings().getOrCreateChildWithName ("presets", nullptr);
auto preset = presetNode.getChild (index);
foleys::ParameterManager manager (*this);
manager.loadParameterValues (preset);
}
//==============================================================================
double FoleysSynthAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
//==============================================================================
// This creates new instances of the plugin..
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new FoleysSynthAudioProcessor();
}