219 lines
7.2 KiB
C++
219 lines
7.2 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
This file contains the basic framework code for a JUCE plugin processor.
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#include "PluginProcessor.h"
|
|
#include "PluginEditor.h"
|
|
|
|
//==============================================================================
|
|
ReverbAudioProcessor::ReverbAudioProcessor()
|
|
#ifndef JucePlugin_PreferredChannelConfigurations
|
|
: AudioProcessor (BusesProperties()
|
|
#if ! JucePlugin_IsMidiEffect
|
|
#if ! JucePlugin_IsSynth
|
|
.withInput ("Input", juce::AudioChannelSet::stereo(), true)
|
|
#endif
|
|
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
|
|
#endif
|
|
)
|
|
#endif
|
|
{
|
|
|
|
addParameter(roomSize = new juce::AudioParameterFloat("roomSize", "Room Size", 0.0, 1.0, 0.5));
|
|
addParameter(damping = new juce::AudioParameterFloat("damping", "Damping", 0.0, 1.0, 0.5));
|
|
addParameter(wetLevel = new juce::AudioParameterFloat("wetLevel", "Wet Level", 0.0, 1.0, 0.5));
|
|
addParameter(dryLevel = new juce::AudioParameterFloat("dryLevel", "Dry Level", 0.0, 1.0, 0.5));
|
|
addParameter(width = new juce::AudioParameterFloat("width", "Width", 0.0, 1.0, 0.5));
|
|
addParameter(freezeMode = new juce::AudioParameterFloat("freezeMode", "Freeze", 0.0, 1.0, 0.5));
|
|
|
|
verb.setSampleRate(48000);
|
|
}
|
|
|
|
ReverbAudioProcessor::~ReverbAudioProcessor()
|
|
{
|
|
}
|
|
|
|
//==============================================================================
|
|
const juce::String ReverbAudioProcessor::getName() const
|
|
{
|
|
return JucePlugin_Name;
|
|
}
|
|
|
|
bool ReverbAudioProcessor::acceptsMidi() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool ReverbAudioProcessor::producesMidi() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool ReverbAudioProcessor::isMidiEffect() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
double ReverbAudioProcessor::getTailLengthSeconds() const
|
|
{
|
|
return 0.0;
|
|
}
|
|
|
|
int ReverbAudioProcessor::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 ReverbAudioProcessor::getCurrentProgram()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void ReverbAudioProcessor::setCurrentProgram (int index)
|
|
{
|
|
}
|
|
|
|
const juce::String ReverbAudioProcessor::getProgramName (int index)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
void ReverbAudioProcessor::changeProgramName (int index, const juce::String& newName)
|
|
{
|
|
}
|
|
|
|
//==============================================================================
|
|
void ReverbAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
|
|
{
|
|
// Use this method as the place to do any pre-playback
|
|
// initialisation that you need..
|
|
verb.reset();
|
|
}
|
|
|
|
void ReverbAudioProcessor::releaseResources()
|
|
{
|
|
// When playback stops, you can use this as an opportunity to free up any
|
|
// spare memory, etc.
|
|
}
|
|
#ifndef JucePlugin_PreferredChannelConfigurations
|
|
bool ReverbAudioProcessor::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
|
|
}
|
|
#endif
|
|
|
|
void ReverbAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
|
|
{
|
|
juce::ScopedNoDenormals noDenormals;
|
|
auto totalNumInputChannels = getTotalNumInputChannels();
|
|
auto totalNumOutputChannels = getTotalNumOutputChannels();
|
|
|
|
|
|
// 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 (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
|
|
buffer.clear (i, 0, buffer.getNumSamples());
|
|
|
|
// This is the place where you'd normally do the guts of your plugin's
|
|
// audio processing...
|
|
// Make sure to reset the state if your inner loop is processing
|
|
// the samples and the outer loop is handling the channels.
|
|
// Alternatively, you can process the samples with the channels
|
|
// interleaved by keeping the same state.
|
|
|
|
/*
|
|
for (int channel = 0; channel < totalNumInputChannels; ++channel)
|
|
{
|
|
auto* channelData = buffer.getWritePointer (channel);
|
|
|
|
// ..do something to the data...
|
|
}
|
|
*/
|
|
update_verb();
|
|
verb.processStereo(buffer.getWritePointer(0), buffer.getWritePointer(1),
|
|
buffer.getNumSamples());
|
|
|
|
}
|
|
|
|
//==============================================================================
|
|
bool ReverbAudioProcessor::hasEditor() const
|
|
{
|
|
return true; // (change this to false if you choose to not supply an editor)
|
|
}
|
|
|
|
juce::AudioProcessorEditor* ReverbAudioProcessor::createEditor()
|
|
{
|
|
return new juce::GenericAudioProcessorEditor (*this);
|
|
}
|
|
|
|
void ReverbAudioProcessor::update_verb()
|
|
{
|
|
params.roomSize = roomSize->get();
|
|
params.damping = damping->get();
|
|
params.wetLevel = wetLevel->get();
|
|
params.dryLevel = dryLevel->get();
|
|
params.width = width->get();
|
|
params.freezeMode = freezeMode->get();
|
|
|
|
verb.setParameters(params);
|
|
}
|
|
|
|
//==============================================================================
|
|
void ReverbAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
|
|
{
|
|
juce::MemoryOutputStream stream(destData, true);
|
|
|
|
stream.writeFloat(*roomSize);
|
|
stream.writeFloat(*damping);
|
|
stream.writeFloat(*wetLevel);
|
|
stream.writeFloat(*dryLevel);
|
|
stream.writeFloat(*width);
|
|
stream.writeFloat(*freezeMode);
|
|
}
|
|
|
|
void ReverbAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
|
|
{
|
|
juce::MemoryInputStream stream(data, static_cast<size_t> (sizeInBytes), false);
|
|
roomSize->setValueNotifyingHost(stream.readFloat());
|
|
damping->setValueNotifyingHost(stream.readFloat());
|
|
wetLevel->setValueNotifyingHost(stream.readFloat());
|
|
dryLevel->setValueNotifyingHost(stream.readFloat());
|
|
width->setValueNotifyingHost(stream.readFloat());
|
|
freezeMode->setValueNotifyingHost(stream.readFloat());
|
|
}
|
|
|
|
//==============================================================================
|
|
// This creates new instances of the plugin..
|
|
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
|
{
|
|
return new ReverbAudioProcessor();
|
|
}
|