music, especially when you work with musical instrument
s, it is tempting to fix a specific set of musical note
s, that is, frequencies, and write all your music to use these. That way you can build the instruments to produce exactly those notes, which makes them easier to build and to play.
The fundament of tonality in music is harmony; harmony is the physical property of frequencies strengthening each other; the math can be summarized by saying: this happens when two frequencies are in rational proportion.
The strongest case of this is unisono (two identical notes); next to that is a 1/2 proportion (an octave); after that, 2/3 (the natural fifth), 3/4 (the natural fourth), 4/5 (the natural major third),5/6 (the minor third, 6/7 (the last note in a seventh chord such as C7), 7/8 (the B flat-C interval in the same chord), 8/9 (the natural second, C-D in the scale of C), and 9/10 (the natural D-E interval in the same scale).
These natural proportions naturally sound as harmonics, a secondary frequency in any sound that isn't a completely pure sine wave. For example, they are in everything you play on a guitar, but they can be brought out more clearly by constraining the guitar string to produce the harmonics explicitly - the technique of flageolets. They are in organ and trumpet pipes, and can be brought out by blowing them differently; they are in the wind blowing around the corner of your house.
Therefore, they naturally appear in all tonal music: natural chords consist of them, and they also dominate melody, as illustrated by a musical analysis of Row your boat.
So on a musical instrument with fixed frequencies, like a fretted guitar or a piano, you expect to find these proportions of frequency as notes.
Once you have music, and in perticular, melody, it becomes very attractive, for practical and musical reasons, to use musical transposition, whereby a whole piece of music is shifted in frequency, usually by an octave or fifth. This produces new notes, not present in the original harmonic scale.
(Although string instruments, harmony and principles of tuning were known long before him, Pythagoras of Samos seems to have been the first to describe these mathematical principles.)
Now when you want to produce musical instruments with a fixed set of frequencies ('notes'), like a fretted guitar or a piano, these are the natural frequencies to use. The twelve-tone system is one particular choice that happened to be popular among the Greeks and, through the church organ and the classical/medieval system of musical modes, made its way into modern Western European music.
While transposition (by a fifth) is a natural and extremely useful phenomenon, arund 1600 composers got a little carried away with it; they started to experiment with repeated transposition. In transposed music, notes will occur that are very much like the notes available in your non-transposed harmonical scale, but not quite the same. For instance, if the base note of your instrument is C, your harmonic B note is the 7/8th of the next C as explained above; but when transposing a melody up by a fifth, so its ground note becomes G, the B note will need to double as a third in the interval of thirds G-B-D. The harmonically pure B in his chord is 1 - 1/6 . 2/3 = 5/6 of the next C rather than 7/8. Without retuning or extra keys on the keyboard, a keyboard player cannot have both Bs at the same time. So in practice, they compromise, and have their B tuned to something in between.
This led to the development of different systems of tuning and eventually to the adoption of the system of equal temperament for much of Western music.