Derived Synthesiser class problems


#1

Hi - just getting back into Juce after a forced absence - It’s looking better than ever :slight_smile:

So i’m deriving a class from Synthesiser - I wanted to modify it to support velocity switching of sounds. Unfortunately, when overriding Synthesiser::noteOn, which i’m basically copy/pasting for the most part - i run into a few problems:

  1. shouldStealNotes is private so i can’t access it. (not a show-stopper as i generally want his to be true anyway)

  2. I can’t access the private variables in SynthesiserVoice because my derived Synthesiser class isn’t a friend. Not sure how to get round this right now other than hacking some extra “set” functions into SynthesiserVoice.

Any ideas on a better way to get round this?

Thanks!


#2

Yep, I’ll add a isNoteStealingEnabled() method to allow access to that variable.

Those variables in the voice class are private because you shouldn’t need them, unless they have an accessor method. I can’t see why you’d want to change any of them anyway? And changing things like the current note would break the way the voice class is used by the synthesiser…


#3

i’m trying to override Synthesiser::noteOn, so i can modify the conditions for triggering a sound (so its not just based on midi channel, and note). However, noteOn(), as it has been implemented, needs to access the private members of the voice to start the sound playing. My overriden version can’t do that…


#4

Can you suggest a better way of extending the synth class to be able to do what you want, instead of just hacking it to make variables public? Maybe a virtual method to pick the appropriate sound based on the note number and channel or something? Or a virtual startVoice() method to do the code that’s currently inside the noteOn inner block?


#5

i think he means he need something like a

so he could do other checks if the synth should play that note or not (taking into account user set parameters for example) and eventually stop the note from be played. i’m mistaken ?

i needed something along the lines before, cannot remember when exactly tho.


#6

yeah, sorry - i wasn’t being very constructive there :wink:

The way i have set it up right now is i have a added a virtual function that - given the note,channel, and velocity, returns a list of the sounds to play. I modified noteOn() to iterate through this list. This is almost what Kraken is suggesting, but with the loop moved to my new function.

a StartVoice() function, like Jules suggested would work perfectly for me too - then i could modify noteOn as much as i like. I think this is probably the simplest and most flexible solution…


#7

ok, I’ll throw in a startVoice method, that’d be a neat solution.


#8

sounds good - thanks!