Hello!
I think the number of notes “that you play” could be interpreted as follows:
The chronological sum of the notes which have been played.
The simultaneous notes which are pressed currently.
Assuming from your code template, I think the first one is what you think.
Is the following code appropriate? It includes both of what I mentioned above:
Your MIDIdef runs every note you play. It starts with setting a = 1, adds 1 to it and posts the result.
In order to keep count you can’t re-set your counter every time you want to add to it. You already have defined a global variable, use that in your function instead of a local variable, like
{~counting = ~counting + 1},