I am a good way into developing a synthesizer using synthVoice, but am running into a problem that stopNote() is called on every voice still playing, when repeatedly hitting same key.
I looked into solutions presented here https://forum.juce.com/t/voice-stealing-when-the-same-note-is-pressed/30344/2, especially as @DaveH posted “Just as a catch-up, all I had to was override ‘isVoiceActive’ in the voice itself, and return true if the ADSR is still running.”, but it did not solve my problem.
// Including or omitting override seems to make no difference
bool isVoiceActive () const override
{
return adsrRunning;
}
Then I looked briefly at the “Tutorial: Build a MIDI synthesiser” here https://docs.juce.com/master/tutorial_synth_using_midi_input.html and was wondering why startNote, renderNextBlock, and stopNote have to be overridden? It is not something I had done before, and adding made no detectable difference.
Anyways back to the problem causing me to ask whether override is really needed.
In my stopNote I got;
// Including or omitting override seems to make no difference
void stopNote (float velocity, bool allowTailOff) override
{
ignoreUnused (allowTailOff);
adsrVoice.release (); // Starts release stage of my custom ADSR
// I got the below test variable for all my 16 voices, each synthVoice with its
// own unique voicenumber identifier. When playing notes, all 16 test values
// is displayed in the plugin so I can see what is going on.
testValue[voiceNumber]++;
}
So if I repeatedly hit the same note, that is hit the note (that calls startNote) which leads to my ADSR start its attack stage, then release the key (which calls my stopNote) before sustain stage is reached, and with a decent amount of release time, therefore before the release stage is done (which if it had would make my code call clearCurrentNote), then hit the same key (note) again, every single voice still going through its release stage is forced an unexplainable stopNote. In other words if for example voice 0 through 5 is still sounding, going through its release stage, when I hit the same note again, voices 0 through 5 have its stopNote called, even though startNote correctly is invoked in a free synthVoice.
I should mention that I off course considered that my problem could easily be because my custom ADSR is the cause, however if I instead of repeatedly and in fast succession hits the same note, hit different notes, say quickly go up or down the scale, there is no problem!