Answering as a brass player, all music is produced by sound ocillations, i.e. causing the air to vibrate at a certain number of cycles per second. For example the A to which an ochestra tunes (given by the oboe) should ocilate (assuming the oboist is in tune) at 440 cycles per second. Therefore in order to contract any instrument with a full chromatic (all twelve notes in the scale) range, it is necessary to provide it with some method of altering it's natural pitch. This can be achieve by key conbinations (woodwind instruments), or stopping strings (violins, guitars etc.). In the case of modern brass instruments, a twelve note scale is acheived by a combination of three valves (a forth can also be added to assist with range and tuning). Each valve opens up an additional length of tubing that lowers the pitch. Generally the instruments natural pitch (e.g. B flat for a standard UK trumpet or cornet) is acheive with all valves open. The middle of the three valves lowers the pitch by a semi-tone, the first valve by a whole tone, the third by 2 tones although this is usually acheived by the first and second held down together. First and third held down together lower by three tones. Thus any note of a chromatic scale can be acheived.
I am sure a mathematical formula ican be used to calculate how much extra tubing can be used to acheive each change of note, though the player still has to make compensations to ensure he/she stays in tune