Skip to content

Commit

Permalink
Merge pull request #46 from StoneyDSP/Develop
Browse files Browse the repository at this point in the history
Refactored internals
  • Loading branch information
nathanjhood authored Jun 13, 2022
2 parents a0342c3 + bddcc6b commit 691eb2f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 38 deletions.
24 changes: 8 additions & 16 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@ BiquadsAudioProcessorEditor::BiquadsAudioProcessorEditor (BiquadsAudioProcessor&
audioProcessor (p),
state(apvts),
undoManager(um),
/*knobComponents(p, apvts),
buttonComponents(p, apvts),
comboBoxComponents(p, apvts),*/
subComponents(p, apvts),
undoButton("Undo"),
redoButton("Redo")
subComponents(p, apvts)
{
setSize(400, 300);
/*addAndMakeVisible(buttonComponents);
addAndMakeVisible(knobComponents);
addAndMakeVisible(comboBoxComponents);*/
addAndMakeVisible(subComponents);
addAndMakeVisible(undoButton);
addAndMakeVisible(redoButton);
undoButton.onClick = [this] { undoManager.undo(); };
redoButton.onClick = [this] { undoManager.redo(); };
setResizable(true, false);
setResizable(true, true);

startTimerHz(24);
}
Expand All @@ -44,10 +36,6 @@ BiquadsAudioProcessorEditor::~BiquadsAudioProcessorEditor()
////==============================================================================
void BiquadsAudioProcessorEditor::timerCallback()
{
/*knobComponents.resized();
buttonComponents.resized();
comboBoxComponents.resized();*/
undoManager.beginNewTransaction();
}

//==============================================================================
Expand All @@ -65,11 +53,15 @@ void BiquadsAudioProcessorEditor::paint (juce::Graphics& g)
g.setFont(15.0f);
g.drawFittedText(ProjectInfo::companyName, getLocalBounds(), juce::Justification::topLeft, 1);
g.drawFittedText(ProjectInfo::projectName, getLocalBounds(), juce::Justification::topRight, 1);
g.drawFittedText(ProjectInfo::versionString, getLocalBounds(), juce::Justification::bottomRight, 1);
g.drawFittedText(ProjectInfo::versionString, getLocalBounds(), juce::Justification::bottomLeft, 1);
}

void BiquadsAudioProcessorEditor::resized()
{
subComponents.resized();
subComponents.setBounds(0, 0, getWidth(), getHeight());
undoButton.setBounds((getWidth() / 2) - 10, getHeight() - 20, 20, 20);
redoButton.setBounds((getWidth() / 2) + 10, getHeight() - 20, 20, 20);
subComponents.resized();
undoButton.resized();
redoButton.resized();
}
10 changes: 3 additions & 7 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

#include "../JuceLibraryCode/JuceHeader.h"
#include "PluginProcessor.h"
//#include "Components/AutoKnob.h"
//#include "Components/AutoButton.h"
//#include "Components/AutoComboBox.h"
#include "Components/AutoComponent.h"

//==============================================================================
Expand All @@ -39,11 +36,10 @@ class BiquadsAudioProcessorEditor : public juce::AudioProcessorEditor, public j
APVTS& state;
juce::UndoManager& undoManager;

/*AutoKnob knobComponents;
AutoButton buttonComponents;
AutoComboBox comboBoxComponents;*/
AutoComponent subComponents;
juce::TextButton undoButton, redoButton;

juce::ArrowButton undoButton{ "Undo", 0.5f , juce::Colours::white };
juce::ArrowButton redoButton{ "Redo", 0.0f , juce::Colours::white };

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BiquadsAudioProcessorEditor)
};
4 changes: 1 addition & 3 deletions Source/PluginParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ void Parameters::setParameterLayout(Params& params)
std::make_unique<juce::AudioParameterChoice>("osID", "Oversampling", osString, 0),
std::make_unique<juce::AudioParameterFloat>("outputID", "Output", outputRange, 00.00f, decibels, outParam),
std::make_unique<juce::AudioParameterFloat>("mixID", "Mix", mixRange, 100.00f, percentage, genParam),
std::make_unique<juce::AudioParameterBool>("bypassID", "Bypass", false),
std::make_unique<juce::AudioParameterBool>("undoID", "Undo", false),
std::make_unique<juce::AudioParameterBool>("redoID", "Redo", false)
std::make_unique<juce::AudioParameterBool>("bypassID", "Bypass", false)
//==================================================================
));

Expand Down
36 changes: 31 additions & 5 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ void BiquadsAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBloc
{
getProcessingPrecision();

processorFloat.prepare(sampleRate, samplesPerBlock);
processorDouble.prepare(sampleRate, samplesPerBlock);
processorFloat.prepare();
processorDouble.prepare();
}

void BiquadsAudioProcessor::releaseResources()
Expand All @@ -127,17 +127,26 @@ void BiquadsAudioProcessor::releaseResources()

void BiquadsAudioProcessor::numChannelsChanged()
{
releaseResources();
processorFloat.reset();
processorDouble.reset();
processorFloat.prepare();
processorDouble.prepare();
}

void BiquadsAudioProcessor::numBusesChanged()
{
releaseResources();
processorFloat.reset();
processorDouble.reset();
processorFloat.prepare();
processorDouble.prepare();
}

void BiquadsAudioProcessor::processorLayoutsChanged()
{
releaseResources();
processorFloat.reset();
processorDouble.reset();
processorFloat.prepare();
processorDouble.prepare();
}

bool BiquadsAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
Expand Down Expand Up @@ -227,6 +236,14 @@ void BiquadsAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
copyXmlToBinary(*xml, destData);
}

void BiquadsAudioProcessor::getCurrentProgramStateInformation(juce::MemoryBlock& destData)
{
auto state = apvts.copyState();
std::unique_ptr<juce::XmlElement> xml(state.createXml());
copyXmlToBinary(*xml, destData);
}


void BiquadsAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
std::unique_ptr<juce::XmlElement> xmlState(getXmlFromBinary(data, sizeInBytes));
Expand All @@ -236,6 +253,15 @@ void BiquadsAudioProcessor::setStateInformation (const void* data, int sizeInByt
apvts.replaceState(juce::ValueTree::fromXml(*xmlState));
}

void BiquadsAudioProcessor::setCurrentProgramStateInformation(const void* data, int sizeInBytes)
{
std::unique_ptr<juce::XmlElement> xmlState(getXmlFromBinary(data, sizeInBytes));

if (xmlState.get() != nullptr)
if (xmlState->hasTagName(apvts.state.getType()))
apvts.replaceState(juce::ValueTree::fromXml(*xmlState));
}

//==============================================================================
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
Expand Down
4 changes: 3 additions & 1 deletion Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BiquadsAudioProcessor : public juce::AudioProcessor
~BiquadsAudioProcessor() override;

//==========================================================================
juce::AudioProcessorParameter* getBypassParameter() const;
juce::AudioProcessorParameter* getBypassParameter() const override;
bool supportsDoublePrecisionProcessing() const override;
ProcessingPrecision getProcessingPrecision() const noexcept;
bool isUsingDoublePrecision() const noexcept;
Expand Down Expand Up @@ -68,7 +68,9 @@ class BiquadsAudioProcessor : public juce::AudioProcessor

//==========================================================================
void getStateInformation (juce::MemoryBlock& destData) override;
void getCurrentProgramStateInformation(juce::MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override;
void setCurrentProgramStateInformation(const void* data, int sizeInBytes) override;

//==========================================================================
/** Audio processor value tree. */
Expand Down
19 changes: 14 additions & 5 deletions Source/PluginWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ ProcessWrapper<SampleType>::ProcessWrapper(BiquadsAudioProcessor& p, APVTS& apvt
}

template <typename SampleType>
void ProcessWrapper<SampleType>::prepare(double sampleRate, int samplesPerBlock)
void ProcessWrapper<SampleType>::prepare()
{
overSamplingFactor = 1 << curOS;
prevOS = curOS;

spec.sampleRate = sampleRate;
spec.maximumBlockSize = samplesPerBlock;
spec.sampleRate = audioProcessor.getSampleRate() * overSamplingFactor;
spec.maximumBlockSize = audioProcessor.getBlockSize();
spec.numChannels = audioProcessor.getTotalNumInputChannels();

for (int i = 0; i < 5; ++i)
Expand All @@ -76,6 +76,7 @@ template <typename SampleType>
void ProcessWrapper<SampleType>::reset()
{
mixer.reset();
mixer.setWetLatency(getLatencySamples());
biquad.reset(static_cast<SampleType>(0.0));
output.reset();

Expand Down Expand Up @@ -113,7 +114,7 @@ void ProcessWrapper<SampleType>::process(juce::AudioBuffer<SampleType>& buffer,
template <typename SampleType>
void ProcessWrapper<SampleType>::update()
{
spec.sampleRate = audioProcessor.getSampleRate();
spec.sampleRate = audioProcessor.getSampleRate() * overSamplingFactor;
spec.maximumBlockSize = audioProcessor.getBlockSize();
spec.numChannels = audioProcessor.getTotalNumInputChannels();

Expand All @@ -139,11 +140,19 @@ void ProcessWrapper<SampleType>::setOversampling()
overSamplingFactor = 1 << curOS;
prevOS = curOS;
mixer.reset();
mixer.setWetLatency(getLatencySamples());
biquad.reset(static_cast<SampleType>(0.0));
biquad.sampleRate = spec.sampleRate * overSamplingFactor;
//biquad.sampleRate = spec.sampleRate * overSamplingFactor;
output.reset();
}
}

template <typename SampleType>
SampleType ProcessWrapper<SampleType>::getLatencySamples() const noexcept
{
// latency of oversampling
return overSample[curOS]->getLatencyInSamples();
}
//==============================================================================
template class ProcessWrapper<float>;
template class ProcessWrapper<double>;
4 changes: 3 additions & 1 deletion Source/PluginWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProcessWrapper

//==========================================================================
/** Initialises the processor. */
void prepare(double sampleRate, int samplesPerBlock);
void prepare();

/** Resets the internal state variables of the processor. */
void reset();
Expand All @@ -45,6 +45,8 @@ class ProcessWrapper
/** Sets the oversampling factor. */
void setOversampling();

SampleType getLatencySamples() const noexcept;

private:
//==========================================================================
// This reference is provided as a quick way for the wrapper to
Expand Down

0 comments on commit 691eb2f

Please sign in to comment.