Where is the editor in component hierarchy [SOLVED]

I’m trying to access the editor component from a subsub(…)component so I used

getTopLevelComponent();

which I expected to return the pluginEditor. But it didn’t, neither was the editor a child of this. I did a blind search through the tree for the editors id, and it appreas to be the second son of the first son of the top level component.

While I’m happy with this, it looks really error prone to me. Can I expect the editor to always be in this place? What are the higher components anyway, and why are they not labeled with an id?

In plugins there are usually wrapper components that hold the AudioProcessorEditor, so the editor will not be the highest component in the hierarchy.

Try findParentComponentOfClass(), like so:

if (auto editor = findParentComponentOfClass<juce::AudioProcessorEditor>())
    // do something with editor
1 Like

As tedious as it is to do, you should probably pass around a proper pointer or reference of the main AudioProcessorEditor object into the child (or child child etc) components.

1 Like

Ouch we’re talkin the knob class, so that would indeed be tedious… Is there any downside to the solution TonyAtHarrison proposed?

One downside is dynamic casting, and if you somehow had multiple AudioProcessorEditor components in the parent hierarchy for some reason you would have to do extra work to find the top-most editor :stuck_out_tongue:

1 Like

Ouch we’re talkin the knob class

Do you mean juce::Slider? You can pass a pointer in the capture list of a lambda to onValueChange, onDragStart, and onDragEnd.

Well a custom derived class of Slider, yes. However, the knobs are still nested in further parent components. I think the solution proposed will do, as I need to do it only on rare occasions.