Well, Panama Jack had the closest to the proper answer. So you know all music is math in so much as the theoretical aspect goes. The part when he said that he wrote more pleasing to the ear is actually more of an opinion as non-western music violates those types of rules that Bach followed and to many westerners sounds like crap.
Anyway, Bach united harmonic and melodic theory to a degree that was really unheard of before his time. Harmonic theory is what a laymen would generally refer to as the chords below the the singer (a giant oversimplification). Melodic theory is the theory that the individual notes of a melody lead from one place to another (they could be the same place, again greatly oversimplified). Anyway, Bach made the two classes of theory a unified piece. The harmony is based on stacked melodies following a chordal pattern. What, you say? You think this was done in the Rennaissance? It sure was but they were done modally. Modal music doesn’t follow a strict harmonic structure. Oftentimes Rennaissance music ends in an open fifth (intervals are yet another mathematical aspect of music that get enveloped into the harmonic theory) or other incomplete chords. Rennaissance music is really more of a series of stacked melodies with very basic chord structures.
Out of the Baroque Period (which Bach is the representative character), harmony started gaining importance. Melody was still desired for obvious reasons (you like to hum or sing along to songs, don’t you?) but Rennaissance music seemed to lack the presence of direction as modal music typically does. Harmonic theory developed by D’Arrezzi (I believe if I remember correctly) and thus was born the Baroque. He studied music that was considered pleasing and/or patterns in the music that happened often and named them and gave them a functionality within a musical context. (IE, the leading tone leads to the tonic. Or basically half steps lead to the closest note within the key, e leads to f ascending, b leads to c ascending, f leads to e descending, c leads to b descending. Again, this is a simplification.)
This is when modal theory started losing prevalence and really when our modern Western Music evolved. All tonically based music from techno, industrial, some punk, rock, etc is based off of the principles that evolved during the Baroque and later refined more in the Classical period.
I know it may sound a little off topic to how music is mathematically based but I assure you the theoretical principles behind classical music are highly mathematical. So you know, Bach really was known for Fugues which are the exposition form of a canon. A round is very specific type of canon with exact repeats, fugues can have a transcribed repeat and inversions and all types of mathematical fun. Woohoo! Pick up some sheet music if you can read it, and look at the patterns that a Bach fugue make. They should basically have all the same shapes of musical lines starting at different places, ending in different places, and even being different notes. It takes a wonderful musician/mathematician/composer to pull all of those elements together and have them end at the same time in a manner that others find pleasing. I know that pleasing is an opinion as I stated earlier.
This takes in everything except rhythmic theory. Rhythmic theory is also math. Rhythm is just a series of fractions and how to break down measures in identifiable grouped movement. Rhythm is the most basic element of music and the most concrete mathematical. You can see how the fractions break down in the given element. Time signatures tell you what beats get emphasis and how many strong beats there are per measure. The individual notes (half, whole, quarter, eighth, etc) tell one how fast something is to be played. To give an analogy to a computer it is like the clock speed. It tells you how fast to play something so it is still enjoyable. Would you like to play Doom so slow that everyone can kill you before you can turn around? Or so fast that you can’t get off the wall because you keep hitting the side when you barely touch the keys? It is that type of idea.
Sheet music is just a graph that shows music through time in a mathematical sense.