Synth Voice - Dynamic Cast or not. Help?

I am running into a few design headache's / queries regarding custom voice classes derived from JUCE's SynthVoice class. 

Most of my issues have been solved by creating the various components of my Synth as AudioProcessors and hooking them up into an AudioProcessorGraph. 

So dealing with things like filter cutoff parameters and delay parameters is becoming much more flexible. 


However, I am still having the issue that my WaveTableOscillator class is being implemented as a member of my derived SynthVoice class. The various functions within the voice class for rendering the voice and noteOn call the oscillators output to fill the buffer and also in turn set it's frequency. 

I need access to a few paramters of my oscillator within my derived SynthVoice's (fine tune etc. for modulation and GUI param changes). The getVoices() function returns a SynthVoice and the only way i can call my derived voices functions/access their member variables is to perform a dynamic cast. 

I'm wondering whether dynamic casting in this instance really is the best / only option or not (this seems to be the suggested solution in most threads touching on this issue) ? It's working but is it an ugly work around ? I'm working through the various Meyers texts and think im getting a reasonable understanding of the consequences of dynamic casts. 


My alternative ideas were:

1.Pass a reference/pointer to the "Owning" synth object in the Voices constructor and access member variables of the synth(which could be controlled by param changes in the audio processor) to set my oscillator values. However i suspect I'll run into some threading disasters here ? 

2.Set up a broadcast/listener method or some sort of asynchronous messaging from the synth to the synthVoices with a callback that updates my custom synthVoice class parameters.



Does anyone have any advice in regards to this ? 


Any help for a still "in learning" C++ programmer would be most appreciated

If you know for sure that the pointer will always be to your derived class I think you could just call static_cast<>.  It should have little or no overhead.

Option 1 looks okay as well.  What's the threading disaster you are thinking of?

Hey Bazrush, 


Thanks for the advice. Yeah your right passing a pointer to the owner synth has worked out pretty well. I was concerned about sharing processing units (oscilators, filters) between voices but I think its gonna be enough to just access parameter values of the owning Synth which doesn't seem to be causing any issues. 

Thanks for the static cast advice. I should have thought about that more rather than going by the forum posts I read. 


I'll pop up some code for a derived Synth voice implementation and some point when I've cleaned things up as it might be handy for new Synth makers. Bout time I contributed something back to the forum ! 


Thanks again