I do it when I'm stressed, excited, figuring out/thinking through a problem, and listening to music. I have different stims for different situations, depending on what I need. For example when I'm excited I'll flap my hands to release my excitement, when I'm stressed I'll rock back and forth and have other hand stims to calm myself down, but sometimes I'll do the same thing when I'm listening to music, to really get into the music. And when I'm trying to think through or figure out a problem, I'll usually do all of the above plus pace around and talk out loud to myself as I try to work through it.
I don't do all of these stims all of the time, but depending on the situation and whether I need to relax, release excitement, figure something out, or whatever it may be, each of the different stims have their own purpose and they don't all work in the same situation.