From the Super Mario Wiki
Rainbow Notes (sometimes called Music Notes) are multicolored items that appear in Super Mario Galaxy. They will usually appear when Mario grabs a Question Coin, although the ones in Gold Leaf Galaxy appear if Mario rings a bell with the Star Cursor. Afterwards, they will line up, and Mario will need to grab all of them. Each note makes a different sound and together forms a short jingle or tune, typically from another game in the Mario series. If the Player gets every note, Mario will get a prize, such as a 1-Up Mushroom. The notes are also used in a few levels where they need to be collected to get the star, such as the Hurry-Scurry Galaxy, the Gold Leaf Galaxy, and the Sea Slide Galaxy.
They appear in Super Mario 3D Land as well with a similar purpose, activated by a P-Switch. If all of the Rainbow Notes are collected, Mario can earn a power-up if he is on his Small or his Super form, otherwise he earns a 1-Up Mushroom.
In Mario Kart 7, even if Music Notes aren't technically present, large black single note-like enemies known as Bouncing Notes take life and bounce from left to right causing a beat to occur on the ground. They only appear in Music Park.
 Themes Played by Rainbow Notes