forked from getdunne/VanillaJuce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginProcessor.cpp
153 lines (129 loc) · 3.79 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
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include "SynthVoice.h"
VanillaJuceAudioProcessor::VanillaJuceAudioProcessor()
: currentProgram(0)
{
initializePrograms();
for (int i = 0; i < kNumberOfVoices; ++i)
synth.addVoice(new SynthVoice());
pSound = new SynthSound(synth);
pSound->pParams = &programBank[currentProgram];
synth.addSound(pSound);
}
void VanillaJuceAudioProcessor::initializePrograms()
{
for (int i = 0; i < kNumberOfPrograms; i++)
programBank[i].setDefaultValues();
}
const String VanillaJuceAudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool VanillaJuceAudioProcessor::acceptsMidi() const
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool VanillaJuceAudioProcessor::producesMidi() const
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
double VanillaJuceAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int VanillaJuceAudioProcessor::getNumPrograms()
{
return kNumberOfPrograms;
}
int VanillaJuceAudioProcessor::getCurrentProgram()
{
return currentProgram;
}
void VanillaJuceAudioProcessor::setCurrentProgram (int index)
{
currentProgram = index;
pSound->pParams = &programBank[currentProgram];
sendChangeMessage();
}
const String VanillaJuceAudioProcessor::getProgramName (int index)
{
return programBank[index].programName;
}
void VanillaJuceAudioProcessor::changeProgramName (int index, const String& newName)
{
programBank[index].programName = newName;
sendChangeMessage();
}
void VanillaJuceAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
ignoreUnused(samplesPerBlock);
synth.setCurrentPlaybackSampleRate(sampleRate);
}
void VanillaJuceAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
void VanillaJuceAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
}
bool VanillaJuceAudioProcessor::hasEditor() const
{
return true;
}
AudioProcessorEditor* VanillaJuceAudioProcessor::createEditor()
{
return new VanillaJuceAudioProcessorEditor(*this);
}
void VanillaJuceAudioProcessor::getStateInformation (MemoryBlock& destData)
{
XmlElement xml = XmlElement("VanillaJuce");
xml.setAttribute("currentProgram", currentProgram);
XmlElement* xprogs = new XmlElement("programs");
for (int i = 0; i < kNumberOfPrograms; i++)
xprogs->addChildElement(programBank[i].getXml());
xml.addChildElement(xprogs);
copyXmlToBinary(xml, destData);
}
void VanillaJuceAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
ScopedPointer<XmlElement> xml = getXmlFromBinary(data, sizeInBytes);
XmlElement* xprogs = xml->getFirstChildElement();
if (xprogs->hasTagName("programs"))
{
int i = 0;
forEachXmlChildElement(*xprogs, xpr)
{
programBank[i].setDefaultValues();
programBank[i].putXml(xpr);
i++;
}
}
setCurrentProgram(xml->getIntAttribute("currentProgram", 0));
}
void VanillaJuceAudioProcessor::getCurrentProgramStateInformation(MemoryBlock& destData)
{
ScopedPointer<XmlElement> xml = programBank[currentProgram].getXml();
copyXmlToBinary(*xml, destData);
}
void VanillaJuceAudioProcessor::setCurrentProgramStateInformation(const void* data, int sizeInBytes)
{
ScopedPointer<XmlElement> xml = getXmlFromBinary(data, sizeInBytes);
programBank[currentProgram].putXml(xml);
sendChangeMessage();
}
// This creates new instances of the plugin.
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new VanillaJuceAudioProcessor();
}