Music written in all major or minor keys

There is a long tradition in classical music of writing music in sets of pieces that cover all the major and minor keys of the chromatic scale. These sets typically consist of 24 pieces, one for each of the major and minor keys (sets that comprise all the enharmonic variants include 30 pieces).
Examples include Johann Sebastian Bach's The Well-Tempered Clavier and Frédéric Chopin's 24 Preludes, Op. 28. Such sets are often organized as preludes and fugues or designated as preludes or études. Some composers have restricted their sets to cover only the 12 major keys or the 12 minor keys; or only the flat keys (Franz Liszt's Transcendental Études) or the sharp keys (Sergei Lyapunov's Op. 11 set). In yet another type, a single piece may progressively modulate through a set of tonalities, as occurs in Ludwig van Beethoven's Two Preludes through all twelve major keys, Op. 39.
The bulk of works of this type have been written for piano solo, but there also exist sets for piano 4-hands; two pianos; organ; guitar; two guitars; flute; recorder; oboe; violin solo; violin and piano; cello solo; cello and piano; voice and piano; and string quartet. There are examples of attempts to write full sets that, for one reason or another, were never completed (Josef Rheinberger's organ sonatas, Dmitri Shostakovich's string quartets, César Franck's L'Organiste).
A number of composers have written multiple sets of works covering all the keys of the scale.
Full details are shown in the tables below.
Ludwig van Beethoven wrote 2 Preludes through all 12 Major Keys, Op. 39 for piano (1789). These two preludes each progressively traverse the 12 major keys. In Prelude No. 1, each key occupies from 2 to 26 bars. The keys of C# and D♭, which are enharmonically equivalent, are both represented. C major both opens and closes the set. In Prelude No. 2, the cycle of keys appears twice; in the first cycle, the number of bars per key ranges from 1 to 8; in the second half, after C every new key signature lasts for only one bar; the cycle concludes with 15 bars of C major. There is no evidence that Beethoven intended to write similar sets in the 12 minor keys.
Giovanni Battista Vitali (1632–1692) included in Artificii musicali, Op. 13 (1689) a passacaglia which modulates through eight major keys (out of twelve) from E♭ major to E major through the cycle of fifths.
Fugue No. 8 from Anton Reicha's Trente six Fugues pour le Piano-Forté composées d'après un nouveau systême (subtitled Cercle harmonique) modulates through all keys.
The rondo theme of Darius Milhaud's Le bœuf sur le toit is played fifteen times in all 12 major keys (twice in A major and three times in the tonic, C major). It also passes through every minor key except E minor and B minor.
Around 1704, Johann Pachelbel completed his 95 Magnificat Fugues, which covered all eight of the church modes.
Charles-Valentin Alkan composed Petits préludes sur les huit gammes du plain-chant, for organ (1859, no opus number), a sequence of eight organ preludes covering each of the church modes.
In the music of the Eastern Orthodox Church, the doxasticon for Vespers of the Dormition is notable as a single hymn that includes passages in all eight tones of the Byzantine Octoechos.
Not all sets of 24 pieces belong in this category. For example, there was no intention in Niccolò Paganini's 24 Caprices for solo violin, Claude Debussy's 24 Préludes for piano, or Pavel Zemek Novak's 24 Preludes and Fugues for piano to cover all the keys. (Paganini may not have been aware of Pierre Rode's 24 Caprices for violin, which did span the 24 keys and were written almost at the same time as Paganini's.)
Chopin's 24 Études, Opp. 10 & 25 might have originally been planned to be in all 24 keys. In fact, apart from Nos. 7 and 8, the first series (Op. 10) is made of couples of études in a major key and its relative minor (the major key either preceding the minor key or following it) with none of the tonalities occurring twice (except for C major, which appears in No. 1 and then in the only couple which is not major-minor, i.e. Nos. 7 and 8). But in the second series (Op. 25) this tonal scheme gets more and more loose. It is still possible to see connections on a tonal basis between the couples of études in Op. 25, but they are not based on one principle (e.g. Nos. 3 and 4 in F major – A minor, two tonalities which Chopin likes to put together very often, as in his second Ballade). One might suppose that Chopin considered writing the études in all the tonalities but eventually came to the conclusion that it wasn't practical, and turned back to it later, for the 24 Preludes, Op. 28. The fact that the first étude of Op. 10 is made of arpeggios in C major draws a connection to Bach's first book of The Well-Tempered Clavier and makes it clear that Chopin had the tradition on his mind.
There are 12 notes in the octave, and each of them can be the tonic of one major and one minor key. This gives 24 possible keys, but each note can be represented by several enharmonic note names (note names which designate the same actual note in the 12 note octave such as G# and A♭) and so each key can be represented by several enharmonic key names (e.g. G# minor and A♭ minor).
In practice, the choice of key name is restricted to the 30 keys whose signatures have no double flats or double sharps. (Such key signatures are used for so-called theoretical keys which are almost never encountered outside music-theoretical exercises.) Keys with 6 flats and 6 sharps, with 7 flats and 5 sharps and with 5 flats and 7 sharps are enharmonic to one another. Composers will, in most (though not all) cases, choose only one key from each enharmonic pair. But there are also cases of sets covering all 30 keys, which, in other words, include all enharmonic variants.
The table below outlines the choices made in the various collections listed here. The keys are in the order that J.S. Bach used.
The circle of fifths, whereby each major key is followed by its relative minor key, and the sequence proceeds in fifths (C, a, G, e, D, b ...) is a commonly used schema. Angelo Michele Bartolotti used this approach as early as 1640, and it was also adopted by such later composers as Rode, Hummel, Chopin, Heller, Busoni, Scriabin, Shostakovich, Kabalevsky and Kapustin.
In J.S. Bach's The Well-Tempered Clavier and some other earlier sets, major keys were followed by their parallel minor keys, and the sequence ascends chromatically (C, c, C#/D♭, c#, D, d, ...). The Bach order was adopted by Arensky, Glière, York Bowen and others.
Other composers derived their own schemas based on certain logical rationales. For example, in Alkan’s 25 Preludes, Op. 31, the sequence of keys moves alternately up a fourth and down a third: the major keys take the odd-numbered positions in the cycle, proceeding chromatically upwards from C to C again, and each major key is followed by its subdominant minor.
Yet others used no systematic ordering. Palmgren, Rachmaninoff and Castelnuovo-Tedesco's works are examples of this.
Johann Sebastian Bach's The Well-Tempered Clavier, two complete sets of 24 Preludes and Fugues written for keyboard in 1722 and 1742, and often known as "the 48", is generally considered the greatest example of music traversing all 24 keys. Many later composers clearly modelled their sets on Bach's, including the order of the keys.
It was long believed that Bach had taken the title The Well-Tempered Clavier from a similarly named set of 24 Preludes and Fugues in all the keys, for which a manuscript dated 1689 was found in the library of the Brussels Conservatoire. It was later shown that this was the work of a composer who was not even born by 1689: Bernhard Christian Weber (1712–1758). In fact, the work was written in 1745–50 in imitation of Bach's example. While Bach can safely claim the title The Well-Tempered Clavier, he was not the earliest composer to write sets of pieces in all the keys:
As early as 1567, Giacomo Gorzanis [it; de; ca; fr] (c.1520–c.1577) composed twelve settings of the passamezzo antico and passamezzo moderno, each followed by a saltarello, in all 24 keys. In 1584, Vincenzo Galilei, father of Galileo Galilei, wrote a Codex of pieces illustrating the use of all 24 major and minor keys.
In 1640, Angelo Michele Bartolotti wrote Libro primo di chitarra spagnola, a cycle of passacaglias that moves through all 24 major and minor keys according to the circle of fifths. Also in 1640, Antonio Carbonchi wrote Sonate di chitarra spagnola con intavolatura franzese for guitar.
In 1702, Johann Caspar Ferdinand Fischer wrote a cycle of 20 organ pieces all in different keys in his Ariadne musica. These included E major as well as E in Phrygian mode and again in Dorian mode, but not E minor per se. They also excluded C#/D♭ major, D#/E♭ minor, F#/G♭ major, G#/A♭ minor, and A#/B♭ minor. Bach modelled the sequence of his 48 Preludes on Fischer's example.
In 1735, between Bach's two sets, Johann Christian Schickhardt wrote his L'alphabet de la musique, Op. 30, which contained 24 sonatas for flute, violin, or recorder in all keys. In 1749, the year before Bach's death, Johann Gottlieb Goldberg, the inspiration for J.S. Bach's Goldberg Variations, wrote his own 24 polonaises for keyboard, one in each of the major and minor keys. Other examples include works by John Wilson (1595–1674), Daniel Croner (1682), Christoph Graupner (1718), Johann Mattheson (1719), Friedrich Suppig (1722), and Johann David Heinichen (1683–1729).
The following is an incomplete list of works of this type that have been written since the death of J.S. Bach.
Legend: AC = ascending chromatic; C5 = circle of fifths, major followed by relative minor; C5* = circle of fifths, major followed by parallel minor