Melodies are culturally transmitted sequences of notes that evolve through time in a manner that broadly parallels the process of molecular sequence evolution. While gene sequencing and the identification of general mechanisms of DNA transmission and mutation have revolutionized our understanding of biological evolution, the nature - and even the existence - of cross-culturally universal mechanisms of musical evolution remains debated. Here we adapt sequence alignment algorithms from molecular genetics to analyze musical evolution in a sample of 10,062 melodies from musically divergent Japanese and English folk song traditions. Our analysis identifies 328 pairs of highly related melodies, within which rates of musical evolution vary in ways predicted by general principles of music cognition and cultural evolution. Note changes are more likely when they have smaller impacts on a song's melody, specifically: 1) notes are most likely to change to neighboring notes, 2) rarer notes are more likely to change, and 3) notes with stronger functional roles are less likely to change. These results are consistent across samples despite using different scales with different probabilities of change between notes, suggesting they may apply universally. Our findings demonstrate that even a creative art form such as music is subject to evolutionary constraints analogous to those governing the evolution of genes, languages, and other domains of culture.