Melody lab

A melody is a line of notes heard as one shape, and much of its effect comes from expectation. A listener who has grown up on a repertoire half-knows which note comes next, and feels it when the melody agrees or departs. Draw a melody on the grid, read its contour and its interval profile, and then compare it with what a small corpus of German folksongs would have predicted at every step.

Melody grid
Presets:

Each column is an eighth note (thin lines mark beats, thick lines bars) and each row a note of the chosen scale; switch to chromatic to see all twelve. Click a cell to place a note and click it again to remove it. Clicking the cell right after a note of the same pitch gives a repeated note, and clicking that cell once more turns the repeat into a held note, which is how the chapter's scale ends on a whole note. The presets are written in C and follow the key selector.

The melody as drawn

Contour is pitch against time, the shape listeners remember best from a single hearing. Its name comes from a simple rule: a range of two semitones or less is flat, and three or more changes of direction make a wave; otherwise the notes are split into three parts in order, and if the middle part averages at least a semitone above both ends the shape is an arch, if the last part is at least a semitone above the first it is ascending, below it descending, and anything else is a wave. The interval profile counts the distance from each note to the next in semitones, upward positive and downward negative; a held note counts as one note. Steps are intervals of two semitones or less, repeats included, as in the chapter's count of the corpus. The grey outline is the same profile for the corpus described below.

Expectation from a corpus

Guess the next note:

The app draws a short phrase from the table, plays it, and asks which note comes next. Ten rounds.

Things to try: draw a melody that is all leaps and watch the surprise climb, then smooth it into steps and watch it fall. Make a melody that avoids the tonic, or ends on the note just above it, and feel the lack of closure; then let the last note land on the tonic and hold it. Place any note and look at the bars: the corpus most often predicts a repeat or a step, and after the leading note it predicts the tonic strongly. Play the game in another key and notice that the predictions follow the tonic, because the model, like a listener, hears relative pitch.