The Canon Machine

Bach · BWV 988 · the nine canons

Every third variation in Bach’s Goldberg Variations is a canon: a second voice that copies the first exactly — the same tune, entering later, and shifted to start on a different note. There are nine, and that shift widens by one step each time. In the first the copy sings the very same pitches; by the ninth it sits more than an octave away.

Which is harder than it sounds, because you only get to write one line — the second is generated from it by rule. Every note has to work twice: once where you put it, and again wherever its copy lands. And all thirty variations sit on the same bass, thirty-two notes long, unchanged anywhere in the work. So each tune had to be built so that it and its own copy together would fit a harmony fixed before Bach began. Nine times, at nine different distances.

This page shows how he did it, one canon at a time. Pick any of the nine and it builds itself in front of you: the bass, then his single line, then that line carried into place by the rule to become the second voice — and finally the answer he actually engraved, printed over the top. Wherever the rule alone was enough, the two fuse and vanish into one another. What stays visible is the small residue where Bach overrode his own mechanism, and it is never very much.

Except twice. In two of the nine, no single rule reproduces the movement at all, because he changes the answer partway through — and those two turn out to be the most interesting things in the set.

No music reading needed — pitch is height, time runs left to right. The dials are there if you want to move his answer and see why it sits where it does, but nothing asks you to.

The nine, in Bach’s order. Each diagram shows the shape of that rule — how far apart the voices sit, how long the second waits, and in two of them that the copy is turned upside down. The last has no bass at all.

Interval
Motion
Delay

leader — Bach’s, given your answer — computed engraved answer free bass the ground bass — 32 notes

Those thirty-two vertical columns are the ground bass: the bass line of the opening Aria, one note to a bar. Every movement of the Goldberg Variations is built over it and not one of them alters it — the variations are on the bass, not on the tune. It is the fixed thing these canons are woven across, and the reason a canon written over it has to survive a harmony it did not choose.

analysis

How this was made

A MusicXML file records what is printed: pitches, durations, barlines. It does not record that the upper voice of Variation 18 is answering the lower one a sixth higher and half a bar later, or where the thirty-two notes of the ground sit beneath a movement in 3/8 with alternate endings, or which second of a recording any of that falls on. All of it has to be worked out. This is how.

The sources

Two files. The score is the Open Goldberg Variations edition — MusicXML, 990 measures. The recording is Kimiko Ishizaka’s 2012 performance of that edition, made at Teldex Berlin, and archived at the Internet Archive. Both are released under CC0, which waives copyright and the neighbouring rights that normally attach to a recording, and is the reason a performance can be played here at all. Trademark is not waived: the credit to MuseScore and Open Goldberg is due, and implies no endorsement.

Reading the score

Each note becomes a row: onset in quarter-notes, duration, staff, voice, measure, and the engraved spelling — letter, accidental, octave.

The spelling is the part that earns its place. Everything here reasons in scale degrees, and a degree cannot be recovered from pitch alone. F sharp and G flat are the same key on a keyboard and different degrees on a stave, and in G minor the difference is a seventh. An earlier version of this pipeline inferred degrees from MIDI numbers by taking the nearest note of the scale; a pitch a semitone off the scale is equally near two of them, and the tie went to whichever the loop reached first. That put 117 of these movements’ 4,594 notes on the wrong degree, concentrated in the two G-minor canons, where the raised leading note is everywhere. The score had been spelling it correctly the whole time.

Four clocks

A movement keeps several kinds of time at once, and they are not interchangeable. There is the order the measures are printed in; the thirty-two ground positions they sit on; the order they are actually played in, once repeats and alternate endings are unfolded; and the seconds of the recording.

Variation 6 is where those come apart. It is the only one of the nine with first- and second-time endings: 36 printed measures, played as 64 bars in four passes of sixteen, over thirty-two ground positions. Bars 17 and 35 are printed inside a first-time ending but belong structurally to the head of the next pass — bar 17 is very nearly a restatement of bar 1, and bar 35 of bar 19. Treating the printed order as the played order costs about 8% in alignment accuracy against the recording (a warping cost of 0.2574 against 0.2359) and pushes four bars outside the ground entirely. Those four are the shaded regions in Variation 6’s plate. No other canon has any.

Finding the canon

Nothing in the score says which notes are the canon and which are free accompaniment, so the voices are separated by search. Notes are matched in scale-degree space with alterations allowed to float, so a chromatic inflection does not break a pairing; a transformation is fitted region by region, and roles are assigned a measure at a time. Out comes a leader, a follower, a free bass where there is one, and an explicit pairing between individual notes of the two canonic voices.

Two findings came out of that search rather than out of the literature. Variation 24 answers at the octave below, above, above, below across four regions. Variation 27 answers a ninth above through its first half and a ninth below through its second. Neither is reproducible by any single rule, which is what the plate for each shows.

The search has one recurring difficulty, which is that the engraver’s voice numbers are not stable across barlines. In Variation 6 the free bass is voice 6 for most of the movement, but in bar 6 the same line is written as voice 5 — so a bass identified once for the whole movement simply disappears for a bar, and its notes are swallowed into the canonic voices. Register does not resolve it there (the two lines run two semitones apart), and neither does canon affinity (a stepwise bass under a canon at the second matches the transform by coincidence). What resolves it is engraving: a free bass is written on the lower staff and stays there, while a canonic voice diving into the same register still leaves notes on the upper staff in that bar. Applying that recovers 41 notes across four bars.

Pairing coverage — the share of leader notes with an identified partner — runs 98.8% in Variation 18, 94.2% in Variation 27, 93.5% in Variation 24, and 66.9% at its lowest, in Variation 15. Where no partner is found the note is counted separately and excluded from every figure quoted above; that is a property of the search rather than of the music, and it comes to 56 notes across all nine movements, over half of them in Variations 3 and 6.

Following the recording

Score and audio are matched by dynamic time warping over chroma features, at a hop of about 93 milliseconds and thinned to roughly two anchor points per second — the resolution the inking needs and no finer. The repeat structure is not assumed: candidate readings are generated from the score’s own barlines and scored by warping cost, so the performance selects its own form. Eight of the nine choose a full double repeat outright. Variation 27 leaves two candidates within one percent of each other, and the reading that accounts for more of the audio is taken, its track running on into Variation 28.

Making the answer

The second voice is not stored. It is computed in the browser from the leader. Writing L for the leader in scale degrees and s for the interval, direct motion is

A(n) = L(n) + s

and contrary motion reflects the line about the leader’s opening note:

A(n) = 2·L(0) + s − L(n)

displaced in time by the delay, given in ground-notes and converted to quarters by the movement’s metre. Because the answer is the leader transformed, it is drawn once in the leader’s own position and then moved: interval a vertical shift, delay a horizontal one, inversion a reflection. When a canon assembles itself on screen, that motion is the operation being performed, not a picture of it.

Reading the differences

Set the computed answer against the engraved one and the disagreements sort themselves into kinds: a degree Bach sharpens or flattens where the rule kept it diatonic; a note shifted to land a cadence; a note dissolved into ornament; a note belonging to a region that answers at a different interval; a note where he goes somewhere else entirely. Naming them separately is the point of the exercise. A canon at the seventh that agrees with a strict copy at 131 notes out of 205 has not been broken; it has been inflected, ornamented and cadenced, and the breakdown says which.

Drawing it

Height is scale degree, time runs left to right. Every note is a capsule as long as the note, so a held note is a long ribbon and a passing note a short one, and a rest is a gap rather than a diagonal drawn through silence. Each thread lays a paper-coloured halo beneath itself, which means that where two voices cross the upper one breaks the lower: the weave is a consequence of the drawing order, not an effect applied afterwards.

The thirty-two ground columns are placed through the timeline rather than by dividing the bar count. Variation 27 has no sounding bass, so its columns are drawn as blind embossing — present, unsounded, visible only as light and shadow. The whole-movement view draws each voice as a smoothed contour, because at that width a note is three pixels and capsules become a picket fence; the detail view draws every note.

Moving it

The answer is one element carrying one transform, so changes animate by interpolating that transform. Contrary motion sweeps the reflection factor from +1 through 0 to −1, collapsing the answer onto a mirror line and unfolding it inverted on the far side. The engraved answer prints in behind an advancing clip, and each note the rule got right sinks into it as the front passes.

Playback inks the plate rather than running a cursor across it. Ahead of the music the threads sit pale, like a first pull; a sounding note is fully inked and swells; a released one dries back over a couple of beats; the ground column beneath the music takes a brief emboss. Only the notes near the playhead are touched on any frame, which is what keeps it smooth over six hundred of them.

The two counts

Onset collisions counts notes that begin against a sounding second, seventh or tritone in the leader or the bass. It reads onsets only: it does not know metre, preparation or resolution, so a prepared suspension counts the same as a clash. Bach’s own answers are not free of them — twenty in Variation 18 — which is the useful thing it shows. Pitch-onset matches requires the same onset, the same degree and the same pitch, and makes no attempt to match one note against two through an ornament.

Colophon

The pipeline is Python: music21 for the score, librosa and NumPy for the alignment. The page is one HTML file with no framework, no build step and no third-party code — the drawing is SVG generated in the browser, the synthesised playback is Web Audio, and the mark at the top is drawn from Variation 18’s opening notes by the same pipeline that feeds the plates. Served as static files from Cloudflare Pages. Typeset in Hoefler Text; the red, blue and ochre follow Oliver Byrne’s 1847 Euclid, in Nicholas Rougeux’s digitisation.