Coloured boxes around / behind notes

For analysis purposes, it can be useful to mark themes, motifs etc.
This snippet demonstrates some tricks for drawing colored boxes around/behind notes.
It is based on the code of snippet 960: http://lsr.di.unimi.it/LSR/Item?id=960