Can't acces the processor's valuetreestate from child component only .h

I don’t know what I’m doing wrong. I get the error

error: no matching function for call to ‘FilterMenu::FilterMenu()’
   17 |     : AudioProcessorEditor (&p), processor (p)
      |                                              ^
In file included from ../../Source/PluginEditor.h:17,
                 from ../../Source/PluginEditor.cpp:12:
../../Source/FilterMenu.h:22:5: note: candidate: ‘FilterMenu::FilterMenu(GeoHeadalphaAudioProcessor&)’
   22 |     FilterMenu(GeoHeadalphaAudioProcessor& p) :
      |     ^~~~~~~~~~
../../Source/FilterMenu.h:22:5: note:   candidate expects 1 argument, 0 provided

This is the code for the child component:

#pragma once

#include <JuceHeader.h>
#include "PluginProcessor.h"

class FilterMenu    : public Component
    FilterMenu(GeoHeadalphaAudioProcessor& p) :
     processor (p) <----- ERROR
      setSize(200, 200);

      filterMenu.addItem("Low Pass", 1);
      filterMenu.addItem("High Pass", 2);
      filterMenu.addItem("Band Pass", 3);

      filterTypeAttachment = std::make_unique<AudioProcessorValueTreeState::ComboBoxAttachment>(processor.parameters, "FILTER_TYPE_ID", filterMenu);

      filterCutoff.setRange(20.0, 10000.0);
      filterCutoff.setValue (400.0);
      filterCutoff.setTextBoxStyle(Slider::NoTextBox, false, 0, 0);

      filterCutoffAttachment = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.parameters, "CUTOFF_ID", filterCutoff);

      filterRes.setRange(1, 5);
      filterRes.setTextBoxStyle(Slider::NoTextBox, false, 0, 0);

      filterResonanceAttachment = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.parameters, "RESONANCE_ID", filterRes);



    void paint (Graphics& g) override
      juce::Rectangle<int> titleArea (0, 10, getWidth(), 20);

      g.fillAll (Colours::black);
      g.drawText("Filter", titleArea, Justification::centredTop);

      juce::Rectangle <float> area (25, 25, 150, 150);

      g.drawRoundedRectangle(area, 20.0f, 2.0f);


    void resized() override
      juce::Rectangle<int> area = getLocalBounds().reduced(40);

      filterCutoff.setBounds (30, 100, 70, 70);
      filterRes.setBounds (100, 100, 70, 70);

    ComboBox filterMenu;
    Slider filterCutoff;
    Slider filterRes;

    std::unique_ptr <AudioProcessorValueTreeState::ComboBoxAttachment> filterTypeAttachment;
    std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> filterCutoffAttachment;
    std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> filterResonanceAttachment;


    GeoHeadalphaAudioProcessor& processor;


Time to learn C++… :wink: But, in the meantime, the error says you are trying to instantiate a FilterMenu with a constructor that does not exist, ie. you have only defined FilterMenu(GeoHeadalphaAudioProcessor& p), not FilterMenu(). To help more, we’ll need to see where in your code you are using FilterMenu?

In the editor .h
FilterMenu filterComponent;

And .cpp
void GeoHeadalphaAudioProcessorEditor::resized()
filterComponent.setBounds(732, 600, 200, 200);
Why do I have to declare FilterMenu() without the GeoHeadalphaAudioProcessor& p? I’ve seen in the example they declared it in the class .h as FilterMenu(GeoHeadalphaAudioProcessor&) and in the .cpp they did the same as I did here. But I’m only working with a .h can it be done, or do I need to split it?

As @cpr2323 says I think we need to see more of your code, maybe the PluginEditor.h and cpp where it seems to be trying to call the FilterMenu constructor without passing the reference to GeoHeadalphaAudioProcessor. I suspect you’ve added FilterMenu as a member of your PluginEditor class. This would use the default, FilterMenu(), constructor — unless you explicitly initialise it in your PluginEditor class’ constructor too (to pass the reference to your GeoHeadalphaAudioProcessor too).

@Rubenkaller, like I said, time to start learning more about C++. We don’t mind offering some assistance with basic C++ in the forums, but it is best if you lean on the forums for JUCE and more advanced C++ questions. So, you declaration:

FilterMenu filterComponent;

invokes the default constructor (FilterMenu::FilterMenu()) for FilterMenu, but you have only defined the constructor which takes GeoHeadalphaAudioProcessor& parameter.

Since GeoHeadalphaAudioProcessor is a reference in FilterMenu, you will need to pass it into the constructor, as you are doing. But it also means you need to pass that reference when you declare filterComponent. Something like:

FilterMenu filterComponent (myGeoHeadalphaAudioProcessor);

Thank you for your reply. I’m going to do a couple weekends of deep learning c++, together with DSP. My excuse for asking these questions is that I figured a lot of people will run into the same errors. I’ll head over to stackoverflow in the future.

But in the example he can just declare it as:

In the editor.h:
Filter filtergui; //Why can he declare it without passing the AudioProcessor?

In the Filter.h:

And in the filter.cpp:
Filter::Filter(JuceSynthFrameworkAudioProcessor& p) :

Anyway I can’t make it work it starts giving trouble in the editor, so I’m gonna go with the seperated .h and .cpp. Thanks for pushing me towards learning, apparently it’s what I need to hear.

It is valid to declare a variable and not initialise it. It will call the default constructor. But that default constructor is not available, that’s what your error message says: “expect 1 argument, but 0 was provided”.

Ideally you move the line

GeoHeadalphaAudioProcessor& processor;

to the top of the variables, that way the other variables can depend on it.

Then you can add the FilterMenu using the previously declared reference as argument:

GeoHeadalphaAudioProcessor& processor;
FilterMenu filterComponent { processor };

Note the curly brackets, it is a default initialiser. It can be overriden by a constructor in the member initialiser list. That would look like the colon section like it is in the AudioProcessorEditor boilerplate. In that case with normal backets.

Good luck on your journey

1 Like

Thanks man. Is there also a way to pass the plugineditor to a component?

FilterMenu filterComponent { processor, this }; //???

That would work. Preferably if the editor is mandatory, you would use a reference again, in which case you need to dereference this:

FilterMenu filterComponent { processor, *this };

And remark 2: You could create an accessor to the processor in the editor, that way you need only one argument:

FooProcessor& FooEditor::getProcessor()
    return processor;

Thanks for the tip.

Now I don’t manage to get the editor correct. I don’t know what to do.

#include <JuceHeader.h>
#include "PluginEditor.h"

class CircleCardioid    : public Component,
                          public Slider::Listener


    CircleCardioid(GeoHeadalphaAudioProcessor& p, GeoHeadalphaAudioProcessorEditor& e):
    processor(p), editor(e)

error: ‘GeoHeadalphaAudioProcessorEditor’ has not been declared

GeoHeadalphaAudioProcessorEditor& editor;

error:‘GeoHeadalphaAudioProcessorEditor’ does not name a type;

Most likely you created a circular dependency:

The GeoHeadalphaAudioProcessorEditor has a CircleCardioid component, therefore it includes the CircleCardoid.h. The CircleCardoid has a reference to the editor, that’s why you added the #include "PluginEditor.h".

The preprocessor cannot work that out correctly. There are two solutions to that:

  • Use a forward declaration: remove the #include "PluginEditor.h" and instead add class GeoHeadalphaAudioProcessor;
  • only include from the cpp files (which takes a bit more care to get it right)

I get a forward declaration error… Is it even possible in this way?

error: invalid use of incomplete type ‘class GeoHeadalphaAudioProcessorEditor’
138 |


note: forward declaration of ‘class GeoHeadalphaAudioProcessorEditor’
14 | class GeoHeadalphaAudioProcessorEditor;

You’re leaving out too much code. Where is that error taking place? Do you have code in the .h file that is generating that? If so, move the function body into the .cpp file.

Also, when using a forward declaration in the header, you need to have the actual include in the cpp file. So make sure you add #include “PluginEditor.h” at the top of that cpp file.

1 Like