Hi JUCE folk,
I have a bit of a question in regards to OwnedArrays and ReferenceCountedArrays/Objects.
I am trying to abstract the various components of my synth plugin into "module" base classes. So for instance my filters and oscillators will all be a subclass of a SynthAudioModule class and my LFO's and ADSR's will be subclasses of a SynthModModule class.
The SynthAudioModule and SynthModModule will then be a subclass of SynthModule and my synth is a derived class of the JUCE Synthesizer class and is also derived from a class I am implementing called SynthModuleHost.
Im trying to get my head around RAII techniques and the best ways of handling a dynamic array of objects.
Specifically i want the SynthModuleHost class to hold an array of object pointers to SynthModules.
I know the number of indivual modules(oscillators, filters etc.) in my synthesizer but obviously want the SynthModuleHost class to be reuseable for Synth plugins with more or fewer components/modules.
So to the meat of my question,
How would I go about adding in modules to the array of SynthModule pointers in my SynthModuleHost class ?
My idea was to do this with an OwnedArray like so: OwnedArray<SynthModule> synthModules;
And then in the counstructor of my synth call the function addSynthModule(Int index, SynthModule* module) which is declared in the SynthModuleHost class and adds a SynthModule pointer to the OwnedArray at a specified index (defined my a modules enum).
The modules will have various functions allowing audio modules to be connected together within the Synthesizer object (oscillator to filter etc.) and modulation modules to be connected to audio module parameters. So I'm unsure as to whether an OwnedArray is the best thing to use as modules within the OwnedArray may need to be accessed during the Synth's processBlock(wondering about speed accessing the array elements).
Jules has kindly mentioned in this thread that the OwnedArray is capable of returning its elements pretty quickly so its probably not an issue.
http://www.juce.com/forum/topic/how-effecient-are-arrays/ownedarrays
On the other hand would more learned JUCE coders advise to just define an array of SynthModule pointers in my own Synthesizer class as define the size of the array upfront ?
Apologies for the long winded explanation, any help with a bit of a design decision here will be greatly appreciated.