There's increasing evidence that rhymes, poems, meter and cadence in stories were created not because they are beautiful but because they helped us keep the words straight before the advent of written language. It is how our civilization kept important lessons, histories, messages and stories intact without writing anything down.
Imagine any rhyming story or poem you know and repeat it so the cadence or the rhyme doesn't work - you know it's wrong instantly because you're memorizing a pattern that makes it all fit. This is the first human programming exercise and it has stayed with us throughout time.
Did music evolve in the same way and for the same reason? Certainly you know instantly when a wrong note is hit - and what's amazing about that is you're able to identify a single error in a many thousand line piece of "code" that you probably didn't may much attention to.
Imagine trying to memorize thousands of words and making sure each is 100% correct. Most of us cannot do this but nearly all of us can memorize complex musical passages, symphonies and songs and know instantly when the pattern or the coding is wrong.
See? And you thought it was simple.