Skip to content

Commit

Permalink
initial juce::AudioProcessor overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjhood committed Mar 8, 2024
1 parent 98aaef3 commit b194cc2
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 17 deletions.
7 changes: 3 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@
"files.associations": {
"**.bash**": "shellscript",
"**.cmake": "cmake",
"ignore": "ignore",
".editorconfig": "editorconfig",

"ignore": "ignore",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
Expand All @@ -191,7 +190,6 @@
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",

"exception": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
Expand Down Expand Up @@ -266,6 +264,7 @@
"xlocmes": "cpp",
"xlocmon": "cpp",
"xloctime": "cpp",
"xtree": "cpp"
"xtree": "cpp",
"*.mm": "cpp"
}
}
7 changes: 7 additions & 0 deletions include/StoneyDSP/Biquads/PluginEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@ class BiquadsAudioProcessorEditor final : public juce::AudioProcessorEditor
// access the processor object that created it.
BiquadsAudioProcessor& processorRef;

juce::AudioProcessorValueTreeState& state;

juce::UndoManager& undoManager;

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)
};
39 changes: 37 additions & 2 deletions include/StoneyDSP/Biquads/PluginProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

#pragma once

#include <juce_audio_processors/juce_audio_processors.h>
// #include <juce_audio_processors/juce_audio_processors.h>

// #include <JuceHeader.h>
#include <JuceHeader.h>

// #include "PluginParameters.h"
// #include "PluginWrapper.h"
Expand All @@ -27,6 +27,11 @@ class BiquadsAudioProcessor final : public juce::AudioProcessor
BiquadsAudioProcessor();
~BiquadsAudioProcessor() override;

//==========================================================================
juce::AudioProcessorParameter* getBypassParameter() const override;
bool isBypassed() const noexcept;
void setBypassParameter(juce::AudioParameterBool* newBypass) noexcept;

//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
Expand Down Expand Up @@ -57,7 +62,37 @@ class BiquadsAudioProcessor final : 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;

//==========================================================================
/** Undo Manager. */
juce::UndoManager undoManager;
/**
* @brief Get a reference to the UndoManager object.
*
* @return juce::UndoManager&
*/
juce::UndoManager& getUndoManager() { return undoManager; };

//==========================================================================
/** Audio processor value tree. */
juce::AudioProcessorValueTreeState apvts;
/**
* @brief Get a reference to the AudioProcessorValueTreeState object.
*
* @return juce::AudioProcessorValueTreeState&
*/
juce::AudioProcessorValueTreeState& getAPVTS() { return apvts; };
/**
* @brief Create a juce::AudioProcessorValueTreeState::ParameterLayout object.
*
* @return juce::AudioProcessorValueTreeState::ParameterLayout
*/
static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout();

juce::AudioParameterBool* bypassState { nullptr };

private:
//==============================================================================
Expand Down
5 changes: 4 additions & 1 deletion src/StoneyDSP/Biquads/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

//==============================================================================
BiquadsAudioProcessorEditor::BiquadsAudioProcessorEditor (BiquadsAudioProcessor& p)
: AudioProcessorEditor (&p), processorRef (p)
: AudioProcessorEditor (&p)
, processorRef(p)
, state(p.getAPVTS())
, undoManager(p.getUndoManager())
{
juce::ignoreUnused (processorRef);
// Make sure that before the constructor has finished, you've set the
Expand Down
88 changes: 78 additions & 10 deletions src/StoneyDSP/Biquads/PluginProcessor.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,58 @@
/**
* @file PluginProcessor.cpp
* @author StoneyDSP ([email protected])
* @brief
* @version 0.1
* @date 2023-09-07
*
* @copyright Copyright (c) 2023
*
*/

#include "StoneyDSP/Biquads/PluginProcessor.hpp"
#include "StoneyDSP/Biquads/PluginEditor.hpp"

//==============================================================================
BiquadsAudioProcessor::BiquadsAudioProcessor()
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", juce::AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
#endif
)
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", juce::AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
#endif
)
, undoManager()
, apvts(*this, &undoManager, "Parameters", createParameterLayout())
, bypassState (dynamic_cast<juce::AudioParameterBool*>(apvts.getParameter("bypassID")))
{
}

BiquadsAudioProcessor::~BiquadsAudioProcessor()
{
}

//==============================================================================
juce::AudioProcessorParameter* BiquadsAudioProcessor::getBypassParameter() const
{
return bypassState;
}

bool BiquadsAudioProcessor::isBypassed() const noexcept
{
return bypassState->get() == true;
}

void BiquadsAudioProcessor::setBypassParameter(juce::AudioParameterBool* newBypass) noexcept
{
if (bypassState != newBypass)
{
bypassState = newBypass;
releaseResources();
reset();
}
}

//==============================================================================
const juce::String BiquadsAudioProcessor::getName() const
{
Expand Down Expand Up @@ -164,20 +199,53 @@ juce::AudioProcessorEditor* BiquadsAudioProcessor::createEditor()
return new BiquadsAudioProcessorEditor (*this);
}

juce::AudioProcessorValueTreeState::ParameterLayout BiquadsAudioProcessor::createParameterLayout()
{
juce::AudioProcessorValueTreeState::ParameterLayout parameterLayout;

parameterLayout.add(std::make_unique<juce::AudioParameterBool>("bypassID", "Bypass", false));

// Parameters::setParameterLayout(parameterLayout);

return parameterLayout;
}

//==============================================================================
void BiquadsAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.
juce::ignoreUnused (destData);
auto state = apvts.copyState();
std::unique_ptr<juce::XmlElement> xml(state.createXml());
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)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
juce::ignoreUnused (data, 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));
}

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));
}

//==============================================================================
Expand Down

0 comments on commit b194cc2

Please sign in to comment.