The basis of our tonal system is the diatonic scale: A, B, C, D, E, F, G. The note H, however, had two different forms as early as the end of the first millennium: b rotundum (also b molle or soft b) and b quadratum (b durum or hard b). The first of these was fixed as the note name B by the 16th century printers in Germany, and the latter was named H, perhaps because of its form, which resembled the letter h.
These signs are the origin of today's chromatic signs. Their usage was inconsistent and based on the personal whim of the composer/note scribe. The form of the natural sign, for one, was first met in the 12th century, and a symbol resembling the sharp sign was first used in the 13th century. Both signs obviously derived from the quadratum and denoted either a sharp or a cancellation of a preceding flat, depending on the practices of the note scribe. The current meaning of the natural sign was seen as late as the 18th century. At the same time, the double sharp and flat signs were getting more commonplace. A "reclining" form of the sharp sign, b iacente (not to be confused with the double sharp), was still in common use as late as the 18th century.
double flat (lowers a note already lowered by the key signature)
flat (lowers a note by a chromatic semitone)
natural sign (cancels a flat or a sharp)
sharp (raises a note by chromatic semitone)
double sharp (raises a note already raised by the key signature)
In general, two notes with the same pitch can be written using either a flat or a sharp symbol, for example, G sharp = A flat. What chromatic sign to use with these enharmonic notes is dependent on a multitude of factors. In tonal music, chromatic alteration in the present key is preferred: in A flat major, for example, we don't write G sharp, C sharp, F sharp, or any other notes of that kind.
If the melody is rising, the notes indicated by the key signature are usually raised, and if it is falling, they are lowered. There are, however, exceptions to the rule (see the chromatic scale). We sometimes need to make compromises when the melody is contrasts with the chord structure. A typical example of this is a chord with both a major and a minor third, for example G7#9. The absolute chord symbol (and often the melody as well) seems to indicate that we should write A sharp (A sharp ninth), but as often as not, we write B flat, the way it is easiest to perceive (as "10").
Notation of chromatically altered notes
There is a fixed tradition for writing chromatic scale progressions in major and minor keys. The basic rule is that in a rising melody, the notes of the diatonic scale (notes that are part of a major or a minor scale) are raised, and in a falling melody, they are lowered. There are, however, a few noteworthy exceptions to the rule.
In a major key, it is more common in a rising melody to lower the seventh degree than it is to raise the sixth degree. A flat seventh degree is common in some altered chords (e.g., V7/IV).
In a falling melody, instead of lowering the fifth degree, the fourth degree is always raised. Several altered chords (V/V) include this degree.
This tradition may also be derived from the fact that a tendency tone is assigned to the fifth degree. Standard notation never lowers the first, fourth, or fifth degrees since they all have tendency tones of their own.
In a minor key, a rising melody progresses according to the basic rule, but a falling melody borrows the chromatic alterations from a parallel major key. It is natural, of course, since the only difference between a melodic minor key and a major key is in the third degree.
Chromatic scale in C major
Chromatic scale in C minor
Below, we have included an example of Chopin's prelude in E minor, op. 28, in which the composer has lowered both the tonic and dominant! In bar two, it is possible to hear a second inversion of the dominant chord, with D sharp replaced by E flat. The same E flat is part of a pile of thirds in the following bar with a tritone substitution of a dominant chord (F75). A distinct falling chromatic line can be noted both in the melody and in the accompanying chords.