Example: If I want to play a sound in my soon to be homemade VST instrument, and this note in the sequencer is 15000 samples long and the note is set to ON by the processEvents, the processReplace function starts to play the sound from 0 to sampleFrames (that is 10000 in my example here). Then there will be 5000 samples left to play of the note the next time it enters the loop in processReplace, but still the loop will play from 0 to 10000 which is 5000 more than samples to play from the note. There will be 5000 samples of silence that are going to be played and that means that this note will not be turned off until 5000 samples later!?
If a new sound in the sequencer is placed directly after the first one the processReplace function will not see the short period of OFF set by the processEvents and see the next sample as a continous sound of the first one because it will only see the new notes ON when the loop is entered again.
How can I prevent this from happening? How can I stop the processReplace loop if the note ends in the middle of the loop?