1 /*
2   ==============================================================================
3 
4     This file contains the basic framework code for a JUCE plugin processor.
5 
6   ==============================================================================
7 */
8 
9 %%filter_headers%%
10 
11 //==============================================================================
12 %%filter_class_name%%::%%filter_class_name%%()
13 #ifndef JucePlugin_PreferredChannelConfigurations
14      : AudioProcessor (BusesProperties()
15                      #if ! JucePlugin_IsMidiEffect
16                       #if ! JucePlugin_IsSynth
17                        .withInput  ("Input",  juce::AudioChannelSet::stereo(), true)
18                       #endif
19                        .withOutput ("Output", juce::AudioChannelSet::stereo(), true)
20                      #endif
21                        )
22 #endif
23 {
24 }
25 
26 %%filter_class_name%%::~%%filter_class_name%%()
27 {
28 }
29 
30 //==============================================================================
31 const juce::String %%filter_class_name%%::getName() const
32 {
33     return JucePlugin_Name;
34 }
35 
36 bool %%filter_class_name%%::acceptsMidi() const
37 {
38    #if JucePlugin_WantsMidiInput
39     return true;
40    #else
41     return false;
42    #endif
43 }
44 
45 bool %%filter_class_name%%::producesMidi() const
46 {
47    #if JucePlugin_ProducesMidiOutput
48     return true;
49    #else
50     return false;
51    #endif
52 }
53 
54 bool %%filter_class_name%%::isMidiEffect() const
55 {
56    #if JucePlugin_IsMidiEffect
57     return true;
58    #else
59     return false;
60    #endif
61 }
62 
63 double %%filter_class_name%%::getTailLengthSeconds() const
64 {
65     return 0.0;
66 }
67 
68 int %%filter_class_name%%::getNumPrograms()
69 {
70     return 1;   // NB: some hosts don't cope very well if you tell them there are 0 programs,
71                 // so this should be at least 1, even if you're not really implementing programs.
72 }
73 
74 int %%filter_class_name%%::getCurrentProgram()
75 {
76     return 0;
77 }
78 
79 void %%filter_class_name%%::setCurrentProgram (int index)
80 {
81 }
82 
83 const juce::String %%filter_class_name%%::getProgramName (int index)
84 {
85     return {};
86 }
87 
88 void %%filter_class_name%%::changeProgramName (int index, const juce::String& newName)
89 {
90 }
91 
92 //==============================================================================
93 void %%filter_class_name%%::prepareToPlay (double sampleRate, int samplesPerBlock)
94 {
95     // Use this method as the place to do any pre-playback
96     // initialisation that you need..
97 }
98 
99 void %%filter_class_name%%::releaseResources()
100 {
101     // When playback stops, you can use this as an opportunity to free up any
102     // spare memory, etc.
103 }
104 
105 #ifndef JucePlugin_PreferredChannelConfigurations
106 bool %%filter_class_name%%::isBusesLayoutSupported (const BusesLayout& layouts) const
107 {
108   #if JucePlugin_IsMidiEffect
109     juce::ignoreUnused (layouts);
110     return true;
111   #else
112     // This is the place where you check if the layout is supported.
113     // In this template code we only support mono or stereo.
114     // Some plugin hosts, such as certain GarageBand versions, will only
115     // load plugins that support stereo bus layouts.
116     if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
117      && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
118         return false;
119 
120     // This checks if the input layout matches the output layout
121    #if ! JucePlugin_IsSynth
122     if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
123         return false;
124    #endif
125 
126     return true;
127   #endif
128 }
129 #endif
130 
131 void %%filter_class_name%%::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
132 {
133     juce::ScopedNoDenormals noDenormals;
134     auto totalNumInputChannels  = getTotalNumInputChannels();
135     auto totalNumOutputChannels = getTotalNumOutputChannels();
136 
137     // In case we have more outputs than inputs, this code clears any output
138     // channels that didn't contain input data, (because these aren't
139     // guaranteed to be empty - they may contain garbage).
140     // This is here to avoid people getting screaming feedback
141     // when they first compile a plugin, but obviously you don't need to keep
142     // this code if your algorithm always overwrites all the output channels.
143     for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
144         buffer.clear (i, 0, buffer.getNumSamples());
145 
146     // This is the place where you'd normally do the guts of your plugin's
147     // audio processing...
148     // Make sure to reset the state if your inner loop is processing
149     // the samples and the outer loop is handling the channels.
150     // Alternatively, you can process the samples with the channels
151     // interleaved by keeping the same state.
152     for (int channel = 0; channel < totalNumInputChannels; ++channel)
153     {
154         auto* channelData = buffer.getWritePointer (channel);
155 
156         // ..do something to the data...
157     }
158 }
159 
160 //==============================================================================
161 bool %%filter_class_name%%::hasEditor() const
162 {
163     return true; // (change this to false if you choose to not supply an editor)
164 }
165 
166 juce::AudioProcessorEditor* %%filter_class_name%%::createEditor()
167 {
168     return new %%editor_class_name%% (*this);
169 }
170 
171 //==============================================================================
172 void %%filter_class_name%%::getStateInformation (juce::MemoryBlock& destData)
173 {
174     // You should use this method to store your parameters in the memory block.
175     // You could do that either as raw data, or use the XML or ValueTree classes
176     // as intermediaries to make it easy to save and load complex data.
177 }
178 
179 void %%filter_class_name%%::setStateInformation (const void* data, int sizeInBytes)
180 {
181     // You should use this method to restore your parameters from this memory block,
182     // whose contents will have been created by the getStateInformation() call.
183 }
184 
185 //==============================================================================
186 // This creates new instances of the plugin..
createPluginFilter()187 juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
188 {
189     return new %%filter_class_name%%();
190 }
191