Hi Jarilo,
Yes indexVoice is to keep track of the voices order allocation.
When we have to stop a playing voice, we stop the older one.
Just had a look at the code to refresh my memory
The logic in the first loop :
. is the note we ask is already paying => use same voice
. If a voice is not playing => use voice (I don't remember why we don't stop looping here :/ )
. If a voice is still playing but has been release => use it unless we find a not playing voice or an older note that is also realeased later in the loop
If we didn't find any available voice. We must chose one :Second loop....
. chose the older one but excludes voices that are about to start (isNewNotePending()).
That's the idea....
Xavier