Monophonic play modes

I'm building an open source FM synth in VST/AU form with Juce. I've just implemented a simple glide option when numVoices gets set to 1 (it's an option in the GUI of the plugin). There's one nasty side effect somehow, to Synthesiser's handling of voices. The envelopes retrigger (which I believe I want to have), and they make the sound crackle when going from one note to another, while the first one is held down. The other, less annoying thing is that when key A is held down, then key B is held down and released again, the sound is not returned to the first pushed key.

Does anybody know of (re)implementations of Synthesiser, or perhaps workarounds, that are open source and have already made this to work?

Howdy

I wrote a new function that tracks the pitch keys. Mine is not really for monophonic synthesiser, was more for enabling changes that could only happen one at a time (pitch shifting). I'll try to post some psuedo code that worked for me. It is likely ugly - I had to do it very quickly, and so would be fine if anyone wants to correct it. Also I originally only tracked 4 keys (see the last for loop).

Basically, you need to keep a 'memory' of the keys pressed ('pitchKeyHit'), and then re-write the memory based on what is being pressed. I had a nice graphic output that was cool to visualise it - and really helped with debugging.

Thanks

void trackPitchKeys(int key, int onOff){ //this tracks which pitch keys are hit
    bool match = false;
    //first walk through the array forward to determine is a key already pressed and should we turn it off
    for (int i = 0; i < keysHeld; i++){
        if (pitchKeyHit[i] == key){ //does the key match?
            match = true;
        }//end if match
        if (match == true){ pitchKeyHit[i] = pitchKeyHit[i + 1]; }         //set it to previous value
    }
    if (match == true){ keysHeld -= 1; return; } //bail if it was a note off
    for (int i = 4; i > 0; i--){
        pitchKeyHit[i] = pitchKeyHit[i - 1];
    }
    pitchKeyHit[0] = key;
    keysHeld += 1;
}