Calling multiple synthesiser voices with one keypress


Hi there.

I’m working on a polyphonic synth. So at the moment whenever a midi key is pressed, the synth plays the sound belonging to that key, until it runs out of voices (then it removes the oldest sound to play the new pressed sound on that voice). The way i do this is simply by implementing the SynthesiserVoice and SynthesiserSound classes and calling the startNote function in the SynthesiserVoices.

But now i want to create an option which makes it possible to call multiple voices (for example one for the pressed midinote and one for a note an octave higher) with one midi keypress. I dont really know how to go about this. Could anyone help me with this?

Thanks so much!


The JUCE Synthesiser class does not support that use case. You could maybe alter the Synthesiser code to allow it, though. (I’ve done it myself but I didn’t thoroughly test it works completely as intended as it wasn’t for an urgent project.)


Ah thats a shame. Ill look into that!



If I’ve understood what you’re after correctly you should be able to do it without modifying the Synthesiser class. You’ll need to create a sub class of it though, and override the noteOn method and do something like this:

for (auto* sound : sounds)
    if (sound->appliesToNote (midiNoteNumber) && sound->appliesToChannel (midiChannel))
        // If hitting a note that's still ringing, stop it first (it could be
        // still playing because of the sustain or sostenuto pedal).
        for (auto* voice : voices)
            if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel (midiChannel))
                stopVoice (voice, 1.0f, true);

        startVoice (findFreeVoice (sound, midiChannel, midiNoteNumber, shouldStealNotes),
                    sound, midiChannel, midiNoteNumber, velocity);
        startVoice (findFreeVoice (sound, midiChannel, midiNoteNumber, shouldStealNotes),
                    sound + 12, midiChannel, midiNoteNumber, velocity);



Ill try this! thanks