♪Music, Built

Act III · Voices

Part 20 of 68

Canon and Fugue

Foundationsstarts at this level35 min of film14 chaptersprerequisites: Part 14, Part 16, Part 17, Part 19

Which melodies can be combined with themselves, and how is a fugue built from them?

On 7 May 1747 Frederick the Great gave Bach a theme and asked for a fugue; Bach answered with the Musical Offering, a six-voice fugue and canons set as riddles. A round works when every piece of a tune agrees with every other: sung against itself in three voices, Part 14's tunes rank Frère Jacques, Row, Row, Row Your Boat and Three Blind Mice first, third and fourth of 54, though the program was never told which were rounds. Canons exist at every interval, as Bach's Goldberg canons show; a dynamic programme counts them exactly, about one melody in 536 at the fifth and one in 1,539 at the fourth, the hardest interval. The four forms of a line, prime, inversion, retrograde and retrograde inversion, make Klein's four-group. Invertible counterpoint at the octave turns fifths into fourths, so a counter-line without fifths survives the swap and one with them does not. Crab canons, counted from both ends, grow about 25-fold for every two notes; a canon raised a tone each lap and played in Shepard tones climbs for ever. A fugue's tonal answer swaps tonic and dominant in the subject's head; a Viterbi search writes a countersubject, and a three-voice exposition on the Tune comes out with no dissonant beat; the Tune's phrase allows 11 strettos, the closest two beats behind a fourth below. The Art of Fugue does all of this to one subject and ends, unfinished, on B-A-C-H. The Tune is heard as a canon, a crab canon and an exposition.

What you need. Part 4 for Shepard tones; Part 14 for the tunes; Part 16 for two-voice rules; Part 17 for Viterbi search; Part 19 for keys. Dynamic programming and small groups.

Ideas, mathematics and history
rounds, invertible counterpoint, the symmetries of a subject, tonal answers, stretto, the Musical Offering and its endlessly rising canon
What we build, compute and hear
a canon solver; a three-voice fugue exposition on the Tune

What you will be able to do

Foundations

  • Sing or play a round and say why it works; name the four forms of a line and recognize them by ear.
  • Identify subject, answer, countersubject and stretto in a fugue exposition.
  • Write the tonal answer to a subject that begins on tonic and dominant.

Full course

  • Count canons exactly by dynamic programming over the leader's last notes, and crab canons from both ends.
  • Judge two or three lines for dissonant beats and parallels, and list a subject's strettos.
  • Write a countersubject by Viterbi search, invertible at the octave.

Research

  • Show that prime, inversion, retrograde and retrograde inversion form Klein's four-group, and what adding transposition gives.
  • Describe computational fugue analysis and what makes entry detection hard.

Practice

  • Teach harmony through rounds; plan a canon at a chosen interval and delay.
  • Use delay and echo as canons at the unison, timed to the beat or the bar.

Contents

Each chapter has a home level. Choose a track to see what to read and watch: Foundations 19 min · Full course 33 min · Research 35 min · Practice 21 min.

  1. 0A king's themeFoundations2 min
  2. 1RoundsFoundations2 min
  3. 2Canon at every intervalFull course4 min
  4. 3Four forms of a lineFoundations2 min
  5. 4Invertible counterpointFoundations2 min
  6. 5Slower, and in riddlesFull course2 min
  7. 6The crab canonFull course2 min
  8. 7A canon that never arrivesFoundations2 min
  9. 8Subject and answerFoundations3 min
  10. 9An exposition, builtPractice3 min
  11. 10StrettoFull course3 min
  12. 11The Art of FugueFoundations2 min
  13. 12Frontier: fugues by machineResearch2 min
  14. Variation 20, recap and problemsAll tracks3 min

Also on this page: Lecture · Key results · Try it · Lab · Problems · Notes and sources · Build the film.

Lecture

The text of each chapter is the film's narration, as it is spoken, so you can read along or revise without the film. The pictures are in the film. A dashed box stands for a number the film computes when it is rendered (hover over it to see what is computed); the README's figures for each chapter, where it lists them, follow the chapter's text.

A king's themeFoundations2 min

On the evening of the seventh of May, 1747, at the palace in Potsdam, King Frederick the Great of Prussia, a keen flautist, had a visitor: Johann Sebastian Bach, sixty-two years old. The king played him a theme, and asked him to improvise a fugue on it. Here it is, with its rhythm simplified: a minor triad climbing, a plunge of a diminished seventh, and then a slow chromatic slide.

The theme seems made to resist being combined with itself: that chromatic slide is hard to set against its own copies. Bach improvised a fugue in three voices on it on the spot. When the king asked for six voices, he chose a theme of his own. Two months later he sent the king a printed answer, the Musical Offering. It holds a fugue in six voices on the king's theme, and a set of canons written as riddles: only one line is printed, and the reader must find how the other voices enter. One canon is played against itself backwards. Another rises a whole tone each time round, and its inscription hopes that the king's glory rises with it.

This part asks one question in many forms: which melodies can be combined with themselves? It starts with rounds, and counts the canons a computer can find at every interval. Then the four forms of a line, forwards, upside down and backwards, and the small group they make. Then lines that can swap places, lines against themselves slowed down, and canons set as riddles. Then the two canons of the Musical Offering, the crab and the endless climb, solved and heard. Then the fugue, built from its parts on the Tune. And at the end, The Art of Fugue, and what machines can do with all this.

1RoundsFoundations2 min

Why does a round work?

The simplest way to combine a melody with itself is a round. One voice starts; when it reaches the end of the second bar, a second voice starts the same tune from the beginning; two bars later, a third. Here is Frère Jacques, in three voices, each an octave below the last so you can follow them.

Why does it work? Cut the tune into its two-bar pieces. With three voices two bars apart, you hear the first piece against the second against the third, then the second against the third against the fourth. So the pieces that overlap at this entry delay must fit together; not every pair need overlap in three voices. The easy way is for every piece to outline the same chord: this simplified Frère Jacques arrangement stays over its home harmony. The earliest surviving well-known English round, Sumer is icumen in, written down in about 1250, combines four round voices with a two-voice repeating pes: the cuckoo sings over a harmony that barely moves.

Can a program find rounds? Take every tune in Part 14's collection, and sing each one against itself in three voices, trying every delay of a whole number of bars. On every strong beat, ask whether all the voices agree, thirds, fifths, sixths and octaves, and keep each tune's best delay. The program was not told which tunes are rounds. Frère Jacques comes , Row, Row, Row Your Boat , and Three Blind Mice , out of . The fourth tune in the top four, Go Tell Aunt Rhody, simply has a harmony that never moves. This ranks compatibility on selected strong beats, not every aspect of successful round writing.

2Canon at every intervalFull course4 min

How rare is a melody that makes a canon?

A round is the simplest case of a canon: a second voice copies the first, entering later. But the copy need not start on the same note. It can enter a second higher, or a fifth lower, at any interval, keeping the shape of the line within the scale. In 1741 Bach published the Goldberg Variations, thirty variations on one bass, and made every third variation a canon: the third at the unison, the sixth at the second, the ninth at the third, and so on up to the twenty-seventh, a canon at the ninth. Is that a feat, or is any interval as easy as any other?

Ask a program. A leader of twelve notes, one a beat, in C major, beginning and ending on C. The follower plays the same line two beats later, a chosen number of scale steps away. From the follower's entry, every beat must be consonant, and no two beats in a row may make parallel fifths or octaves, Part 16's rules. The leader moves by steps and by the usual leaps. Whether the next note is allowed depends only on the leader's last three notes, the two the follower is copying and the one before. So the program never lists the melodies: it counts, for every three-note ending, how many ways there are to reach it, and adds up. Hundreds of millions of melodies are counted in a compact dynamic-programming search.

Here are the counts. Every interval works: there are hundreds of thousands of canons at each. But they are rare. Of about million melodies the leader could sing, about one in makes a canon at the fifth or the octave. The fourth and the seventh are hardest, about one in at the fourth: a fourth is dissonant over the bass, and a seventh copies every consonance onto a dissonance a step away. Bach’s canons also use rhythmic and tonal freedoms absent from this restricted count; these rankings do not measure his compositional difficulty.

Does it matter whether the follower enters above or below? At the octave it makes no difference: the counts are identical, since an octave above and an octave below make the same intervals. At every other interval it does. The ninth below allows only thousand canons against thousand above, and the second below thousand against . The major scale is not symmetric, its steps a pattern of tones and semitones that reads differently upwards and downwards, so a copy above and a copy below are different problems.

Three of the canons the solver found, heard: at the unison, at the second, and at the fifth below. In each, the pink voice copies the gold one two beats later. Not one sampled beat violates this consonance check.

They are correct, and they are not Bach. The rules constrain sampled vertical intervals and parallels; they say nothing about shape, direction or a climax. The solver shows how much room there is. The art is in choosing.

3Four forms of a lineFoundations2 min

What can be done to a melody that keeps it the same melody?

First, a question for your ears. You will hear the Tune's first phrase, and then the same phrase changed. Is the second one upside down, or backwards?

Backwards. It begins on the phrase's last note, G, climbs to A, and falls by a fifth to end where the phrase began. The rhythm is backwards too: the long note is now first. Backwards melodies are surprisingly hard to recognize; upside-down ones, which keep the rhythm, are often easier.

There are four forms. The line itself. Its inversion, every rising interval made to fall by the same number of scale steps: the Tune's leap up a fifth becomes a leap down a fifth. Its retrograde, backwards. And its retrograde inversion, backwards and upside down. Hear all four.

There are two ways to turn a line upside down. Within the scale, every step down becomes a step up of the same number of scale degrees: the Tune's rising fifth C to G becomes a falling fifth C to F, and its rising sixth to A becomes a falling sixth to E. Or exactly, semitone for semitone: then the falling major sixth from C lands on E flat, a note outside the key. Bach often adapts inversion to tonal context; real passages can use chromatic alterations; the twelve-tone composers of Part 29 invert exactly, and have no key to stay in.

The four forms have an arithmetic. Do one and then another, and you always land on one of the four. Each form undoes itself: upside down twice is the right way up. Any two different nonidentity operations make the third: inverting a retrograde gives the retrograde inversion. And the order never matters. Mathematicians call such a set a group, and this one is a standard four-element noncyclic group, Klein's four-group, the symmetries of a rectangle: flip it across, flip it along, or turn it half round. The program checks the table on the Tune itself. With a fixed inversion convention, twelve transpositions give up to forty-eight labeled forms of a twelve-tone row, which Part 29 will need.

4Invertible counterpointFoundations2 min

Can two lines swap places?

A fugue reuses its material in new arrangements, and one of the commonest is to swap two lines, the upper going below. Take two lines, one above the other. Move the upper one down an octave, so that it is now the lower. Every interval between them, counted in scale steps, turns into its complement: a third becomes a sixth, a sixth a third, an octave a unison. But a fifth becomes a fourth, and a fourth over the bass is a dissonance. So a counter-line meant to swap places at the octave must avoid fifths, or treat them like dissonances, passing through them.

Two counter-lines were written below the Tune's first phrase by the solver: line A freely, line B with no fifths against the phrase. Each has now been moved above the phrase. Which avoids the displayed on-beat fourths, A or B?

B. Below the phrase, both lines were clean. Moved above it, line A's fifths have become fourths over the bass, of them on the beat; line B, written without fifths, comes through with . Invertible countersubjects can be planned along these lines, with stylistic treatment of dissonance, so that they could go above or below the subject.

Lines can also be swapped at other distances. At the octave, the fifth is the problem. At the tenth, every consonance stays a consonance, but thirds become octaves, so a pair of lines moving in parallel thirds, the sweetest thing in two voices, turns into forbidden parallel octaves. At the twelfth, fifths become octaves and thirds tenths, but the sixth becomes a seventh. Each kind of invertibility forbids something different, and the treatises of Bach's time taught them as separate crafts.

5Slower, and in riddlesFull course2 min

What else can a canon change?

A canon can also change speed. In augmentation the follower plays every note twice as long; in diminution, half as long. Here the Tune's first phrase is sung twice in the upper voice, while the bass sings it once, twice as slowly.

It nearly works. On of the strong beats the two clash, because the Tune was not designed for it: when the fast voice moves to A, the slow one is still on G. Bach's subjects in The Art of Fugue were designed so that they would fit against their own augmentations and inversions, and he wrote canons of exactly this kind into it.

This idea is old. In fifteenth-century notation, the same written notes could be read in different metres, depending on a sign at the start. So composers wrote mensuration canons: a single line, sung by several voices at once, each reading it at its own speed, the slow voices spreading the tune out under the fast ones. Johannes Ockeghem's Missa prolationum, from late in the fifteenth century, builds a whole Mass from such canons, at different intervals as well as different speeds. One line written, several heard: composition as a puzzle in time.

Bach's canons in the Musical Offering continue this tradition of puzzles. Some puzzle canons leave a following voice to be inferred from the printed material. The clues are a sign where another voice enters, perhaps a clef printed upside down, or a Latin motto. Over one of them Bach wrote: quaerendo invenietis, seek and you shall find. To solve such a riddle, you try every entry point, every interval and selected transformations and rhythmic proportions, and check the proposed solutions against stylistic constraints. That is exactly a search over the possibilities, the kind the canon solver does. Riddle canons have more than one solution surprisingly often, and solvers since Bach's pupils have argued over which he meant.

6The crab canonFull course2 min

Can a melody be its own accompaniment, backwards?

The Musical Offering's crab canon is two voices playing the same line, one forwards and one backwards, at the same time: crabs were thought to walk backwards. So the first note sounds against the last, the second against the second-to-last, and so on. Every pair of notes is heard twice, once near the start and once, the other way round, near the end, and the midpoint is the temporal mirror; the voices need not cross in pitch. That suggests how to find such lines: fill the melody from both ends at once, a pair of notes at a time, checking each pair against the pair before.

Count them, with the canon solver's rules: every pair consonant, no parallel fifths or octaves, beginning and ending on notes of the home chord. For four notes there are ; for twelve, about million, about times more for every two notes added, about five times for each note. That is because each new pair of notes, one at either end, must agree only with itself and with the pair before; the count grows exponentially, for these transition rules; local constraints do not universally imply this growth rate. There are many crab canons under this finite rule set. What is rare is one that makes sense forwards and backwards as a melody, with a shape a listener can follow both ways.

Here is one, found by asking the solver to begin with the Tune's first three different notes, C, G and A. First the line alone; then against itself backwards, an octave lower. Watch the two voices meet in the middle and exchange their notes.

In 1979 Douglas Hofstadter wrote a dialogue in this shape for his book Gödel, Escher, Bach: its dialogue structure mirrors itself in reverse order, spoken by two characters, the Tortoise and Achilles. A crab canon is a palindrome that two voices sing at once.

7A canon that never arrivesFoundations2 min

Can music rise for ever?

The other famous canon of the Musical Offering is the canon through the keys. It is written so that it ends a whole tone higher than it began, ready to start again there. Played six times round, it climbs through six keys and arrives where it began, an octave higher. Bach's inscription: as the modulation rises, so may the glory of the King. Part 4 built a sound that makes the climb endless, the Shepard tone: each note a stack of octaves under a fixed bell of loudness, so that twelve semitones up is the same sound. Play a rising canon in Shepard tones, and it can climb for ever without getting anywhere.

Here is a two-voice canon the solver found, at the fifth below, eight notes long. It is played seven times, each lap a whole tone higher than the last, every note a Shepard tone. On the right, the key of each lap goes round the clock of Part 12; after six laps it is back where it started. Listen to whether the music ever comes home.

The construction is designed to suggest rising laps, though responses vary; this example has no listener study. Yet the seventh lap is the first lap, sample for sample. Part 4 explained why: pitch has two parts, height, and where a note sits within the octave, its chroma. Shepard tones keep the chroma and hide the height, so each step up is heard as up, and the steps add up to nothing. Hofstadter called this a strange loop, a hierarchy that, climbed far enough, returns to its start, and he took Bach's rising canon as his first example.

8Subject and answerFoundations3 min

Why does a fugue answer at the fifth, and why bend the answer?

A fugue is not a form so much as a procedure built from canon. One voice states the subject, the theme, alone. A second voice enters with the answer, typically the subject transposed toward the dominant, with adjustments possible in a tonal answer. Meanwhile the first voice goes on with a counter-line, and if it is kept and reused, it is called the countersubject. Each voice enters in turn, subject, answer, subject, and when all have entered, the exposition is over. After that come episodes, sequences built from fragments, entries in other keys, perhaps a stretto, where entries overlap, and often a held bass note, a pedal, before the end.

Take the Tune's first phrase as a fugue subject, and answer it twice at the fifth. One answer copies it exactly, a fifth higher; the other bends one interval. Which answer stays closer to the home key, A or B?

B. The subject opens with a leap from C up to G, home to dominant. Answer A, the real answer, copies it exactly: G up to D, dominant to the dominant's dominant, which pulls the music toward G major at once. Answer B, the tonal answer, bends the leap: G up to C, a fourth instead of a fifth, dominant back to home, and only then continues a fifth higher. The opening is answered as a mirror, and the home key survives the answer's first notes.

The rule fits in a line of code. In the subject's head, its opening notes, wherever it moves between the tonic and the dominant, swap them: tonic answered by dominant, dominant by tonic, so a fifth becomes a fourth. After the head, move everything up a fifth within the scale. Answering at the fifth is the canon at the fifth of chapter two, with the follower delayed until the leader has finished. And the fifth because the dominant is the nearest key, the first stop on every journey Parts 15 and 18 measured: the answer leaves home only as far as the next room. These are common teaching guidelines; actual real and tonal answers depend on the subject’s complete tonal design.

9An exposition, builtPractice3 min

How does a program write the countersubject?

Now build an exposition on the Tune, in three voices. Bars one and two: the subject, the Tune's first phrase, alone in the top voice. Bars three and four: the tonal answer in the middle voice, and above it the countersubject. The program writes the countersubject by searching for the smoothest line, one note a beat, that is consonant with the answer on every beat, makes no parallels, and avoids fifths, so that it could later go below. The search is Part 17's Viterbi again: for each candidate state it keeps the cheapest path into it, with the transition information this cost requires. Bars five and six: the subject enters in the bass, the countersubject moves down to the middle voice above it, and the top voice gets a free line, found the same way against both. Moved down, one note of the countersubject clashed with the subject, and the program altered it by a step, as composers did.

Here is the exposition. The gold voice begins, the pink voice answers, and the blue bass enters last.

After the exposition comes an episode, a passage without the whole subject that travels somewhere new. The usual recipe is Part 18's sequence: take a short fragment, here the first four notes of the free voice, G, A, G, B, and repeat it a step lower in each bar, while the other voice sings the fragment upside down, sequenced with it. The program chose how far below to put the lower voice so that no beat clashes.

Sixteen beats, clashes, and the music has walked down a fourth, ready for the subject to return in a new key. Episodes are where fugues breathe, and where Bach's are most inventive.

Check it: on all beats where two or three voices sound, are dissonant and there are parallels. It passes these limited checks, and it is deliberately plain: one note a beat, no suspensions, no rhythm of its own. A real countersubject contrasts with its subject: it moves in quick notes where the subject holds, and holds where the subject moves, so that the ear can follow two lines. As with the canons, the rules make an exposition possible; they do not make it good.

10StrettoFull course3 min

How close can the entries come?

Late in a fugue, the entries often crowd together: the next voice comes in before the last has finished. This is stretto, from the Italian for tightening. Which strettos does a subject allow? The program tries every delay and every common interval, and keeps the ones in which the two entries never clash on a beat and never move in parallel fifths or octaves. For the Tune's first phrase there are . The closest: the second voice beats behind, . The entries that come late are easy, since they hardly overlap; the close ones are the prize, and composers designed subjects to allow them.

Here it is, and then with a third entry the program found as well: the bass, beats after the first voice, . Three entries of the phrase within four beats, with nothing clashing.

A stretto can also bring the second voice in upside down. Give the search the phrase's inversion as the follower: it finds strettos, against with the phrase as it is, and of them only two beats behind, where the plain phrase allowed . A line and its mirror image fill each other's gaps: when one rises, the other falls, and they meet less often on the same wrong note. Bach built the stretto fugues of The Art of Fugue, its fifth to seventh pieces, on exactly this: the subject against its own inversion, and then against it slowed down and sped up as well.

How special is that? Run the same search on the opening phrase of every tune in Part 14's collection, allowing the second voice to enter anywhere up to the phrase's midpoint. of the phrases allow at least one stretto. Folk tunes repeat notes and outline a chord, which makes them easy to overlap. A chromatic subject like the king's is the opposite. With its rhythm simplified, the program finds no stretto for the king's theme until the second voice waits of its beats, when the two hardly overlap: its slide clashes with itself almost everywhere, which is part of why the king's challenge was hard. Bach’s complete fugue subjects were not counted in this offline build, since no fugue scores were available to this series offline; the problem set asks you to do it.

11The Art of FugueFoundations2 min

What did Bach do with one subject?

In his last decade Bach worked on a collection that does to one subject everything this part has done. The Art of Fugue takes a plain subject in D minor, D, A, F, D, C sharp, D, E, F, and builds about twenty pieces on it. Simple fugues first, then fugues in which the subject meets its own inversion. Stretto fugues, with the subject against itself slowed down and sped up. Double and triple fugues, with new subjects combined with the first; mirror fugues that can be played entirely upside down, every voice inverted; and four canons. It is a catalogue of everything in this part, on a single line of eight notes.

The last fugue of the collection introduces a third subject that spells a name. In German note names, B means B flat and H means B natural, so B, A, C, H is a melody: B flat, A, C, B natural.

Four notes spanning a minor third: a chromatic cell, the king's slide in miniature, and a signature that composers from Schumann and Liszt to Schoenberg and Webern have borrowed.

The story attached to it is famous. The final fugue breaks off in the middle of a bar, soon after B, A, C, H has been combined with the other subjects. In the manuscript, his son Carl Philipp Emanuel wrote that the composer died over this fugue. Scholars now doubt it: the handwriting is earlier, and a lost continuation and an unfinished plan are competing possibilities; the precise reason remains uncertain. One influential reconstruction proposes to bring the main subject in as a fourth, making a quadruple fugue, and the four subjects do fit together, as later musicians who completed it have shown. Bach died in July 1750, and the collection was printed the next year, unfinished.

12Frontier: fugues by machineResearch2 min

Can a machine analyse, or write, a fugue?

The tools of this part run both ways. To analyse a fugue, a program must find every entry of the subject, real or tonal, sometimes with altered notes or a changed ending. Then the countersubjects, the episodes, the cadences and pedals. In 2015 a team at Lille, Mathieu Giraud, Richard Groult, Florence Levé and others, published an analysis of the fugues of the Well-Tempered Clavier by program, compared with the analyses of human experts. The hard part is not matching notes; it is deciding which near-copies count as entries, the very question on which human analysts disagree.

And to write one. Rules and search, as in this part, can exhaust the specified finite search space, without guaranteeing full stylistic correctness or musical quality. In the 1980s and 1990s, David Cope's program EMI wrote music in the style of Bach and others by recombining fragments of their own works. More recently, neural networks trained on Bach's chorales learned to fill in missing voices, and in 2019 a web page let millions of people write a melody and hear it harmonized in his style. Fugue is harder than chorale: it needs a plan over minutes, entries placed in keys, tension built and released. Models that write convincing local counterpoint still struggle with that long-range shape, which is Part 21's subject: form.

And the old question that canons raise. When a subject is turned upside down or backwards, does the listener hear the same theme? Experiments suggest that recognition of inversions and retrogrades depends on task, familiarity, contour and training; retrogrades are often difficult, as chapter three's question may have shown you. So how much of a fugue's structure is for the ear, and how much for the eye of a reader of the score? Designing an experiment that separates the two is this part's research problem.

Variation 20, recap and problemsAll tracks3 min

Every part ends by doing something to the Tune with what it has built. This part combined melodies with themselves. So the Tune is heard three ways. First the whole Tune as a canon: the stretto search, run on all of it, found that a second voice can follow two beats behind and a fourth below, almost cleanly, all the way through. Then the crab canon on its first three notes. And last, the fugue exposition of chapter nine.

Row twenty of the ledger. seconds. The measurement: the whole Tune against itself two beats later, a fourth below: dissonant beats in . A nursery tune, it turns out, was nearly a canon all along.

What did we find? A round needs compatible overlaps at its chosen entry delay, and a program that knew nothing of rounds found the famous ones. Canons exist at every interval, counted exactly, rare but plentiful, with the fourth and seventh hardest under this chosen rule set. The four forms of a line make Klein's four-group. Lines can swap places, if they avoid what the swap would spoil. Crab canons are common, good ones rare, and a canon in Shepard tones can climb for ever. And a fugue's exposition can be built by rule, subject, tonal answer, countersubject and stretto, correctly and plainly.

Five problems. One to compute, one to prove, one for your ears, one to build, and a research problem, marked with a star. Solutions are in this part's notes. Pause here.

Where does this come back? In form, where a fugue's shape over minutes is the question. In the Renaissance, whose polyphony is built from imitation, and the Baroque, the fugue's home. In twelve-tone music, where the four forms meet twelve transpositions. In Steve Reich's phasing and in tiling canons, and in a tempo canon no human could play.

And in practice. Choirs and classrooms teach harmony through rounds, since every singer learns every part. Keyboard players learn fugues a voice at a time. Songwriters let a backing line answer the melody a bar later. And a producer's delay effect is a canon at the unison, and beat-synchronized delay is one useful production choice.

The books and papers this part follows. The full list, with notes, is in the README.

This part combined lines a few bars at a time. But a fugue, a sonata or a song lasts minutes, and a listener follows it. What holds three minutes of music together, and can a program find the shape from the sound alone? Next time. Part 21: Form.

Where it goes next. Form in Part 21; Renaissance imitation in Part 24; the Baroque fugue in Part 25; twelve-tone rows in Part 29; phasing and tiling canons in Parts 30 and 33; tempo canons in Part 53.

Key results

The part's results in one place, for revision.

Rounds found\(\displaystyle \text{Frère }\allowbreak \text{Jacques, }\allowbreak \text{Row }\allowbreak \text{Row, }\allowbreak \text{Three }\allowbreak \text{Blind }\allowbreak \text{Mice: }\allowbreak \text{places } 1, 3, 4 \text{ of } 54\)
Canons at every interval\(\displaystyle n = 12: \ 1{,}378{,}924 \text{ at }\allowbreak \text{the }\allowbreak \text{fifth}, \ 479{,}936 \text{ at }\allowbreak \text{the }\allowbreak \text{fourth, }\allowbreak \text{of } 738{,}663{,}910\)
The four forms\(\displaystyle \{P, I, R, RI\} \cong \mathbb{Z}_2 \times \mathbb{Z}_2\)
Crab canons\(\displaystyle N(12) = 193{,}459{,}554 \approx 25 \, N(10)\)
Inversion at the octave\(\displaystyle s \mapsto 7 - s: \ \text{fifth} \to \text{fourth}, \ \text{third} \leftrightarrow \text{sixth}\)

Try it

Lab 20 · Canons, solved

Count the canons a melody can make at every interval, find one, count crab canons, check the four forms' table, see what inversion at the octave does, answer a subject tonally, list a subject's strettos, and name the forms of a phrase by ear.

Figure produced by Lab 20: Canons, solved
Produced by the lab below, seed 0, in 0.4 s.
python -m videos.music.labs 20 needs numpy, scipy, matplotlib · download lab20.py · source on GitHub
canons of 12 notes, follower 2 beats later and above                 unison 1,207,968,  second 826,314,  third 1,120,593,  fourth 479,936,  fifth 1,378,924,  sixth 1,291,326,  seventh 602,696,  octave 1,371,456,  ninth 884,555
a canon at the fifth                                                 72 71 72 65 64 65 67 65 62 65 72 60   (dissonant beats 0, parallels 0)
crab canons of 4, 6, 8, 10 notes                                     468,  11,738,  299,320,  7,604,514
one crab canon                                                       67 65 69 72 74 62 65 77 72 79   (against its retrograde: 0 dissonant beats)
the four forms' table closes on a real line                          True
inversion at the octave: unison, third, fifth, sixth, octave become  octave, sixth, fourth, third, unison
the subject                                                          67 72 71 72 74 72 71 69 67
real answer / tonal answer                                           74 79 78 79 81 79 78 76 74  /  72 79 78 79 81 79 78 76 74
its strettos (delay in beats, interval in semitones)                 (5, +0),  (5, +12),  (7, -12),  (7, +7)
the best rounds in Part 14's tunes                                   Frère Jacques (every 8 beats);  Go Tell Aunt Rhody (every 16 beats);  Row, Row, Row Your Boat (every 4 beats);  Three Blind Mice (every 12 beats);  London Bridge (every 14 beats)
ear problem, each phrase then its form (listen first)                inverted;  backwards;  backwards;  the phrase;  the phrase;  the phrase;  both;  inverted

Canons exist at every interval but are rare among melodies, hardest at the fourth and seventh; crab canons grow about twenty-five-fold for every two notes; the four forms make a group of four; a tonal answer swaps tonic and dominant in the head; and a subject's strettos can be listed by trying every delay and interval.
The code (109 lines; it asserts its own result)
"""Lab 20: canons counted and found, crab canons from both ends, the four forms of a line, invertible counterpoint,
tonal answers, strettos of a subject of your own, and the forms of a phrase by ear."""

import numpy as np

from videos.coursekit import labs
from explainer.music.monochord import Clip, concat
from explainer.music.monochord import canon as K
from explainer.music.monochord import chords as CH
from explainer.music.monochord import melody as M
from explainer.music.monochord.partkit import organ_tone

TITLE = "Canons, solved"
GOAL = ("Count the canons a melody can make at every interval, find one, count crab canons, check the four forms' "
        "table, see what inversion at the octave does, answer a subject tonally, list a subject's strettos, and name "
        "the forms of a phrase by ear.")
TASKS = [
    "Change N and DELAY. Which interval is hardest now? Does the fourth stay the hardest?",
    "Write a SUBJECT of your own (midi pitches and beats) and list its strettos. Which subjects allow close strettos?",
    "Set STEPS to 7 (a canon at the octave) and listen to the canon the solver finds. Is it a melody you would sing?",
]
N, DELAY, STEPS = 12, 2, 4                               # canon length, follower delay (beats), interval (scale steps)
SUBJECT = ([67, 72, 71, 72, 74, 72, 71, 69, 67], [1, 1, 0.5, 0.5, 1, 1, 1, 1, 2])   # G C B C D C B A G, in C
SR = 48_000


def tone(midi, seconds):
    return organ_tone(CH.hz(midi), seconds, partials=6, rolloff=0.7, decay=1.4)


def render(lines, beat=0.32):
    T = max(K.end(ln) for ln in lines)
    y = np.zeros(int((T * beat + 1.0) * SR))
    for ln in lines:
        for p, a, d in ln:
            t = tone(p, d * beat * 1.1)
            i = int(a * beat * SR)
            y[i:i + len(t)] += t[: len(y) - i]
    return Clip(y, SR).fade(0.01, 0.2).at_level(-20.0)


def run(seed=0):
    rng = np.random.default_rng(seed)
    lab = labs.Lab()

    # 1. canons at every interval
    counts = {K.STEP_NAMES[s]: K.count_canons(N, DELAY, s) for s in range(0, 9)}
    lab.row(f"canons of {N} notes, follower {DELAY} beats later and above", ",  ".join(f"{k} {v:,}" for k, v in counts.items()))
    mel = K.sample_canon(N, DELAY, STEPS, rng=rng)
    lead, fol = K.line(mel), K.shift(K.line([K.diatonic(p, STEPS) for p in mel]), DELAY)
    f = K.faults([lead, fol], start=DELAY, stop=N)
    assert f["dissonant"] == 0 and f["parallels"] == 0, "the solver's canon must not clash"
    lab.row(f"a canon at the {K.STEP_NAMES[abs(STEPS)]}", " ".join(str(p) for p in mel) + f"   (dissonant beats {f['dissonant']}, parallels {f['parallels']})")

    # 2. crab canons
    crabs = {n: K.count_crabs(n) for n in (4, 6, 8, 10)}
    lab.row("crab canons of 4, 6, 8, 10 notes", ",  ".join(f"{v:,}" for v in crabs.values()))
    crab = K.sample_crab(10, rng=rng)
    lab.row("one crab canon", " ".join(str(p) for p in crab) + f"   (against its retrograde: {K.crab_ok(crab)['dissonant']} dissonant beats)")

    # 3. the four forms, and inversion at the octave
    assert K.check_table_on([60, 64, 67, 65, 62, 71])
    lab.row("the four forms' table closes on a real line", "True")
    lab.row("inversion at the octave: unison, third, fifth, sixth, octave become",
            ", ".join(K.STEP_NAMES[r["becomes"]] if r["becomes"] < 9 else str(r["becomes"]) for s, r in K.invertible(7).items() if s in (0, 2, 4, 5, 7)))

    # 4. answers and strettos of SUBJECT
    subj = K.line(*SUBJECT)
    lab.row("the subject", " ".join(str(p) for p, _, _ in subj))
    lab.row("real answer / tonal answer", " ".join(str(p) for p, _, _ in K.real_answer(subj)) + "  /  " + " ".join(str(p) for p, _, _ in K.tonal_answer(subj)))
    st = K.strettos(subj)
    lab.row("its strettos (delay in beats, interval in semitones)", ",  ".join(f"({x['delay']:g}, {x['interval']:+d})" for x in st) or "none")

    # 5. rounds in the corpus
    rc = K.round_census(M.corpus())
    lab.row("the best rounds in Part 14's tunes", ";  ".join(f"{r['name']} (every {r['delay']:g} beats)" for r in rc[:5]))

    # 6. Problem 3, for the ear: eight forms of three short phrases
    phrases = [K.line([72, 72, 79, 79, 81, 81, 79], [1, 1, 1, 1, 1, 1, 2]), K.line([64, 65, 67, 72, 71], [1, 1, 1, 2, 1]),
               K.line([67, 64, 65, 62, 60], [0.5, 0.5, 1, 1, 3])]
    answers, clips = [], []
    for _ in range(8):
        ph = phrases[int(rng.integers(0, 3))]
        form = K.FORMS[int(rng.integers(0, 4))]
        ax = K.degree_of(ph[0][0])[0]
        x = {"P": ph, "I": K.diatonic_invert(ph, ax), "R": K.retrograde(ph), "RI": K.retrograde(K.diatonic_invert(ph, ax))}[form]
        clips.append(render([ph]))
        clips.append(render([x]))
        answers.append({"P": "the phrase", "I": "inverted", "R": "backwards", "RI": "both"}[form])
    lab.audio = concat(clips, gap=0.8)
    lab.row("ear problem, each phrase then its form (listen first)", ";  ".join(answers))

    fig, (a, b) = labs.figure(2)
    a.bar(range(9), [counts[k] / 1000 for k in counts], color=[labs.GOLD if k not in ("fourth", "seventh") else "#d66" for k in counts])
    a.set_xticks(range(9))
    a.set_xticklabels(list(counts), rotation=40)
    a.set_ylabel("thousands")
    a.set_title(f"Canons of {N} notes at each interval")
    ns = list(crabs)
    b.semilogy(ns, [crabs[n] for n in ns], "o-", color=labs.GOLD)
    b.set_xlabel("notes")
    b.set_ylabel("crab canons")
    b.set_title("Crab canons, counted from both ends")
    lab.fig = fig
    lab.note = ("Canons exist at every interval but are rare among melodies, hardest at the fourth and seventh; crab "
                "canons grow about twenty-five-fold for every two notes; the four forms make a group of four; a tonal "
                "answer swaps tonic and dominant in the head; and a subject's strettos can be listed by trying every "
                "delay and interval.")
    return lab

Now change it

  1. Change N and DELAY. Which interval is hardest now? Does the fourth stay the hardest?
  2. Write a SUBJECT of your own (midi pitches and beats) and list its strettos. Which subjects allow close strettos?
  3. Set STEPS to 7 (a canon at the octave) and listen to the canon the solver finds. Is it a melody you would sing?

Problems, with solutions

Try each problem before opening its solution.

  1. Compute. Write the tonal answer to a subject beginning G C B C D (in C major), and say which notes change and why.

    Solution

    The head moves between the dominant (G) and the tonic (C), so those are swapped: G is answered by C and C by G, the rising fourth G–C becoming the rising fifth C–G. After the head, the rest goes up a fifth in the scale: B → F♯ in G major, C → G, D → A. The answer is C G F♯ G A. A real answer, D G F♯ G A, would begin on D and assert G major at once; the tonal answer begins on C, inside the home key.

  2. Prove. Prove that a line and its retrograde inversion, sounded together, make the same intervals at times t and T − t, and say what that implies for a mirror crab canon.

    Solution

    Let the line be p(t) and its retrograde inversion q(t) = 2a − p(T − t). At time t the interval is p(t) − q(t) = p(t) + p(T − t) − 2a; at time T − t it is p(T − t) + p(t) − 2a, the same. So such a canon is palindromic in its intervals: whatever is consonant in the first half is consonant in the second, and only half the piece needs checking, as in the crab solver, which fills both ends at once.

  3. Ear. The lab plays eight forms of three short phrases. For each, say: the phrase, inverted, backwards, or both?

    Solution

    The lab prints the answers. Listen for the rhythm first: a backwards form reverses it (long notes move to the other end), an inversion keeps it. Then the direction of the first leap tells inversion from the original.

  4. Build. Give the stretto finder a fugue subject of your choice in score, find all its strettos, and compare them with those the composer used.

    Where to look. Encode the subject as (midi, onset, duration) in beats and call canon.strettos, adding the inverted form (diatonic_invert) as a follower. Many of Bach's subjects admit strettos he did not use, and some he used break the simple rules (a dissonance on a beat, resolved as a suspension); the finder needs a rule for suspensions before its list matches a composer's.

  5. ★ Does the ear follow a fugue? Design an experiment that tells whether listeners follow a fugue's entries by ear, or only on paper.

    Where the frontier is. One design: listeners press a key whenever they hear the subject begin, in fugues where the entries are known; measure hits, misses and false alarms against training and against the entry's voice (inner voices are hardest) and form (Dowling found inversions and retrogrades hard to recognize). Comparing real fugues with versions whose entries have been moved tests whether the structure is heard as structure.

Notes and sources

Sources

  • J. S. Bach, Musikalisches Opfer (1747) and Die Kunst der Fuge (1751); C. Wolff, Johann Sebastian Bach: The Learned Musician (2000), for the visit to Potsdam and the history of The Art of Fugue.
  • A. Mann, The Study of Fugue (1958); R. Gauldin, A Practical Approach to Eighteenth-Century Counterpoint (1988).
  • D. R. Hofstadter, Gödel, Escher, Bach (1979): the crab canon and the endlessly rising canon.
  • R. N. Shepard, "Circularity in judgments of relative pitch", JASA 36 (1964); Part 4 for Shepard tones.
  • W. J. Dowling, "Recognition of melodic transformations: inversion, retrograde, and retrograde inversion", Perception & Psychophysics 12 (1972).
  • M. Giraud, R. Groult, E. Leguy and F. Levé, "Computational fugue analysis", Computer Music Journal 39 (2015).
  • D. Cope, Experiments in Musical Intelligence (1996); C.-Z. A. Huang and others, "Counterpoint by convolution", ISMIR (2017).
  • Part 14 for the tunes; Part 16 for the rules of two voices; Part 17 for Viterbi search.
About this partfrom its README

Part 20 of a sixty-eight-part course in music (see the series plan and the syllabus), the fifth part of Act III. Parts 16 to 19 set lines against other lines; this part sets a line against itself. It starts in Potsdam in 1747 with the king's theme and the Musical Offering, and asks which melodies can be combined with themselves: rounds, canons at every interval, the four forms of a line and the group they make, invertible counterpoint, augmentation and riddle canons, the crab canon, the endlessly rising canon, and the fugue's subject, answer, countersubject and stretto, built on the Tune; then The Art of Fugue and fugues by machine. The canon tools are Monochord's (explainer/music/monochord/canon.py); the tunes are Part 14's corpus (explainer/music/monochord/tunes.py); everything heard is computed in compute.py and played on Part 18's plucked string over Part 7's soundboard, the endless canon in Part 4's Shepard tones. Published findings are the ones listed under Sources.

  • A king's theme. Potsdam, 7 May 1747; the royal theme heard (rhythm simplified); the Musical Offering; the plan.
  • 1. Rounds. Frère Jacques in three voices, heard; why a round works (compatible overlapping two-bar pieces; Sumer is icumen in); every one of Part 14's 54 tunes sung against itself in three voices at its best delay, judged on the strong beats: Frère Jacques, Row, Row, Row Your Boat and Three Blind Mice, the three known rounds, rank 1st, 3rd and 4th (the 2nd, Go Tell Aunt Rhody, has a harmony that never moves).
  • 2. Canon at every interval. The Goldberg canons (1741), unison to ninth; a solver that counts canons exactly by dynamic programming over the leader's last three notes: 12 notes, follower 2 beats later, from 1,378,924 at the fifth and 1,371,456 at the octave down to 479,936 at the fourth, of 738,663,910 melodies (1 in 536 at the fifth, 1 in 1,539 at the fourth); below the leader the counts change at every interval but the octave (the ninth below 552,984 against 884,555 above); three solver canons heard (unison, second, fifth below).
  • 3. Four forms of a line. An ear question (the phrase, then backwards or upside down?); prime, inversion, retrograde, retrograde inversion, heard; inversion within the scale (C C F F E E F) against exact inversion (C C F F E♭ E♭ F); their table, checked on the Tune: Klein's four-group.
  • 4. Invertible counterpoint. At the octave every interval of s steps becomes 7 − s: fifths become fourths; an ear question (two counter-lines moved above the phrase: the one written freely has 2 dissonant beats, the one without fifths 0); at the tenth thirds become octaves, at the twelfth sixths become sevenths.
  • 5. Slower, and in riddles. The phrase against itself in augmentation, heard (3 of 8 strong beats clash: the Tune was not designed for it); mensuration canons and Ockeghem's Missa prolationum; puzzle canons and quaerendo invenietis.
  • 6. The crab canon. A line against its own retrograde; filled from both ends at once; counted exactly: 468 of 4 notes, 11,738 of 6, 299,320 of 8, 7,604,514 of 10, 193,459,554 of 12 (about 25 times more for every two notes); one built on the Tune's C, G, A, heard; Hofstadter's crab-canon dialogue (1979).
  • 7. A canon that never arrives. The Canon per tonos; a solver canon played seven times, a tone higher each lap, in Shepard tones (the seventh lap is the first, sample for sample); pitch height and chroma (Part 4); strange loops.
  • 8. Subject and answer. The fugue's parts; an ear question (real or tonal answer: which stays closer to home?): G G D D E E D against G G C C E E D; the tonal answer as a rule.
  • 9. An exposition, built. Subject, tonal answer with a countersubject found by Viterbi search (no fifths), the subject in the bass with the countersubject above it (one note altered) and a free voice; heard; 16 beats of two or three voices: 0 dissonant, 0 parallels; an episode, a four-note fragment sequenced down a step a bar against its inversion, heard (0 clashes in 16 beats).
  • 10. Stretto. Every delay and interval at which the phrase can enter against itself: 11, the closest 2 beats behind a fourth below, and a third entry in the bass 4 beats in, an octave and a fifth below, heard; by inversion 15, 6 of them two beats behind (the stretto fugues of The Art of Fugue); 41 of the 54 tunes' opening phrases allow a stretto by their midpoint; the king's theme (rhythm simplified) none until its second entry waits 23 of its 26 beats.
  • 11. The Art of Fugue. One subject, about twenty pieces; B–A–C–H heard; the unfinished final fugue and what scholars now think of C. P. E. Bach's note.
  • 12. Frontier: fugues by machine. Computational fugue analysis (Giraud, Groult, Leguy and Levé 2015); EMI; networks trained on chorales and the 2019 doodle; recognizing transformed melodies (Dowling 1972). ★ research problem: does the ear follow a fugue's entries?
  • Variation 20, recap and problems. The whole Tune as a canon at the fourth below, two beats behind (2 dissonant beats in 46); a crab canon on its first notes; the three-voice exposition; the ledger; what we found; five problems; where it comes back; in practice; references; Part 21.
What is computed and built

python -m videos.music.music20.compute (about a minute) fills .cache/music20/.

Item What it computes Checked against
hook the royal theme (rhythm simplified) —
rounds Frère Jacques in three voices; every tune ranked as a round the known rounds
canons canons counted at nine intervals, above and below; three sampled brute force on short canons (tests)
forms the four forms of the phrase; their table the table acting on the phrase
invertible two counter-lines and their inversions at the octave; the interval maps —
augment the phrase against its augmentation —
crab crab canons counted; one sampled from the Tune's head brute force on short crabs (tests)
rising a canon a tone higher each lap, in Shepard tones lap 7 = lap 1
answers real and tonal answers —
exposition a three-voice exposition no dissonant beat, no parallels
episode a fragment sequenced against its inversion no dissonant beat, no parallels
stretto the phrase's strettos, as it is and inverted; the corpus; the royal theme —
bach B–A–C–H —
tune Variation 20 —

Monochord's canon tools are held in tests/music/test_canon.py; this part's claims and clips in tests/music/test_music20.py.

Sounds. A string plucked near its end, as a harpsichord's quill plucks it, through Part 7's soundboard (physical model), in twelve-tone equal temperament; the endless canon in Shepard tones (synthesized). There are no recordings.

What the models are, and are not. The judge of harmony asks only that every pair of voices sounding on a beat make a third, fifth, sixth, unison or octave (a fourth allowed above the lowest voice), and that no two voices move in parallel fifths or octaves; it hears no dissonance between beats and knows nothing of shape, so passing notes in real music would count as faults if they fell on beats. The canon counts are for one note a beat in C major within C4 to G5, starting and ending on C, with no repeated notes and leaps of at most a fifth or an octave; other choices can change both the numbers and their order. The rounds are judged at each tune's best delay, a whole number of bars of two beats, on strong beats only, with three voices in unison. The two Bach subjects (the royal theme and the head of The Art of Fugue) are written out for the series with their rhythm simplified; no score files were available offline, so the stretto search was not run on Bach's fugues, and the film says so. The exposition is one note a beat in its counter-lines; a real countersubject would have its own rhythm.

Notes

The round test checks the overlaps produced by a chosen delay; three voices do not require every pair of sections to sound together. The exact canon counts and interval ranking apply only to the stated pitch range, rhythm and rules. They are not measures of Bach’s difficulty or complete historical style. The sampled harmony checker cannot establish that a passage is universally consonant or artistically successful.

The four-form table uses a fixed axis, or identifies sequences up to transposition when the axis follows the first note. Forty-eight row labels need not mean forty-eight distinct sequences for a symmetric row. Real and tonal answers require contextual musical judgment beyond this teaching heuristic. Bach’s tonal inversions can include chromatic adjustments. The cause of the unfinished final fugue and its intended continuation remain uncertain.

Companion material in this repository

The syllabus's plan for this partfrom SYLLABUS.md, the plan of record
  1. Hook: Potsdam, the royal theme heard, the Musical Offering; the plan.
  2. Rounds: Frère Jacques in three voices, heard; why rounds work; every tune of the corpus ranked as a round.
  3. Canon at every interval: the Goldberg canons; a solver that counts canons exactly; three heard.
  4. Four forms of a line: an ear question (backwards or upside down?); the four forms heard; Klein's four-group.
  5. Invertible counterpoint: an ear question (which counter-line survives inversion?); the octave, tenth and twelfth.
  6. Slower, and in riddles: augmentation heard; mensuration canons; puzzle canons.
  7. The crab canon: counted from both ends; one on the Tune's head, heard; Hofstadter.
  8. A canon that never arrives: the Canon per tonos in Shepard tones; strange loops.
  9. Subject and answer: the fugue's parts; an ear question (real or tonal answer?); the tonal answer as a rule.
  10. An exposition, built: a countersubject by Viterbi search; three voices heard.
  11. Stretto: every stretto of the phrase; two and three entries heard; the corpus and the king's theme.
  12. The Art of Fugue: one subject; B-A-C-H heard; the unfinished fugue.
  13. Frontier: computational fugue analysis; generation; recognizing transformed melodies.
  14. Variation 20: the Tune as a canon, a crab canon and an exposition. Outro: problems, payoffs.

Covers: rounds; canon at every interval; invertible counterpoint; inversion, retrograde, augmentation and the group they form; mensuration and puzzle canons; the crab and the endlessly rising canon; the fugue: subject, real and tonal answers, countersubject, episode, stretto, pedal; The Art of Fugue. Built and computed: monochord/canon.py: line transformations and the four forms' table; a judge of lines sounding together; rounds ranked over the corpus; canons counted exactly at every interval and sampled; crab canons counted from both ends and sampled; invertible-counterpoint maps; real and tonal answers; a Viterbi free voice for countersubjects; a stretto finder; the rising canon rendered with Shepard tones. No fugue scores were available offline, so the stretto search runs on the Tune, the corpus and the royal theme (rhythm simplified), not on the Well-Tempered Clavier, and the film says so. Variation 20: the whole Tune as a canon at the fourth below, a crab canon on its head, and a three-voice exposition. Frontier: automatic fugue analysis and generation. Reading: Mann, The Study of Fugue; Gauldin; Hofstadter, Gödel, Escher, Bach.

Build the film

python -m videos.music.music20.compute        # the part's numbers, into .cache/music20
python tools/build.py music20                  # render and assemble the film
EXPLAINER_TTS=silent python tools/qa_scene.py music20 Hook   # one chapter, silent, with a contact sheet

Scenes: videos/music/music20. Setup: see the course page. Source of these notes: the README and the scenes' narration.

Build it
python -m videos.music.music20.compute                          # numbers and sounds (about a minute)
EXPLAINER_TTS=silent python tools/build.py music20 -q l --fps 15   # a silent-narration preview, with the sounds
python tools/qa_sound.py music20 --sync                         # the sound gates
python tools/dead_air.py renders/music20_480p.mp4 --sound music20  # no empty screen; no sound over a still one
python tools/lecture_length.py music20                          # 30 to 60 minutes, listening included
python tools/build.py music20                                   # 1080p30, narrated
python -m pytest -q tests/music                                 # Monochord against its references; this part's claims and clips
python -m videos.music.labs 20                                  # the lab (writes a figure and a short WAV)