THE TEMPERLEY-SLEATOR HARMONIC ANALYZER We have written a program for analyzing music harmonically. The program begins with a piece represented as pitches; it divides the piece into segments, and labels each one with a chord. The program implements a procedure for harmonic analysis developed by David Temperley; the program itself was conceived and written by Daniel Sleator. THE THEORY BEHIND THE PROGRAM. The program has two stages; the "tonal-pitch-class" stage and the harmonic stage. The tonal-pitch-class stage gives each note in the piece its appropriate label or spelling (i.e., Ab versus G#): this means mapping each note on to what we call the "line of fifths" (like the circle of fifths, except a line extending indefinitely in either direction). Its main criterion here is that it tries to label notes so that they are close together on the "line of fifths". The harmonic stage divides the piece into segments and labels them with roots. The program's criteria at this stage are several "preference rules". It tries to find an analysis of the piece such that a) the pitches in each segment are compatible with the chosen root; b) roots of nearby segments are close together on the line of fifths; c) chord-changes occur on metrically strong beats; and d) any ornamental dissonances (or non-chord-tones) are "good" ornamental dissonances, in that they are closely followed by another note a step away. The program finds the optimal analysis of the piece given these constraints. More details about the algorithm can be found in David Temperley's dissertation, "The Perception of Harmony and Tonality: An Algorithmic Approach" (unpublished Ph.D dissertation, Columbia University, 1996). Temperley has also written a paper about the algorithm and the implementation which will be published soon. COMPILING THE PROGRAM. If you've gotten this far you should have a directory called "harmonic-analysis" that contains: README analyze1.0/ samples/ utilities/ (You're looking at this README file.) To compile the program, go to the analyze1.0 directory, and type "make". MAKING ".notes" FILES. To run "analyze", you must have an input file of the right format, representing the piece you want to have analyzed. (These files end in the ".notes" suffix.) This consists of a specification of the metrical structure, followed by a series of lines indicating the notes of the piece (the pitch, on-time and off-time of each note), one note per line. Comment lines may be included in the files; they should be preceded by "%". Here is a sample input file: ------ % This is a sample note file BaseUnit 250 BeatLevel 1 2 0 BeatLevel 2 2 1 BeatLevel 3 3 0 Note 0 250 60 Note 250 500 64 Note 500 1000 67 Note 0 1000 48 ------ First we will explain the encoding of the metrical structure. You must first figure out what the "BaseUnit" of the piece is: the smallest rhythmic unit used, so that all rhythmic values in the piece can be expressed as multiples of that unit. So, for example, if your piece contains sixteenth-notes and no thirty-seconds, then the sixteenth-note is the BaseUnit. (If your piece contains, say, both eighths and triplet eighths, then you must use triplet sixteenth as the BaseUnit, since this is the largest unit of which both eighths and triple eighths are multiples.) The "BaseUnit" line expresses the duration of this unit in milliseconds. The "BeatLevel" lines express a series of levels of beats above this BaseUnit. The levels should be numbered in ascending order (this is the first number of each BeatLevel line). The second number indicates whether beats at that level occur at every second or third beat of the level below; that is, whether the level below is duple or triple. (This number must therefore be either 2 or 3.) The third number indicates how many beats occur at the level below before the first beat at the present level (that is, whether there are upbeats at the level below). The metrical structure given above is shown below, along with an explanation of what each line means. BaseUnit 250 < the BaseUnit is 250 milliseconds (16th notes, say) BeatLevel 1 2 0 < 8th-note level; 8ths are duple; no 16th note upbeat BeatLevel 2 2 1 < quarter-note level; 8ths are duple; one 8th-note upbeat BeatLevel 3 3 0 < dotted-half level; quarter-notes are triple (i.e., the piece is in 3/4); no quarter-note upbeat The note lines indicate the on-time of each note, followed by the off-time, followed by the pitch. The on-time and off-times are in milliseconds. Alternatively, notes can be listed with note-on and note-offs on separate lines, with the time-point followed by the pitch, like this: Note-on 0 60 Note-off 250 60 Note-on 250 64 Note-off 500 64 The pitch numbers indicate chromatic-scale degrees; following the usual convention, 60 = middle C. It is not permitted to have two notes of the same pitch overlapping; this will result in an error message. NB: All the time-points used in the piece must be multiples of the BaseUnit (to within a few milliseconds). If they are not, the program will not run and will produce an error message. GENERATING NOTES FILES FROM MIDI FILES. It is possible to generate notes files of the right format from MIDI files, using the program "mftext" (which is included in this distribution). (If importing a MIDI file made from a Finale document, for example, make sure you import it in the format "raw data".) To run this program on a MIDI file, type To create the mftext program, go to the "utilities" directory, and type "make". While in this directory, you can issue a command like: mftext -s mypiece.midi > mypiece.notes This will take a MIDI file called "mypiece.midi", generate the correct notes file, and put it in a file called "mypiece.notes". HOWEVER: you still have to add the metrical structure information yourself. (The mftext program also produces a lot of other stuff, which "analyze" will ignore.) RUNNING THE PROGRAM. First enter the analyze1.0 directory. To run the program on a notes file "mypiece.notes", type analyze mypiece.notes For example, to analyze "test.1.notes" (from the samples directory), you would type: analyze ../samples/test.1.notes THE OUTPUT OF THE PROGRAM. In processing the piece, the program breaks it down into segments of one BaseUnit in length. While it is processing the piece, the program indicates how many BaseUnit segments it has processed. The program then produces two representations of its preferred interpretation of the piece. First it outputs a series of lines. Here is a sample one: x x x x x start = 0 duration = 250 notes: {(67, 3)} root=3(G ) com= 1.250 har_cog= 3.000 har_var= 0.000 sbp= 0.000 odp= 0.000 tpc_cog= 5.400 tpc_var= 2.250 Each line indicates a segment of the piece: each segment is either one or several BaseUnits long. (If several contiguous BaseUnits occur with no change in pitch, it collapses them into one here.) The "x x x x x" here indicates the strength of the beat the segment starts on (this is indicated by the number of x's). "Duration" is the duration of the segment. "Notes" indicates the chromatic-scale-step and tonal pitch class of each note in the segment. (For chromatic scale steps, 60 = middle C; for tonal pitch classes, C = 2, with numbers ascending in the sharp direction on the line of fifths, so 3 is G.) "Root" indicates the chosen root (both line-of-fifth position and note-name). The expressions that follow give information about the rule scores for the segment in the chosen interpretation: com compatibility rule score har_cog harmonic center of gravity har_var harmonic variance score sbp strong beat penalty odp ornamental dissonance penalty tpc_cog tonal-pitch-class center of gravity tpc-var TPC variance score After the entire interpretation is outputted in this way, it is again outputted in a graphic fashion. Here each line corresponds to one BaseUnit. Here is a sample: 1000 x x x x G | < G > | 1125 x G | < G > | 1250 x x G | < B > | 1375 x G | < B > | 1500 x x x D | < A > | 1625 x D | < A > | 1750 x x D | < D > | 1875 x D | < D > | ^ ^ ^ Time-point Root of TPC (or TPC's) at beginning segment in segment of segment ^ ^ ^ Beat strength Graphic representation Graphic representation of segment of roots on line-of- of pitches on line- beginning fifths of-fiths SAMPLE NOTES FILES. We include a number of input files which the user may be interested in trying out or editing. These are in the samples directory. Some are simple tests; others are complete melodies or pieces or sections of pieces. Many of them are passages or pieces discussed in Temperley's dissertation or paper (which is as yet unpublished). Here is a list of the input files, with commentary. test.1.notes Simple chord progression test.2.notes Figure 14 in paper; tests strong beat rule test.3.notes Figure 6 of paper (first half); tests variance rule test.4.notes Figure 6 of paper (second half) test.5.notes Figure 8 of paper (first half); tests TPC->harmonic influence test.6.notes Figure 8 of paper (second half) test.7.notes Figure 16 of paper; tests harmonic->TPC feedback bach.inv.notes Bach Invention #1 in C major bach.gav.notes Bach Gavotte from French Suite #5 in G yankee.notes "Yankee Doodle" (unaccompanied) kings.notes "We Three Kings" (unaccompanied) susannah.notes "Oh Susannah" (unaccompanied) schub.waltz.notes Bb Major Schubert Waltz (also analyzed by Winograd) bach.min.notes Minuet from Bach C minor French Suite (also analyzed by Maxwell) moz.son.notes Mozart, Piano Sonata K. 309, I (opening only)