NullPointer when adding Parameters to AudioProcessor


#1

Hello guys,

I’m trying to follow the AudioProcessorGraph tutorial.
(https://docs.juce.com/master/tutorial_audio_processor_graph.html)

I’m failing at the point where I have to add the Parameters to the AudioProcessor. The following code is located in the PluginProcessor.cpp file in the constructor.

FilterAudioProcessor::FilterAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  AudioChannelSet::stereo(), true)
                      #endif
                       .withOutput ("Output", AudioChannelSet::stereo(), true)
                     #endif
                       )
, tree (*this, nullptr)
, mainProcessor  (new AudioProcessorGraph())
, muteInput      (new AudioParameterBool   ("mute",    "Mute Input", true))
, processorSlot1 (new AudioParameterChoice ("slot1",   "Slot1",     processorChoices, 0))
, processorSlot2 (new AudioParameterChoice ("slot2",   "Slot2",     processorChoices, 0))
#endif
{
    NormalisableRange<float> cutoffRange (20.0f, 20000.0f);
    NormalisableRange<float> resRange (1.0f, 5.0f);
    
    tree.createAndAddParameter("cutoffLp", "CutoffLp", "CutoffLp", cutoffRange, 600.0f, nullptr, nullptr);
    tree.createAndAddParameter("resonanceLp", "ResonanceLp", "ResonanceLp", resRange, 1.0f, nullptr, nullptr);
    
    tree.createAndAddParameter("cutoffHp", "CutoffHp", "CutoffHp", cutoffRange, 600.0f, nullptr, nullptr);
    tree.createAndAddParameter("resonanceHp", "ResonanceHp", "ResonanceHp", resRange, 1.0f, nullptr, nullptr);
    
    addParameter (muteInput);
    addParameter (processorSlot1);
    addParameter (processorSlot2);
    
    tree.state = ValueTree("filterTree");
}

I’m getting a NullPointer at the following location:

void AudioProcessorValueTreeState::updateParameterConnectionsToChildTrees()
{
    ScopedLock lock (valueTreeChanging);

    for (auto* param : processor.getParameters())
    {
        jassert (dynamic_cast<Parameter*> (param) != nullptr); //Right here
        auto* p = static_cast<Parameter*> (param);

        p->setNewState (getOrCreateChildValueTree (p->paramID));
    }
}

Is there anyone who has an idea why this happens?

Thanks guys
Fabi


#2

You should not mix the AudioParameterBool etc. classes with the AudioProcessorValueTree. Decide, which method to use, and crate all parameters that way.

My preference is the AudioProcessorValueTreeState, but that’s up to you.

The assert makes sure, you didn’t use a Parameter, that is not inheriting the AudioProcessorValueTreeState::Parameter class (it is private, so you can only use that with the createAndAddParameter method, that you used for cutoffLp etc.)

Hope that helps


#3

Thank you very much!! :slight_smile: