Mono voice midi crackling sounds

I’m making a mono synth and have a button that will reset the voice, but when I send midi messages I get a lot of crackling sounds what is going on what the difference between the button that is triggering it cleanly and using a midi keyboard that makes it crackle.

I guess I have to go inside the process block like the regular vst sdk rendering messages before with mono is no good

I guess thats what tailoff is for

indent preformatted text by 4 spacesvoid myRenderBlock(AudioBuffer<float>& outputBuffer, MidiBuffer& midiMessages,int startSample, int numSamples)
    auto *channelData0 = outputBuffer.getWritePointer(0);
    auto *channelData1 = outputBuffer.getWritePointer(1);
    SineWaveVoice *v = dynamic_cast<SineWaveVoice*>(getVoice(0));
    MidiBuffer processedMidi;
    int time = 0;
    MidiMessage m;
    startSample = 0;
    int size = numSamples;
    //for (MidiBuffer::Iterator i (midiMessages);i.getNextEvent (m, time);)
    MidiBuffer::Iterator it (midiMessages);
        held = false;
            while(startSample< numSamples)
                if(m.isNoteOn() && !held)
                    held = true;

                int index = startSample;
                //processing single voice
    outputBuffer.applyGain(0, 0, size, v->ampModAmount.getNextValue());
    outputBuffer.applyGain(1, 0, size, v->ampModAmount.getNextValue());
     midiMessages.swapWith (processedMidi);

a little preview