HELP! Changing the melody using buttons while it's playing

your playMelody() function does not return until all the notes have been played (see the for() loop?)

so you need to break that into chunks and non blocking code using millis() for example

For extra information and examples look at

you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction