manual control of a melody

I have a small but simple question, I guess. Right now, with the example of the tutorial I am able to play a melody with my arduino and a piezo speaker. With the code I am able to adjust the melody, the speed and the intervals in between the tones rather easy. However, I want to manually tell the arduino when to play the next tone by pressing a button. Is this possible?

For example, if I have a melody cddceeccee, can I then play the first note (c) on the first push on the button, the second tone (d) on the second push of the button, the third note (d) on after that? This way I could manually determine the speed and rhythm of the song...? Ofcourse I know the basics of reading a digital switch button, but I don't now how to let that button progress a tone by each press. Who can help me out here?

Working from memory, there's a loop that toggles the audio pin high/low at a speed determined by the note (frequency) for a certain duration (actually a certain number of cycles depending on the frequency).

Sounds like you should change that loop's exit condition so that you stay in it until the next button press, rather than after a given number of cycles.

You may want to debouce that button press, tho.