I have worked during the previous weeks on some transpositions features for Flat. I will try to explain in this post what is the logic behind music intervals.

Intervals are defined with 2 values: diatonic and chromatic.

Diatonic

This is all a matters of intervals. Let's take a simple piano keyboard.
Keyboard
We will start from the C. The diatonic shift is the number of white keys you you have to move to reach the destination pitch. If you move to a D, you shift of one white key: the diatonic value is 1. If you move to F, you shift of 3 white keys, the diatonic value is 3.

Step Diatonic
C 0
D 1
E 2
F 3
G 4
A 5
B 6

There is a specific vocabulary for each diatonic value: if you stay on the C, this is called unison. If you move to the D, it is called a second. For a F, it is called a fourth.
Let's add that to the table:

Step Diatonic Name
C 0 unison
D 1 second
E 2 third
F 3 fourth
G 4 fifth
A 5 sixth
B 6 seventh

Chromatic

The chromatic value is the number of keys you have to move, including black keys. To move from C to E, you move of 4 keys, but to move from C to F, you move of 5 keys. There are also musical terms for these values of chromatic. Let's update the table:

Step Diatonic Name Chromatic Prefix
C 0 unison 0 perfect
D 1 second 2 major
E 2 third 4 major
F 3 fourth 5 perfect
G 4 fifth 7 perfect
A 5 sixth 9 major
B 6 seventh 11 major

Alterations

You can add alterations to base pitch steps: from G, you can make a Gb, or a G#. What are the corresponding intervals? Since the base pitch step is G, the diatonic value will stay the same, 4. It is the chromatic value that will change: 6 for Gb, 8 for G#. And each of these variation has a musical name.

Step Diatonic Name Chromatic Prefix Alteration
C 0 unison 0 perfect natural
1 augmented sharp
D 1 second 0 diminished double flat
1 minor flat
2 major natural
3 augmented sharp
E 2 third 2 diminished double flat
3 minor flat
4 major natural
5 augmented sharp
F 3 fourth 4 diminished flat
5 perfect natural
6 augmented sharp
G 4 fifth 6 diminished flat
7 perfect natural
8 augmented sharp
A 5 sixth 7 diminished double flat
8 minor flat
9 major natural
10 augmented sharp
B 6 seventh 9 diminished double flat
10 minor flat
11 major natural

Enharmonics

But wait, E# has the same chromatic value than F. This is because they are on the same key: they have the same sound. It is the chromatic value that will tell what is the actual sound. The diatonic value will tell us how do we write this sound. Two notes with the same sound but different writting are called enharmonic. For instance: E# and F, E and Fb, B and Cb.