There is no rule about showing code especially code fragments. ![]()
The structure of your loop function is fundamentally diffrent now.
You do not follow the do this then do that then do the other order of things. That is what gets you trapped.
Your code should be
Start loop
Has the thing that triggers the note happened ... -> send note on message, set up note off pending time
Is a note off pending and is it time to turn off ...... -> send note off and clear pending indicator
End loop
Read the examples in the state machi be page.