I am working on a synthesizer. I am getting to the part of effects. I envision an effect chain, a strip of up to 8 effects, in any order. Currently I have 8 different effect types. Each effect type shares a few common elements, such as an on/off/solo button, effect level and pan. So it actually only leaves up to six knobs for any effect. Is it even worth my effort to try and create and remove such a small component of six knobs? I noted that the deleteAllChildren had a warning of not to use. Another option I am considering is simply to make a component array of eight (8 slots), for all 8 effects, or would that be unwise meaning would it considerably bloat plugin file/code size, slow things down, or something else bad? Or is there a better way to do this that I have not thought about?
I generally use an
OwnedArray to hold any
Components that are dynamically created. Its API makes for pretty straightforward use with
juce::OwnedArray<MyComponent> myComponents; for (int i = 0; i < 5; ++i) addAndMakeVisible (myComponents.add (std::make_unique<MyComponent>()));
In terms of overhead of having many nested component panels don’t worry. The components pose little overhead when they ae not visible or occluded. When you hit 1000 components you may start worrying.
This can happen in generic containers like ListBox, which is why it has optimisations for that use case. But the UI you design usually doesn’t need that amount of components.
As for lifetime, follow @connorrevieres advise: don’t rely on the components and deleteAllChildren()
Instead use said juce::OwnedArray or more future proof