Skip to content

6. Fugal Devices ​

A fugue is not a form like a sonata — it is a procedure: one theme (the subject) enters voice by voice, travels through related keys, and returns intensified. Every device in that procedure is a contract between declared material and emitted notes, and the validator checks each one. These rules sit above the local interval rules from chapters 2–3, which keep applying throughout.

The fugue procedure at a glance

Exposition: each voice enters in turn with the subject or its answer; a countersubject may accompany those entries. Episodes: passages often use sequences or subject-related ideas to travel between keys, but their material can vary. Development: middle entries restate the subject in related keys; stretto and pedal points raise the temperature toward the close. The primer's fugue terms table defines each word in one line.

These labels describe common procedures rather than universal requirements; see Open Music Theory's exposition overview and Puget Sound's fugue analysis guide.

Subject and answer ​

When the second voice enters, it usually carries the subject toward the dominant — the answer. A literal transposition is a real answer; the exact interval can be a fifth up or a fourth down, depending on the entering voice. A tonal answer makes small intervallic adjustments where a literal transposition would destabilize the tonal center. The adjustments depend on the subject and its context; they are not limited to an I↔V head followed by an untouched tail.

Fugal deviceSubject, real answer, tonal answervoices play in turn
Play the three lines in turn. Copied a fifth higher, the subject's leap from scale degree 1 to 5 (C–G) becomes 5 to 2 (G–D), which leans toward the dominant key. The tonal answer replies to 5 with 1 (G–C) and copies the rest. The first notes are the same in both answers, so tonal_answer_dominant_mapping, which reads only the first note, cannot tell them apart; imitation_entry_match reads the whole answer window and can.
tonal_answer_dominant_mappingimitation_entry_matchBoth answers start on G. The real answer then copies the subject's leap to D; the tonal answer bends that one note to C.

The engine's fugue builder answers a fourth below the subject. It chooses a tonal answer when the subject opens on scale degree 5, or opens on 1 and reaches 5 within its next three notes. The tonal answer then swaps 1 and 5 inside its first four notes (in practice, a 5 in the subject is answered by 1 instead of 2) and transposes everything after that literally.

Two rules read the result. tonal_answer_dominant_mapping checks only the first note: a subject that opens on the tonic must be answered on the dominant, and the reverse. A real answer to a tonic-opening subject also starts on the dominant, so for those subjects this rule cannot tell real from tonal. The fuller check is imitation_entry_match, which reads the answer's whole window: a real answer keeps one transposition throughout, and a tonal answer may swap tonic and dominant only within its first four notes before rejoining the real transposition.

Here is the textbook case in Bach's own hand — the opening of the C minor fugue from WTC I. Play the two lines in turn and listen for the single bent note:

From BachBach: WTC I Fugue in C minor — the tonal answervoices play in turn
The most quoted tonal answer in the repertoire — the opening of the C minor fugue (WTC I, BWV 847). The subject begins C–B♮–C and drops to G: tonic to dominant. Answered literally a fifth higher, that fourth note would be D and the exposition would lurch out of the home key. Bach answers G–F♯–G and bends the one note back to C — tonic maps to dominant, dominant maps back to tonic, the tail transposes exactly. The engine would derive the same answer: a subject that opens on the tonic and reaches the dominant within its first four notes gets a tonal answer, and in those four notes the subject's G is answered by C. Its tonal_answer_dominant_mapping rule reads only the first note (C answered by G); the bent fourth note is checked by imitation_entry_match.
tonal_answer_dominant_mappingThe subject's fourth note falls to the dominant (G); the answer bends that one note back to the tonic (C) and transposes everything else literally.

A contrasting real answer appears in Bach’s G-minor “Little” Fugue (BWV 578): the displayed alto entry is a literal transposition of the quoted soprano opening, a perfect fourth below. The subject leaps from tonic to dominant at once, which is exactly the shape the textbook (and the engine) would answer tonally; Bach answers it literally:

From BachBach: "Little" Fugue in G minor (BWV 578) — a real answervoices play in turn
In the "Little" Fugue in G minor (BWV 578), the upper staff quotes the soprano in mm. 1–2 and the lower staff quotes the alto in mm. 6–7. The 11 displayed pitches and their durations match after a transposition of −5 semitones, a perfect fourth down. The full subject continues beyond these two bars; this comparison covers its opening only. The subject leaps straight from tonic to dominant (G–D), the textbook trigger for a tonal answer, and the engine would answer it tonally with D–G; Bach keeps the answer real. The staves are aligned for comparison and play sequentially, so they are not simultaneous voices.
The displayed opening of the subject returns five semitones lower in the alto entry.

The countersubject ​

Fugal deviceDeclared countersubject keeps sounding
A countersubject is a recurring companion in some fugues, not a requirement of every fugue. When material declares one, this engine contract samples every quarter-beat of the answer window and fails if the countersubject voice falls silent.
countersubject_continuousWhen a countersubject is declared, it fills every beat of the answer window without resting.

A countersubject is a recurring companion in some fugues, but it is not a required part of every fugue. When material declares one, countersubject_continuous samples every quarter-beat of the answer's window and requires a sounding note from the countersubject voice at each one. Since the pair is designed to be reused with voices swapped (invertible counterpoint), invertible_at_octave also checks it at structural accents; fourths are judged against the actual bass by vertical_dissonance.

In the same C minor fugue, the countersubject enters the moment the answer does — and never stops sounding under it:

From BachBach: BWV 847 — the countersubject at work
Bars 3–4 of the C minor fugue: the answer above, the countersubject below. The first E♭ is the last note of the subject; the countersubject starts with a sixteenth-note scale falling from C, leaps up to E♭, and steps down in eighths to A♮ before turning back toward G. Notice what it never does: rest. Every quarter-beat of the answer's window has the countersubject sounding, which is literally the check countersubject_continuous performs. The pair is built to be reused with the voices exchanged; chapter 2's invertible-counterpoint rules police that property, and bars 7–8 of the same fugue cash it in.
countersubject_continuousWhile the soprano sings the answer, the alto's countersubject fills every quarter-beat of the window without a single rest.

Episodes and sequences ​

Episodes are where fugues travel. Historical episodes often develop fragments of the subject or countersubject, and sequences are common, but they can also use free counterpoint or another salient idea. In this engine, only material explicitly declared as a motif transform must be derived from a source slice — restatement re-anchors the slice at its new position, inversion mirrors the contour upside down, retrograde plays it backwards, and augmentation/diminution stretch or compress every duration (not to be confused with augmented intervals from chapter 4). A declared sequence uses the same seed on successively higher or lower scale degrees.

A sequence can move its pattern in two ways. A tonal (diatonic) sequence slides the pattern along the scale: a half step in the seed may come back as a whole step, and the music stays in its key. A real sequence copies every interval to the semitone, which brings in accidentals and pulls toward other keys. Bach uses both; the tonal kind is the everyday one. Switch the figure between them:

EpisodeDescending sequence
one step lower —
Sequences are a common way for Baroque episodes to travel between keys. This is a tonal (diatonic) sequence: the pattern slides down the C major scale, its interval sizes adjust, and no accidental appears. sequence_pattern_consistency checks this form: each step moves the seed by scale degrees in the key. Switch to the chromatic copy to see what it rejects.
sequence_pattern_consistencyBar 2 repeats bar 1 one scale step lower; the half step C–B becomes the whole step B–A.

The engine's sequence_pattern_consistency rule is diatonic, like Bach's everyday sequence: each step moves the seed by scale degrees in the template's key (a minor key is respelled by the harmony, with the raised leading tone over V). A step shifted by the wrong number of degrees fails, and so does a semitone-exact copy that leaves the key. The fugue builder declares its episodes step by step.

Inversion has the same two forms. A diatonic mirror flips each move along the scale; a chromatic mirror flips each interval semitone for semitone. The engine expects the diatonic one:

EpisodeMotif inversion: the seed upside downvoices play in turn
mirror by —
Inversion turns a line upside down. Measured along the scale (a diatonic mirror), a step up becomes a step down and a third up becomes a third down, so the mirror stays in C major even though some sizes change: the seed's B–D is a minor third, the mirror's E–C a major third. Bach inverts this way, and so does the engine: episode_motif_derived mirrors scale degrees in the key in force, as the fugue builder does for its inverted middle entry.
episode_motif_derivedEach move of the seed comes back in the opposite direction, measured in scale steps.

Bach builds whole stretches of fugue from the diatonic form. In the D♯ minor fugue the subject and its mirror are full partners — the inverted form quoted below even arrives in stretto with another inverted entry:

From BachBach: WTC I Fugue in D♯ minor — the subject upside downvoices play in turn
The subject of the D♯ minor fugue climbs a fifth from tonic to dominant and circles back down. From the fugue's second half Bach turns the whole line upside down: the inverted form quoted here (bar 45) falls a fifth from dominant to tonic and circles back up — and it enters one bar after another inverted entry in the bass, an inversion stretto. Play the two staves in sequence: the rhythm is identical, and the contour is mirrored in scale steps, a tonal (diatonic) inversion. Steps stay steps, so a whole step can answer a half step (A♭–G♭ is answered by F–G♭), and the line stays in the key. The last leap is not mirrored at all: the subject rises a fourth (E♭→A♭) where the mirror would fall one, and the inversion falls a fifth (B♭→E♭) to keep its tonic–dominant frame. The engine mirrors the same way: its fugue builder inverts in scale steps, and episode_motif_derived checks an inverted episode against a diatonic mirror in the key in force. Quoted in E♭ minor spelling for readability; the companion voices around each entry are omitted, and the final note of each quote is trimmed to close the two-bar frame.
Same rhythm, note for note; each rise is answered by a fall of the same number of scale steps, until the closing leap.

The C minor fugue puts both ideas on display the moment its exposition pauses. Bars 5–6 — between the answer and the bass entry — sequence the subject's own head figure upward, one scale step per half bar, as a tonal sequence:

From BachBach: BWV 847 — the first episode climbs by step
Bars 5–6 of the C minor fugue — the bridge between the answer (bars 3–4) and the bass entry (bars 7–8). The episode's material is not new: the soprano's sixteenth cell E♭–D–E♭ is the subject's opening neighbour figure, restated one scale step higher each half bar — E♭, then F, then G — while the alto answers with rising sixteenth runs in its own sequence. It is a tonal sequence: the neighbour is a half step in the first statement (E♭–D) and a whole step in the next two (F–E♭, G–F). The engine's sequence_pattern_consistency is diatonic too: it expects each step to move the seed by scale degrees in the key, so Bach's version passes, whether declared as one sequence or step by step as the engine's fugue builder declares its episodes. The soprano's last F is tied on into bar 7, where the bass entry — the passage chapter 2 quotes for invertible counterpoint — takes over.
sequence_pattern_consistencyThe subject's head cell is restated one scale step higher each half bar while the alto runs counter-scales.
RuleContract
episode_motif_derivedFor a declared episode fragment, every note matches the expected output of the declared motif operation applied to the declared source slice — pitch, duration, and tick. Inversion mirrors scale degrees around a declared pivot in the key in force at the episode, not exact semitones.
sequence_pattern_consistencyFor a declared sequence, each step is the seed moved by the declared number of scale degrees in the template's key (1 for a step, 4 for a falling fifth), minor respelled per the harmony. A copy that leaves the key fails.

Imitation ​

ImitationImitative entry at the fourth below
Imitation declares a contract: the follower must enter exactly at the declared time distance and exactly at the declared interval. The validator checks the entry tick and the pitch offset, then compares every note of the declared window with the leader. Here C4 is answered by G3, a perfect fourth below, one bar later.
imitation_entry_matchThe follower restates the leader's figure one bar later, a fourth lower.

Imitation generalizes the subject/answer idea to any material: a follower restates the leader's fragment at a declared time distance and interval. imitation_entry_match verifies both numbers — enter at leader.tick + distance, pitched at leader.pitch + interval — and then compares every note of the declared window. In the engine, the fugue's answer is the declared imitation: the fugue builder and the fugue tails of the toccata and fantasia forms each declare their answer as an imitation of the subject.

A canon is imitation that never stops: the follower copies the leader for the whole piece. Bach wrote a set of them into the Goldberg Variations, one every third variation, with the interval growing by one step each time. The last of them, a canon at the ninth, keeps the follower one bar behind:

From BachBach: Goldberg Variations — canon at the ninth
Variation 27 (BWV 988), the last canon of the set and the only one without a free bass: two voices, nothing else. Whatever the leader plays, the follower replays one bar later, a ninth higher. In these two bars every pair happens to be a major ninth (14 semitones), so the follower needs a C♯. Bach's canons are diatonic, though: the follower moves along the G major scale, so a leader's B or F♯ is answered a minor ninth higher, by C or G. While the follower repeats the opening, the leader has already moved on to sparse interjections — the texture that keeps a strict canon breathing.
The follower restates the leader one bar later and a ninth higher; in this opening every pair is a major ninth.
VariationCanon atBachEngine's Goldberg model
3unisonupright, over a free bassupright, one bar behind
6secondupright, over a free bassupright, one bar behind
9thirdupright, over a free bassupright, one bar behind
12fourthfollower invertedupright, one bar behind
15fifthfollower inverted, in G minorupright, one bar behind
18sixthupright, over a free bassupright, one bar behind
21seventhupright, in G minorupright, one bar behind
24octaveupright, over a free bassupright, one bar behind
27ninthupright, two voices and no bassupright, one bar behind, over the aria bass

The engine's Goldberg model writes each canon the way Bach writes most of his: the follower is a diatonic transposition of the leader by the canon's number of scale steps, one bar later. It does not invert the canons at the fourth and fifth, it keeps the aria bass under every block, and it does not declare its canons as imitation entries, so imitation_entry_match does not apply to them; the canons are checked by the ordinary voice-leading rules.

Development devices ​

Middle entries ​

After the exposition, the subject returns in related keys.

What makes a key "related"?

Two keys are related when their scales share most of their notes, so the ear can slide between them without a jolt. The dominant and subdominant keys differ from home by a single accidental; the relative key (vi of a major key — A minor for C major) uses the same notes with a different center.

A key has five closely related keys, the ones whose scales differ from it by at most one accidental. Bach's middle entries draw on all five; the engine uses a subset:

Home keyBach's closely related keysValidator acceptsFugue builder uses
C majorG (V), F (IV), A minor (vi), D minor (ii), E minor (iii)V, vi, IV, iiV, vi, IV, each spelled in its own key
C minorE♭ (III), G minor (v), F minor (iv), A♭ (VI), B♭ (VII)v, III, ivv, III, iv, as degree shifts inside C minor

middle_entry_in_related_key checks the declared key and every note of the entry. A V, IV or ii entry is checked against that key's major scale. A vi entry is checked against its own minor collection, natural minor plus the raised seventh, so an A minor entry may use G♯. Every minor-mode entry is checked against the home minor collection: pitch-class offsets {0, 2, 3, 5, 7, 8, 10, 11} from the tonic, which holds both the natural and the raised seventh.

The builder's minor stations do not modulate. A "v" entry in C minor is the subject moved up four scale steps inside C minor, so it has no F♯, the leading tone a real G minor entry would need; the station states the chord on G rather than the key of G minor.

DevelopmentMiddle entry in the relative keyvoices play in turn
After the exposition the subject travels: here the C major subject returns in A minor, the relative key. The validator restricts the declared entry key to the related family (dominant, relative, subdominant, supertonic) and then checks every note of the entry against that key; an A minor entry may also use the raised seventh G♯. Play them in sequence: the same theme in a darker light.
middle_entry_in_related_keyThe subject returns transposed into vi — every note diatonic in the related key.

Stretto ​

DevelopmentStretto: entries overlap
In a stretto the subject chases itself: the second entry begins inside the first one's window. It is the classic intensification device near a fugue's climax. The validator requires a genuine overlap and an exact transposition of the subject.
stretto_overlap_validThe follower starts the subject before the leader has finished it.

No fugue demonstrates the device like the C major fugue that opens WTC I — Bach builds nearly the whole piece from strettos. By bar 7 the subject is already chasing itself at one beat's distance:

From BachBach: WTC I Fugue in C major — stretto at one beat
Bars 7–8 of the C major fugue (WTC I, BWV 846), the fugue famous for being built almost entirely of stretto. The soprano begins the subject; one beat later the alto begins it too, an octave and a fourth (an eleventh) below, and both statements run complete. A genuine overlap and an exact transposition — the two things stretto_overlap_valid demands. (The bass voice of these bars is omitted for clarity.)
stretto_overlap_validThe alto starts the subject one beat after the soprano, an eleventh below, entering together with the leader's third note.

Pedal point ​

DevelopmentTonic pedal point
A pedal point suspends the harmonic clock: the held bass lets the harmony above it change without moving. On beat 3 the dominant harmony (B and D) clashes with the held C, then resolves to the tonic chord. The validator does not police those clashes; it checks that the pedal pitch itself is the tonic or the dominant, the two degrees that can bear this weight.
pedal_point_tonic_or_dominantThe bass holds C while the two upper voices move I–IV–V–I above it.

The pedal point usually arrives near the end — a dominant pedal building tension before the final cadence, or a tonic pedal confirming arrival. Notice the rule's direction: it does not police the dissonances above the pedal (those are licensed by the device), it polices the pedal pitch itself.

The first prelude of WTC I shows the device at its barest. Before the ending, Bach spends eight bars hammering nothing but the dominant in the bass — here are two of them:

From BachBach: WTC I Prelude in C major — the bass refuses to move
Bars 24–25 of the C major prelude — the same ripple the primer's figure showed at bar 1, but now listen to the bottom. The harmony alternates above while the bass strikes G, and only G, again and again: a dominant pedal. Bar 24 is a dominant seventh. Bar 25 spells C–E–G, but over the held G it is a cadential 6/4 (see the primer's chord positions): the dominant with a sixth and a fourth above the bass that want to fall to the fifth and third. It lasts eight bars in the piece, winding the spring that the ending releases — and when release comes, Bach does it again, riding a tonic pedal C from bar 32 to the final chord. Its companion fugue closes the same way, with the last bar's voices running above a held C. Dominant and tonic: the only two degrees the validator lets carry this weight.
pedal_point_tonic_or_dominantFour strikes of the same G under two alternating harmonies — a dominant pedal stretching the tension.

How the engine lays out a fugue ​

The fugue builder follows one plan, so every generated fugue shows these devices in the same order. The figure lays out a 48-bar fugue in a major key.

How the engine lays out a 48-bar fugueThree voice lanes across 48 bars. Exposition, bars 1 to 12: the subject in the upper voice, the answer in the middle voice at bar 5 with the countersubject above it, the subject in the lower voice at bar 9. Development, bars 13 to 44: four cycles of a four-bar middle entry and a four-bar episode; the entries move through the dominant, the relative minor and the subdominant, the second entry is inverted, the third is answered in stretto, and the fourth sits in the dominant over a dominant pedal in the lower voice. Coda, bars 45 to 48: the subject head in augmentation, then a two-bar cadence.subject or answercountersubjectepisode or free voicedominant pedalexpositiondevelopment: four cycles of entry + episodecodauppermiddlelowersubjectCSfreeanswerCSsubjectsubjectCSepisodeinvertedCSepisodesubjectstrettoepisodesubjectCSpedalepisodeIVIVviIVVIV–I159131721252933374145barThe coda states the subject head at double note values, then closes V–I. From 80 bars, episodes run 2–6 bars; from 96 bars, an augmented and a diminished entry are added.
  • The subject fits in four bars. The answer enters at bar 5 with the countersubject above it, and the third voice enters with the subject at bar 9. Fugues under 20 bars keep only the first two entries.
  • The development alternates a four-bar middle entry with an episode, four bars long in most lengths and two to six bars in fugues of 80 bars or more. Entries rotate through the three voices and through V, vi and IV (v, III and iv in minor), and one of the other voices restates the countersubject.
  • With three or more development entries, the second one is stated in diatonic inversion.
  • The stretto sits at the entry nearest 80% of the development: another voice restates the subject one to three bars later, at the octave or the fifth. About one fugue in three with four or more entries adds a second stretto.
  • With two or more entries, the last one is stated in the dominant over a held dominant pedal.
  • The coda states the head of the subject in augmentation (double note values) and closes with a two-bar cadence.
  • Fugues of 96 bars or more also state the subject once in augmentation and once in diminution.

The fugue tails of toccata_and_fugue and fantasia_and_fugue are shorter: exposition, stretto and cadence, with figuration instead of episodes between them. Below 32 bars they have no stretto, and below 24 bars the exposition has two entries and no bass entry.

How the validator sees this chapter ​

RuleOutcomeCheck
tonal_answer_dominant_mappingMusicalFailReads the first note only: a subject opening on the tonic is answered on the dominant, and the reverse. Subjects opening on another degree pass.
countersubject_continuousMusicalFailThe countersubject voice sounds at every quarter-beat of the answer window.
countersubject_invertibleInformationalA strong-beat perfect fifth between a marked countersubject and an overlapping subject or answer would become a fourth under octave inversion. This observation is informational and never blocks generation.
episode_motif_derivedMusicalFailEpisode notes equal the declared motif transform of the declared source slice; inversion is a diatonic mirror in the key in force.
sequence_pattern_consistencyMusicalFailEach sequence step moves the seed by the declared number of scale degrees in the template's key.
imitation_entry_matchMusicalFailFollower enters at the declared tick distance and interval, and every note of the window matches; a tonal answer may swap tonic and dominant within its first four notes.
imitation_entry_realizationMusicalFailDuring Generation, emitted Material notes must match the declared leader/follower windows in pitch, onset, duration, voice, and intent; both entry heads need the realization marker.
middle_entry_in_related_keyMusicalFailIn major mode, entry key ∈ {V, vi, IV, ii}; V, IV and ii entries stay in their key's major scale, a vi entry in its own minor collection (with the raised seventh). In minor mode, entry key ∈ {v, III, iv}; notes use home-minor pitch-class offsets {0, 2, 3, 5, 7, 8, 10, 11}.
stretto_overlap_validMusicalFailFollower starts strictly inside the leader's subject window and is an exact transposition.
pedal_point_tonic_or_dominantMusicalFailEvery pedal pitch class is the home tonic or dominant.

Continue with Chapter 7 — Form-Specific Constraints.

Dual-licensed: AGPL-3.0 · commercial licensing available. Generated MIDI is yours to use freely.