Hello all,
I am not getting any difference in my audio Signal when running in the audio plugin host, I have print statements in the prepare and process block functions of all the node classes/objects none of which are being printed when I run it in the pluginHost, I (believe) I have copied the Cascading Plugins tutorial correctly, My main class, which I believe to be the problem is attached:
#include "PluginProcessor.h"
#include "PluginEditor.h"
//==============================================================================
HRTFPluginV2AudioProcessor::HRTFPluginV2AudioProcessor()
#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
), //MY CODE
mainProcessor (new juce::AudioProcessorGraph()),
muteInput (new juce::AudioParameterBool("muteInput", "Mute Input", true)),
processorSlot1 (new juce::AudioParameterChoice("processorSlot1", "Processor Slot 1", processorChoices, 0)),
processorSlot2 (new juce::AudioParameterChoice("processorSlot2", "Processor Slot 2", processorChoices, 0)),
processorSlot3 (new juce::AudioParameterChoice("processorSlot3", "Processor Slot 3", processorChoices, 0)),
processorSlot4 (new juce::AudioParameterChoice("processorSlot4", "Processor Slot 4", processorChoices, 0)),
bypassSlot1 (new juce::AudioParameterBool("bypassSlot1", "Bypass Slot 1", false)),
bypassSlot2 (new juce::AudioParameterBool("bypassSlot2", "Bypass Slot 2", false)),
bypassSlot3 (new juce::AudioParameterBool("bypassSlot3", "Bypass Slot 3", false)),
bypassSlot4 (new juce::AudioParameterBool("bypassSlot4", "Bypass Slot 4", false)),
//==============================================================================
treeState(*this, nullptr, "PARAMETERS", createParameterLayout())
#endif
{
{std::make_unique<juce::AudioParameterBool>("muteInput", "Mute Input", true),
std::make_unique<juce::AudioParameterChoice>("processorSlot1", "Processor Slot 1", processorChoices, 0),
std::make_unique<juce::AudioParameterChoice>("processorSlot2", "Processor Slot 2", processorChoices, 0),
std::make_unique<juce::AudioParameterChoice>("processorSlot3", "Processor Slot 3", processorChoices, 0),
std::make_unique<juce::AudioParameterChoice>("processorSlot4", "Processor Slot 4", processorChoices, 0),
std::make_unique<juce::AudioParameterBool>("bypassSlot1", "Bypass Slot 1", false),
std::make_unique<juce::AudioParameterBool>("bypassSlot2", "Bypass Slot 2", false),
std::make_unique<juce::AudioParameterBool>("bypassSlot3", "Bypass Slot 3", false),
std::make_unique<juce::AudioParameterBool>("bypassSlot4", "Bypass Slot 4", false);};
//==Tree naming==
variableTree = {
"Variables", {},
{
{ "Group", {{"name", "IR Vars"}},
{
{ "Parameters", {{"id", "file1"}, {"value", "/"}}},
{ "Parameters", {{"id", "root"}, {"value", "/"}}}
}
}
}
};
}
HRTFPluginV2AudioProcessor::~HRTFPluginV2AudioProcessor()
{
}
//==============================================================================
juce::AudioProcessorValueTreeState::ParameterLayout HRTFPluginV2AudioProcessor::createParameterLayout()
{
std::vector<std::unique_ptr<juce::RangedAudioParameter>> params;
return { params.begin(), params.end() };
}
void HRTFPluginV2AudioProcessor::parameterChanged(const juce::String& parameterID, float newValue)
{
}
const juce::String HRTFPluginV2AudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool HRTFPluginV2AudioProcessor::acceptsMidi() const
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool HRTFPluginV2AudioProcessor::producesMidi() const
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
bool HRTFPluginV2AudioProcessor::isMidiEffect() const
{
#if JucePlugin_IsMidiEffect
return true;
#else
return false;
#endif
}
double HRTFPluginV2AudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int HRTFPluginV2AudioProcessor::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 HRTFPluginV2AudioProcessor::getCurrentProgram()
{
return 0;
}
void HRTFPluginV2AudioProcessor::setCurrentProgram (int index)
{
}
const juce::String HRTFPluginV2AudioProcessor::getProgramName (int index)
{
return {};
}
void HRTFPluginV2AudioProcessor::changeProgramName (int index, const juce::String& newName)
{
}
//==============================================================================
void HRTFPluginV2AudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
// Use this method as the place to do any pre-playback
// initialisation that you need..
mainProcessor->setPlayConfigDetails(getMainBusNumInputChannels(), getMainBusNumOutputChannels(), sampleRate, samplesPerBlock);
mainProcessor->prepareToPlay(sampleRate, samplesPerBlock);
// HRTFpluginV2AudioProcessor::initialiseGraph();
initialiseGraph();
}
void HRTFPluginV2AudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
mainProcessor->releaseResources();
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool HRTFPluginV2AudioProcessor::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 HRTFPluginV2AudioProcessor::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.
updateGraph();
mainProcessor->processBlock(buffer, midiMessages);
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer (channel);
// ..do something to the data...
}
}
//==============================================================================
bool HRTFPluginV2AudioProcessor::hasEditor() const
{
return true; // (change this to false if you choose to not supply an editor)
}
juce::AudioProcessorEditor* HRTFPluginV2AudioProcessor::createEditor()
{
return new HRTFPluginV2AudioProcessorEditor (*this);
}
//==============================================================================
void HRTFPluginV2AudioProcessor::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.
//===Impulse Response===//
treeState.state.appendChild(variableTree, nullptr);
juce::MemoryOutputStream stream(destData, false);
treeState.state.writeToStream(stream);
}
void HRTFPluginV2AudioProcessor::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.
//===Impulse Response===//
auto tree = juce::ValueTree::readFromData(data, size_t(sizeInBytes));
variableTree = tree.getChildWithName("Variables");
if (tree.isValid()) {
treeState.state = tree;
savedFile = juce::File(variableTree.getProperty("file1"));
root = juce::File(variableTree.getProperty("root"));
}
}
//==============================================================================
// This creates new instances of the plugin..
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new HRTFPluginV2AudioProcessor();
}
//================================MY METHODS====================================
void HRTFPluginV2AudioProcessor::initialiseGraph(){
mainProcessor->clear();
audioInputNode = mainProcessor->addNode (std::make_unique<AudioGraphIOProcessor> (AudioGraphIOProcessor::audioInputNode));
audioOutputNode = mainProcessor->addNode (std::make_unique<AudioGraphIOProcessor> (AudioGraphIOProcessor::audioOutputNode));
midiInputNode = mainProcessor->addNode (std::make_unique<AudioGraphIOProcessor> (AudioGraphIOProcessor::midiInputNode));
midiOutputNode = mainProcessor->addNode (std::make_unique<AudioGraphIOProcessor> (AudioGraphIOProcessor::midiOutputNode));
connectAudioNodes();
connectMidiNodes();
}
void HRTFPluginV2AudioProcessor::connectAudioNodes(){
for(int channel = 0; channel < getMainBusNumInputChannels(); channel++){
mainProcessor->addConnection({{audioInputNode->nodeID, channel},
{audioOutputNode->nodeID, channel} });
}
}
void HRTFPluginV2AudioProcessor::connectMidiNodes() {
mainProcessor->addConnection({{midiInputNode->nodeID, juce::AudioProcessorGraph::midiChannelIndex},
{midiOutputNode->nodeID, juce::AudioProcessorGraph::midiChannelIndex} });
}
void HRTFPluginV2AudioProcessor::updateGraph() {
bool hasChanged = false;
// juce::Array<juce::AudioParameterChoice*> choices {processorSlot1,
// processorSlot2,
// processorSlot3,
// processorSlot4};
//new system to avoid mem leaks ---
juce::Array<std::unique_ptr<juce::AudioParameterChoice>> choices;
choices.add(std::move(std::make_unique<juce::AudioParameterChoice>("processorSlot1", "Processor Slot 1", processorChoices, 0)));
choices.add(std::move(std::make_unique<juce::AudioParameterChoice>("processorSlot2", "Processor Slot 2", processorChoices, 0)));
choices.add(std::move(std::make_unique<juce::AudioParameterChoice>("processorSlot3", "Processor Slot 3", processorChoices, 0)));
choices.add(std::move(std::make_unique<juce::AudioParameterChoice>("processorSlot4", "Processor Slot 4", processorChoices, 0)));
// juce::Array<juce::AudioParameterBool*> bypasses {bypassSlot1,
// bypassSlot2,
// bypassSlot3,
// bypassSlot4};
juce::Array<std::unique_ptr<juce::AudioParameterBool>> bypasses;
bypasses.add(std::move(std::make_unique<juce::AudioParameterBool>("bypassSlot1", "Bypass Slot 1", false)));
bypasses.add(std::move(std::make_unique<juce::AudioParameterBool>("bypassSlot2", "Bypass Slot 2", false)));
bypasses.add(std::move(std::make_unique<juce::AudioParameterBool>("bypassSlot3", "Bypass Slot 3", false)));
bypasses.add(std::move(std::make_unique<juce::AudioParameterBool>("bypassSlot4", "Bypass Slot 4", false)));
juce::ReferenceCountedArray<Node> slots;
slots.add(slot1Node);
slots.add(slot2Node);
slots.add(slot3Node);
slots.add(slot4Node);
for (int i = 0; i < 4; ++i) {
auto& choice = choices.getReference (i);
auto slot = slots .getUnchecked (i);
if (choice->getIndex() == 0) {
if (slot != nullptr) {
mainProcessor->removeNode (slot.get());
slots.set (i, nullptr);
hasChanged = true;
}
}
else if (choice->getIndex() == 1) {
if (slot != nullptr) {
if (slot->getProcessor()->getName() == "HRTFProcessor"){
std::cout << "choice is HRTFProcessor" << std::endl;
continue;
}
mainProcessor->removeNode (slot.get());
}//instance of HRTFProcessor
slots.set (i, mainProcessor->addNode (std::make_unique<HRTFProcessor>()));
hasChanged = true;
}
else if (choice->getIndex() == 2) {
if (slot != nullptr) {
if (slot->getProcessor()->getName() == "EarlyReflections"){
std::cout << "choice is EarlyReflections" << std::endl;
continue;
}
mainProcessor->removeNode (slot.get());
}
slots.set (i, mainProcessor->addNode (std::make_unique<EarlyReflections>()));
hasChanged = true;
}
else if (choice->getIndex() == 3) {
if (slot != nullptr) {
if (slot->getProcessor()->getName() == "AirAbsorption"){
std::cout << "choice is AirAbsorption" << std::endl;
continue;
}
mainProcessor->removeNode (slot.get());
}
slots.set (i, mainProcessor->addNode (std::make_unique<AirAbsorption>()));
hasChanged = true;
}
else if ( choice->getIndex() == 4) {
if (slot != nullptr) {
if (slot->getProcessor()->getName() == "OpenGL"){
std::cout << "choice is OpenGL" << std::endl;
continue;
}
mainProcessor->removeNode (slot.get());
}
slots.set (i, mainProcessor->addNode (std::make_unique<OpenGLComponent>()));
hasChanged = true;
}
}
// If the graph has changed, we'll need to re-connect the nodes.
if (hasChanged) {
std::cout << "hasChanged = true" << std::endl;
for (auto connection : mainProcessor->getConnections()){ //remove all connections
std::cout << "removing connection" << std::endl;
// std::cout << "connection is: " << connection << std::endl;
mainProcessor->removeConnection (connection);
}
juce::ReferenceCountedArray<Node> activeSlots;
for (auto slot : slots) {
if (slot != nullptr) {
activeSlots.add (slot);
slot->getProcessor()->setPlayConfigDetails (getMainBusNumInputChannels(),
getMainBusNumOutputChannels(),
getSampleRate(), getBlockSize());
}
}
if (activeSlots.isEmpty()) { //if no active slots, connect input to output
std::cout << "activeSlots is empty" << std::endl;
connectAudioNodes();
} else {
for (int i = 0; i < activeSlots.size() - 1; ++i) { //connect slots in series
// std::cout << "active slots are: " << activeSlots << std::endl;
for (int channel = 0; channel < 2; ++channel) {
mainProcessor->addConnection ({ { activeSlots.getUnchecked (i)->nodeID, channel },
{ activeSlots.getUnchecked (i + 1)->nodeID, channel } });
}
}
for (int channel = 0; channel < 2; ++channel) { //connect input and output to first and last slots
mainProcessor->addConnection ({ { audioInputNode->nodeID, channel },
{ activeSlots.getFirst()->nodeID, channel } });
mainProcessor->addConnection ({ { activeSlots.getLast()->nodeID, channel },
{ audioOutputNode->nodeID, channel } });
}
}
connectMidiNodes();
for (auto node : mainProcessor->getNodes()) { //enable all buses
node->getProcessor()->enableAllBuses();
}
//deal with bypass state
for (int i = 0; i < 4; ++i) {
auto slot = slots .getUnchecked (i);
auto& bypass = bypasses.getReference (i);
if (slot != nullptr){
slot->setBypassed (bypass->get());
}
}
audioInputNode->setBypassed (muteInput->get());
slot1Node = slots.getUnchecked (0);
slot2Node = slots.getUnchecked (1);
slot3Node = slots.getUnchecked (2);
slot4Node = slots.getUnchecked (3);
}
}
This is the class header:
class HRTFPluginV2AudioProcessor : public juce::AudioProcessor, public juce::AudioProcessorValueTreeState::Listener
#if JucePlugin_Enable_ARA
, public juce::AudioProcessorARAExtension
#endif
{
public:
//==============================================================================
HRTFPluginV2AudioProcessor();
~HRTFPluginV2AudioProcessor() override;
//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
#ifndef JucePlugin_PreferredChannelConfigurations
bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
#endif
void processBlock (juce::AudioBuffer<float>&, juce::MidiBuffer&) override;
//==============================================================================
juce::AudioProcessorEditor* createEditor() override;
bool hasEditor() const override;
//==============================================================================
const juce::String getName() const override;
bool acceptsMidi() const override;
bool producesMidi() const override;
bool isMidiEffect() const override;
double getTailLengthSeconds() const override;
//==============================================================================
int getNumPrograms() override;
int getCurrentProgram() override;
void setCurrentProgram (int index) override;
const juce::String getProgramName (int index) override;
void changeProgramName (int index, const juce::String& newName) override;
//==============================================================================
void getStateInformation (juce::MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override;
//===================MY CODE================
//===============SliderMethods==============
float getAzimuth();
float getElevation();
float getOxygenConcentration();
float getNitrogenConcentration();
float getAirTemperature();
float getEarlyReflections();
//===============ProcessorGraphMethods================
void updateGraph();
void initialiseGraph();
void connectMidiNodes();
void connectAudioNodes();
//===============ProcessorGraphVariables================
using AudioGraphIOProcessor = juce::AudioProcessorGraph::AudioGraphIOProcessor;
using Node = juce::AudioProcessorGraph::Node;
juce::StringArray processorChoices { "Empty", "HRTFProcessor", "AirAbsorption", "EarlyReflections", "OpenGL" }; //list of available processors
std::unique_ptr<juce::AudioProcessorGraph> mainProcessor;
//fix using this method.
std::unique_ptr<juce::AudioParameterBool> muteInput;
std::unique_ptr<juce::AudioParameterChoice> processorSlot1;
std::unique_ptr<juce::AudioParameterChoice> processorSlot2;
std::unique_ptr<juce::AudioParameterChoice> processorSlot3;
std::unique_ptr<juce::AudioParameterChoice> processorSlot4;
std::unique_ptr<juce::AudioParameterBool> bypassSlot1;
std::unique_ptr<juce::AudioParameterBool> bypassSlot2;
std::unique_ptr<juce::AudioParameterBool> bypassSlot3;
std::unique_ptr<juce::AudioParameterBool> bypassSlot4;
//==============================================================================
//==Impulse Response ==//
juce::AudioProcessorValueTreeState treeState;
juce::ValueTree variableTree;
//===File Choosing Variables===
juce::File root, savedFile;
private:
//===============ProcessorGraph================
Node::Ptr audioInputNode; //pointers to the main AudioProcessorGraph as well as the audio and midi input and output nodes
Node::Ptr audioOutputNode;
Node::Ptr midiInputNode;
Node::Ptr midiOutputNode;
Node::Ptr slot1Node; //pointers to the nodes for each of the 3 slots
Node::Ptr slot2Node;
Node::Ptr slot3Node;
Node::Ptr slot4Node;
//==============================================================================
//==Impulse Response ==//
juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout();
void parameterChanged(const juce::String& parameterID, float newValue) override;
// virtual void parameterChanged (const String& parameterID, float newValue) = 0;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HRTFPluginV2AudioProcessor)
};
In case that class is not the problem, here is one of my object classes: I delcare a new pointer which may be the problem but I’m not sure, I believe I need a unique_ptr to handle matters within the class itself. ( I have ommited non related code for readiblity purposes)
class AirAbsorption : public ProcessorBase
{
public:
AirAbsorption();
void reset() override;
float celciusToKelvin();
#if JUCE_USE_SIMD
juce::dsp::SIMDRegister<float> getOxygenConcentrationSIMD();
juce::dsp::SIMDRegister<float> getNitrogenConcentrationSIMD();
juce::dsp::SIMDRegister<float> getAirTemperatureSIMD();
juce::dsp::SIMDRegister<float> getHumiditySIMD();
juce::dsp::SIMDRegister<float> getAirPressureSIMD();
juce::dsp::SIMDRegister<float> getDistanceSIMD();
juce::dsp::SIMDRegister<float> setFreqBandNominalValueHz(juce::dsp::SIMDRegister<float> freq);
juce::dsp::SIMDRegister<float> celciusToKelvinSIMD();
#endif
private:
float sourceDistance;
float oxygenConcentration;
float nitrogenConcentration;
float airTemperature;
float humidity;
float airPressure;
float freqBandNominalValueHz;
static constexpr float triplePointTempWater = 273.16f;
std::unique_ptr<AirAbsorptionCalc> airAbsorptionCalc;
std::unique_ptr<AirAbsorption> airAbsorption;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AirAbsorption)
};
I also note after some print testing, that I am calling the various constructors many times, May this be the issue? i have a variety of the respective objects so the one which is the node one isn’t the one necessarily getting updated with the slider values etc Thank you very much in advance for your time
