Note easy to override Synthesiser::noteOff when the parameter "isKeyDown" of the voices is private


Hi there,

i’d like to know how to correctly override the Synthesizer::noteOff (which is virtual) in “MySynthesiser” inherited in which i use “MyVoice” inherited class. The fact that in the SynthesizerVoice class the parameter “keyIsDown” is a private bool it doesn’t let me use it from the inherited class “MyVoice”.

Here the noteOff code of Synthesizer :

void Synthesiser::noteOff (const int midiChannel,
const int midiNoteNumber,
const float velocity,
const bool allowTailOff)
const ScopedLock sl (lock);

for (int i = voices.size(); --i >= 0;)
    SynthesiserVoice* const voice = voices.getUnchecked (i);

    if (voice->getCurrentlyPlayingNote() == midiNoteNumber
          && voice->isPlayingChannel (midiChannel))
        if (SynthesiserSound* const sound = voice->getCurrentlyPlayingSound())
            if (sound->appliesToNote (midiNoteNumber)
                 && sound->appliesToChannel (midiChannel))
                jassert (! voice->keyIsDown || voice->sustainPedalDown == sustainPedalsDown [midiChannel]);

                voice->keyIsDown = false;

                if (! (voice->sustainPedalDown || voice->sostenutoPedalDown))
                    stopVoice (voice, velocity, allowTailOff);


Has someone encountered the same issue?
I add for information that “MySynthesizer” and “MyVoice” are in different files in order to get a better readability (as well as matching with cpp standard of getting a file per class)

Thank you for your help


im not encouraging you, but for the same reason i made it public and copied modules to project folder. as well could not help myself vanilla way.


Thanks for your answer, it is a bit sad that a simple setter is not implemented, as it is essential to override this function, and that we need to make a custom JUCE version…


@JUCE Team
Could you change that? We’re also in trouble with this!


Sorry, I’m confused about what you’re asking for… The OP is asking for a public version of isKeyDown, which is already there:


It’s not about the getter - it’s about the setter.
To completely replace the “void Synthesiser::noteOff()” with an own version, we would have to be able to set keyIsDown (which is private and has no setter). For now, we call Synthesiser::noteOff() from our virtual noteOff method to get this done. This works somehow, but it would be much more convenient to be able to control it all from the virtual method.


FYI I’ve added a setKeyDown method now


Thanks a lot !


Cool! Thank you :slight_smile: