mirror of
https://codeberg.org/armin/beamgrid.git
synced 2026-09-01 04:10:47 +02:00
116 lines
4 KiB
C++
116 lines
4 KiB
C++
|
|
#include "PluginProcessor.h"
|
||
|
|
#include "PluginEditor.h"
|
||
|
|
|
||
|
|
BeamgridAudioProcessor::BeamgridAudioProcessor()
|
||
|
|
: AudioProcessor (BusesProperties()
|
||
|
|
.withInput ("Input", juce::AudioChannelSet::stereo(), true)
|
||
|
|
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)),
|
||
|
|
params (*this, nullptr, "Parameters", createParameterLayout())
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
BeamgridAudioProcessor::~BeamgridAudioProcessor() = default;
|
||
|
|
|
||
|
|
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
||
|
|
{
|
||
|
|
return new BeamgridAudioProcessor();
|
||
|
|
}
|
||
|
|
|
||
|
|
juce::AudioProcessorValueTreeState::ParameterLayout
|
||
|
|
BeamgridAudioProcessor::createParameterLayout()
|
||
|
|
{
|
||
|
|
std::vector<std::unique_ptr<juce::RangedAudioParameter>> params;
|
||
|
|
|
||
|
|
params.push_back (std::make_unique<juce::AudioParameterFloat>(
|
||
|
|
"grace", "Peak Grace (ms)",
|
||
|
|
juce::NormalisableRange<float> (0.0f, 2000.0f, 1.0f), 800.0f,
|
||
|
|
juce::AudioParameterFloatAttributes().withLabel ("ms")));
|
||
|
|
|
||
|
|
params.push_back (std::make_unique<juce::AudioParameterFloat>(
|
||
|
|
"falloff", "Peak Falloff",
|
||
|
|
juce::NormalisableRange<float> (0.0f, 1.0f, 0.001f), 0.4f,
|
||
|
|
juce::AudioParameterFloatAttributes().withLabel ("")));
|
||
|
|
|
||
|
|
params.push_back (std::make_unique<juce::AudioParameterFloat>(
|
||
|
|
"barfalloff", "Bar Falloff",
|
||
|
|
juce::NormalisableRange<float> (0.0f, 1.0f, 0.001f), 0.5f,
|
||
|
|
juce::AudioParameterFloatAttributes().withLabel ("")));
|
||
|
|
|
||
|
|
params.push_back (std::make_unique<juce::AudioParameterFloat>(
|
||
|
|
"hue", "Hue",
|
||
|
|
juce::NormalisableRange<float> (0.0f, 1.0f, 0.001f), 0.5f,
|
||
|
|
juce::AudioParameterFloatAttributes().withLabel ("")));
|
||
|
|
|
||
|
|
juce::NormalisableRange<float> barsRange (8.0f, 128.0f,
|
||
|
|
[] (float, float, float v) { return v; }, // convertFrom0To1
|
||
|
|
[] (float, float, float v) { return v; }, // convertTo0To1
|
||
|
|
[] (float, float, float v) // snapToLegalValue
|
||
|
|
{
|
||
|
|
const float steps[] = { 8.0f, 16.0f, 32.0f, 64.0f, 96.0f, 128.0f };
|
||
|
|
float best = steps[0];
|
||
|
|
float bestDist = std::abs (v - best);
|
||
|
|
for (float s : steps)
|
||
|
|
{
|
||
|
|
const float dist = std::abs (v - s);
|
||
|
|
if (dist < bestDist)
|
||
|
|
{
|
||
|
|
bestDist = dist;
|
||
|
|
best = s;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return best;
|
||
|
|
});
|
||
|
|
|
||
|
|
params.push_back (std::make_unique<juce::AudioParameterFloat>(
|
||
|
|
"bars", "Bars", barsRange, 64.0f));
|
||
|
|
|
||
|
|
return { params.begin(), params.end() };
|
||
|
|
}
|
||
|
|
|
||
|
|
void BeamgridAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
|
||
|
|
{
|
||
|
|
analyser.prepare (sampleRate, samplesPerBlock);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BeamgridAudioProcessor::releaseResources() {}
|
||
|
|
|
||
|
|
bool BeamgridAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
|
||
|
|
{
|
||
|
|
if (layouts.getMainInputChannels() == 0 ||
|
||
|
|
layouts.getMainOutputChannels() == 0)
|
||
|
|
return false;
|
||
|
|
|
||
|
|
if (layouts.getMainInputChannels() != layouts.getMainOutputChannels())
|
||
|
|
return false;
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
void BeamgridAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
|
||
|
|
juce::MidiBuffer& /*midi*/)
|
||
|
|
{
|
||
|
|
juce::ScopedNoDenormals noDenormals;
|
||
|
|
|
||
|
|
// Analyse the first channel; pass the audio through unchanged.
|
||
|
|
if (buffer.getNumChannels() > 0)
|
||
|
|
analyser.push (buffer.getReadPointer (0), buffer.getNumSamples());
|
||
|
|
}
|
||
|
|
|
||
|
|
juce::AudioProcessorEditor* BeamgridAudioProcessor::createEditor()
|
||
|
|
{
|
||
|
|
return new BeamgridAudioProcessorEditor (*this);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BeamgridAudioProcessor::getStateInformation (juce::MemoryBlock& dest)
|
||
|
|
{
|
||
|
|
auto state = params.copyState();
|
||
|
|
std::unique_ptr<juce::XmlElement> xml (state.createXml());
|
||
|
|
copyXmlToBinary (*xml, dest);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BeamgridAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
|
||
|
|
{
|
||
|
|
std::unique_ptr<juce::XmlElement> xml (getXmlFromBinary (data, sizeInBytes));
|
||
|
|
if (xml && xml->hasTagName (params.state.getType()))
|
||
|
|
params.replaceState (juce::ValueTree::fromXml (*xml));
|
||
|
|
}
|