Skip to content

5. Tonal Grammar ​

The rules so far judge notes and lines. This chapter judges sentences: how phrases end, how the music borrows chords from neighboring keys, and how it travels to a new key and back. These checks need more context than an interval — the validator reads them against the declared harmonic plan.

What is V to I?

Roman numerals describe chords relative to the key. In C major, I is C major, IV is F major, V is G major, vi is A minor. Upper case marks a major chord, lower case a minor one. A cadence is a closing gesture; V to I is the common dominant-to-tonic closure, but the validator also checks how the individual voices arrive there.

Reading the chord symbols

This chapter's tables use three decorations on Roman numerals. A small 6 (as in iv6) marks first inversion: the chord's third is the lowest note instead of its root — that is how the Phrygian cadence gets its half-step bass descent. A ° (as in vii°) marks a diminished chord, stacked from two minor thirds. A superscript 7 (as in V7) adds a fourth note a seventh above the root; that added note is the "chordal seventh" whose doubling is banned below. Combining the two gives vii°7, the diminished seventh chord: three minor thirds stacked, its outer span the diminished seventh (9 semitones) the chord is named after — Baroque music's most dramatic dominant substitute. Inverted seventh chords carry two figures: V6/5 has the chord's third in the bass, V4/3 its fifth, V4/2 its seventh (chord positions).

Cadences are voice-leading contracts ​

A cadence is more specific than "the harmony is V then I". In polyphonic music, each declared type promises particular outer-voice behavior — the highest and lowest sounding lines at the cadence. In a monophonic form, cadence_voice_leading checks the single line as a melodic cadence instead of requiring a separate bass. The engine knows seven types.

The two approaches are sampled differently. The upper line is read at cadence.tick - 1, immediately before the arrival, so a fast run inside the final beat is preserved. The bass remains structural and is read one quarter-note beat earlier.

Authentic: the period ​

Engine cadence cellEngine perfect-cadence pattern
In standard theory, a perfect authentic cadence is V–I with both chords in root position and scale degree 1 in the highest voice of the final tonic. A soprano 7→1 approach is one common realization, not a requirement. This figure shows the narrower 7→1 pattern used by the validator, which checks the declared cadence type rather than chord labels alone.
cadence_voice_leadingThis cell shows the engine’s narrow leading-tone-to-tonic and bass V-to-I pattern.

In standard tonal theory, a perfect authentic cadence (PAC) has three conditions: V–I harmony, both chords in root position, and scale degree 1 in the highest voice of the final tonic chord. The soprano may approach that tonic by step from scale degree 2 as well as from the leading tone 7. Within an authentic V–I close, if any one of those conditions is missing — for example, an inverted chord or a final soprano other than scale degree 1 — the close is an imperfect authentic cadence (IAC). See the three PAC conditions and IAC distinction.

The engine keeps a separate contract for its named perfect cadence cell. The sampled upper line must make the 7→1 leading-tone resolution, rising at most two semitones, and the bass must move from the dominant in root position (scale degree 5 → 1). It is narrower than the textbook on the soprano, which must make the 7→1 move, and matches it on the bass: an inverted dominant such as V4/3 → I does not pass the perfect cell, and belongs to the imperfect authentic type, as standard theory has it. The figure above shows the root-position case.

Bach’s Goldberg Aria includes a close with this 7→1 realization:

From BachBach: Goldberg Aria — the final cadence
The last two bars of the Goldberg Aria (BWV 988). In the penultimate bar the melody's sixteenths circle down onto F♯ — the leading tone — while the bass winds through the cadential harmony and lands on D. Then the contract closes: F♯ rises a semitone to G, the bass falls D to G, and an inner voice slips in only for the final bar to fill the chord. Outer-voice behavior at the cadence tick is exactly what cadence_voice_leading verifies for a perfect authentic close. The final notes are held under a fermata in performance; the excerpt trims them at the double bar.
cadence_voice_leadingThe melody lands on the leading tone F♯ and rises to G while the bass falls from dominant to tonic.

Imperfect authentic: the softer period ​

Cadence cellImperfect authentic cadence
An authentic V–I close that misses one condition of the perfect cadence. Here the soprano rises 2→3 and ends on E, while the leading tone resolves in the alto. The close still sounds like an arrival, only less final. The engine's imperfect cell checks the bass V→I and asks only that the upper voice land on a tone of the tonic triad.
cadence_voice_leadingV moves to I in root position, but the soprano ends on the third of the tonic chord.

The two common ways to miss a perfect cadence are a soprano that ends on 3 (or 5) of the tonic chord, and a dominant chord that stands on an inverted bass. Switch the figure to hear both. The engine's imperfect cell checks the bass V→I, in the inversion the plan declares, and asks only that the upper voice land on a tone of the tonic triad. Deceptive and Picardy closes accept the planned inversion in the same way.

Plagal: the amen ​

Cadence cellPlagal cadence (IV - I)
The "Amen" cadence. There is no leading tone, so the sense of closure comes from the bass motion IV to I. The validator recognizes the plagal type from the declared cadence event, checks the bass IV → I, and requires the upper voice to land on a tone of the tonic chord.
cadence_voice_leadingThe bass falls from the subdominant to the tonic while the upper voice holds the tonic.

Half: the comma ​

Cadence cellHalf cadence (ends on V)
A half cadence parks the music on V and leaves it expecting continuation. Inside a generated piece it articulates phrase boundaries without closing the paragraph; the final cadence of a section is authentic instead.
cadence_voice_leadingThe phrase stops on the dominant — a musical comma, not a period.

Deceptive: the feint ​

Cadence cellDeceptive cadence (V - vi)
Everything promises a final close — then the bass moves to vi instead of I. Bach uses the deception to extend a phrase that seemed finished. The validator accepts the declared deceptive type only when the bass really arrives on the sixth degree.
cadence_voice_leadingThe leading tone still resolves up, but the bass sidesteps to the sixth degree.

Here is the feint in the wild — three voices of the F major fugue assemble a complete V7, the upper voices resolve exactly as promised, and only the bass slips upward to vi:

From BachBach: WTC I Fugue in F major — the bass that breaks its promise
Bars 10–11 of the dance-like F major fugue. On the last eighth of the bar the three voices align into a complete dominant seventh: C in the bass, the leading tone E on top, the seventh B♭ in the inner voice. Then every tendency tone keeps its promise — E rises to F, B♭ falls to A — except the bass, which breaks its own: instead of dropping home to F it steps up to D, and the downbeat chord is vi. The phrase that sounded finished keeps moving, and Bach rides the evasion straight into the next entry. The validator accepts a declared deceptive cadence on exactly this evidence: the upper voices resolve as if the close were real, and the bass alone lands on the sixth degree.
cadence_voice_leadingA full V7 gathers on the last eighth of the bar — and the bass steps up to D instead of home to F.

Phrygian: the archaic close ​

Cadence cellPhrygian cadence (iv6 - V in minor)
The signature Baroque ending for a slow minor movement: the half-step descent in the bass against contrary stepwise rise above. It ends on V like a half cadence, but the half-step bass approach gives it a distinct, archaic color. In A minor the bass falls F→E (♭6→5) and the upper voice rises D→E (4→5). In polyphony the engine checks both: the bass must fall exactly one semitone and the top voice must rise by at most two.
cadence_voice_leadingThe bass descends by half step onto the dominant while the upper voice rises by step.

The name comes from the Phrygian mode, the church mode whose scale has a half step directly above its final note (E–F on the white keys). The bass's half-step fall onto the dominant borrows that sound.

Bach ends an entire movement this way. The Largo of the fifth organ trio sonata closes on V — phrygian descent in the pedal, a pair of suspensions resolving above — and hands the open door to the finale:

From BachBach: Trio Sonata No. 5, Largo — a movement that ends on V
The last two bars of the Largo from the fifth organ trio sonata (BWV 529), in A minor. The pedal descends A-G-F and then makes the signature half-step drop onto E: the phrygian close. Above it Bach hangs two suspensions across the final bar line — the fourth (A) and the raised seventh (D♯) hold over the new bass, then melt into G♯ and E. The movement ends on that E major sonority and never comes home: a phrygian cadence is a half cadence by nature, and what it opens the door to is the finale in A minor that follows. Dominant preparation at the scale of a whole movement. The engine's polyphonic Phrygian check is narrower than Bach: it wants the top voice itself to rise 4→5 (D→E). Here the top voice falls A→G♯ and the rising step D♯→E sits in an inner voice, so this close would not pass as the engine's Phrygian cell.
cadence_voice_leadingThe pedal walks down to F, slides a half step onto E — and the movement stops there, on the dominant, door open.

Picardy: minor ends major ​

Cadence cellPicardy third
The final chord of a minor-mode work brightens to major. In A minor the dominant seventh E–G♯–D resolves with every tendency tone keeping its promise: G♯ rises to A, D falls to C♯, the bass moves E→A. The raised third needs an accidental. The cadence check accepts either the leading-tone resolution or a step onto the raised third in the upper voice; the separate picardy_third rule checks that the final chord sounds C♯ and never C♮ while it lasts.
cadence_voice_leadingpicardy_thirdAn A minor close lands on A major: the leading tone G♯ rises to A, and the seventh D falls to C♯, the raised third.

The engine checks a declared Picardy close in two places. cadence_voice_leading wants the bass to move V→I and the upper voice either to resolve the leading tone or to step onto the raised third. The separate picardy_third rule checks the harmony: in a minor key, the chord the plan flags as Picardy must sound its major third and never its minor third.

And here is the convention at work — the very last bar of the C minor fugue from WTC I, dominant tension over a tonic pedal melting into a major chord:

From BachBach: BWV 847 — the final bar turns major
The last bar of the C minor fugue (WTC I, BWV 847). The bass has held the tonic C since bar 29; above it the dominant harmony gathers one last time, the upper voice climbs F–G–A♭ and falls back, and the chordal seventh F resolves down to E natural — the raised, major third, sounding on top as the piece ends. A minor fugue closing on a major chord is the Picardy convention: here the upper voice steps onto the raised third, one of the two shapes the engine's cadence check accepts, and E♮ sounds with no E♭ beside it, which is what the picardy_third rule asks. One difference remains: the engine's cadence check also wants the bass to move V→I, and Bach's bass holds its tonic pedal instead. (One inner voice is omitted; the score doubles the pedal an octave lower.)
cadence_voice_leadingOver the tonic pedal, the seventh of the dominant harmony (F) falls to E♮ — a major third ends a C minor fugue.
Cadence typeValidator checks
Perfect authenticUpper voice rises 7→1 (at most two semitones); bass moves from the root of V to the tonic (5→1), so an inverted V does not pass. Standard theory also allows a 2→1 soprano.
Imperfect authenticBass moves V → I, in the inversion the plan declares; the upper voice lands on any tone of the tonic triad.
PlagalBass moves IV → I; the upper voice lands on a tonic-triad tone.
HalfThe bass arrives on the dominant; a rest just before the arrival is allowed.
DeceptiveThe bass moves from V to the sixth degree (vi, or ♭VI in minor) instead of the tonic.
PhrygianIn minor: the bass falls exactly a semitone ♭6 → 5, and in polyphony the top voice rises 4 → 5 by at most two semitones. A single line may state either shape.
Picardy thirdBass V → I; the upper voice resolves the leading tone or steps onto the raised third. The chord's major third itself is checked by picardy_third.

Doubling: tendency tones stay single ​

Some scale degrees carry an obligation (the leading tone wants the tonic; a chordal seventh wants to fall). Giving the same obligation to two voices guarantees one of them breaks it — or they resolve in parallel octaves.

DoublingDoubled leading tone
Doubling the leading tone creates multiple voices demanding the same resolution.
doubling_no_leading_toneThe leading-tone pitch class appears in more than one voice.
DoublingDoubled seventh
The seventh is a tendency tone. Seventh-quality chords keep it single to avoid competing resolutions.
doubling_no_seventhThe chordal seventh appears in more than one voice.

Cross relations: chromatic contradictions ​

ChromaticCross relation
The red notes sound the same scale degree with different inflections at the same time. The completed-score validator also checks adjacent onsets when neither voice starts another note between them; natural E-F and B-C half steps are different degrees and are excluded.
cross_relationDifferent voices contradict the same scale degree chromatically in close succession.

When one voice sounds F♯ while another sounds F♮, the listener hears the key contradict itself: one line claims the chromatic form of a degree while another insists on the diatonic form. The completed-score validator checks simultaneous notes and adjacent note onsets. For an adjacent pair, neither voice may start another note strictly between the two onsets, regardless of their distance in ticks; the pair is judged in the local key at the later onset. Natural half-step pairs (in C major, E–F and B–C; in C minor, D–E♭ and G–A♭) are not cross relations — they are different scale degrees, not chromatic alterations of the same degree. The candidate-placement helper still uses a beat-wide pre-check because the rest of a partial score is not known yet.

Secondary dominants: borrowed tension ​

Applied harmonySecondary dominant resolving (V/V - V)
A secondary dominant borrows dominant function for a chord other than the tonic. In C major, F♯ is foreign to the key; inside the declared V/V region the validator reads it as G's leading tone, which must rise to G, and secondary_dominant_resolution checks that the next chord really is V. The region also suspends the forbidden-leap rules, so a leap inside the D major chord such as C→F♯, a tritone, would pass there.
secondary_dominant_resolutionThe chromatic F sharp acts as a local leading tone and resolves up to G.

A secondary (applied) dominant treats a diatonic chord as a momentary tonic and approaches it with its own dominant — written with a slash and read "of": V/V is "the V of V" (in C major: D major, the dominant of G), V/vi the dominant of the vi chord, and so on. This is the engine's main source of legal chromaticism:

  • Inside the declared applied region, the melodic rules (augmented_melodic, diminished_melodic, tritone_melodic) are exempt — the chromatic motion is the device.
  • In exchange, secondary_dominant_resolution verifies the promise: the next chord must actually be the targeted degree. The rise of the borrowed leading tone is tracked descriptively via provenance, while the hard check is the degree-level resolution.

Pivot-chord modulation ​

ModulationPivot-chord modulation (C major to G major)
A pivot chord belongs to both the old key and the new one, so the ear can reinterpret it mid-phrase. Bar 1 states C major with I–IV6–V–I. Am (vi in C, ii in G) then turns toward a D major chord whose F♯ only makes sense in G, and the arrival on G confirms the new key. The validator requires the declared pivot chord to be diatonic in both keys.
modulation_pivot_chord_requiredBar 1 settles C major; the A minor chord that opens bar 2 is vi in C and ii in G, and the D major chord after it belongs only to G.

To modulate convincingly, Baroque practice routes through a pivot chord — one that is diatonic in both the old key and the new key, so the ear can reinterpret it mid-phrase. For pivot-type modulations, modulation_pivot_chord_required verifies that the declared pivot really belongs to both keys. (The engine also models common-tone and phrase modulations, which carry their own declared shapes rather than a pivot.)

How the validator sees this chapter ​

RuleFailKindCheck
cadence_voice_leadingStructuralFail / MusicalFailAt the cadence tick, polyphonic outer voices or the single monophonic line match the declared cadence type. The upper approach is sampled one tick before arrival; a distinct bass is sampled one beat before. A missing cadence voice or a cadence earlier than one beat is StructuralFail; a voice-leading mismatch is MusicalFail.
picardy_thirdMusicalFailIn a minor key, a chord the harmonic plan flags as Picardy must sound its major third and never its minor third anywhere in its span. In a major key the rule is idle.
doubling_no_leading_toneMusicalFailThe leading-tone pitch class sounds in at most one voice when the chord contains it (V, vii°, V7, vii°7).
doubling_no_seventhMusicalFailA seventh-quality chord's seventh is not doubled.
cross_relationMusicalFailVoices sound the same scale degree in the local key at the later onset, with different inflections, either simultaneously or at adjacent note onsets (neither voice has another onset strictly between them). Natural semitone pairs between different degrees are excluded. The partial-placement pre-check remains beat-wide; FinalScore uses completed-score onset adjacency. Both-material pairs are exempt during Generation only; FinalScore audits every source, and the form's vertical budget decides whether observed findings close the form.
secondary_dominant_resolutionMusicalFailA chord marked V/x is followed by degree x.
modulation_pivot_chord_requiredMusicalFailA pivot modulation's pivot chord is diatonic in both keys.

Continue with Chapter 6 — Fugal Devices.

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