§ I.5 · The CLI Workshop · No. XV
Cantus-Firmus
Search.
After Mongeau & Sankoff 1990 · cf. Jeppesen 1930
Given a source melody and a corpus of pitch sequences, finds every place the source appears — exact, transposed, inverted, retrograde, or near-match. Outputs the offset, the transformation, and a similarity score derived from a Mongeau–Sankoff edit distance over pitch-interval sequences. The find-and-replace of melodic analysis.
¶ Why a command line
Musicologists studying parody masses, chorale harmonisations, and melodic citations across opera corpora need to find quotations and variants at scale. By hand the work takes weeks; in a single shell command it takes seconds. The output names where in the corpus the source occurs, what kind of transformation it underwent, and how good the match is — the rest of the analysis is yours.
¶ Invocation
$ node 06-cantus.js --source=source.txt < corpus.txt $ node 06-cantus.js --source=chant.txt --transpositions --inversions < mass.txt $ node 06-cantus.js --source=incipit.txt --threshold=0.85 < archive.txt $ cat *.txt | node 06-cantus.js --source=motif.txt --retrograde > matches.txt
¶ Sample output
source: C D E F G (intervals: 2 2 1 2) match at 1240 exact (similarity: 1.00) C D E F G match at 2103 transposition +7 (1.00) G A B C D match at 5441 inversion (0.96) G F E D C match at 8870 retrograde (1.00) G F E D C match at 12044 near (T+5,inv) (0.81) F E♭ D C B♭
¶ Scope
input --source=FILE the search melody (pitch list, MIDI or names)
stdin / files the corpus to search (pitch list)
flags --transpositions match all 12 transpositions
--inversions match the inverted contour
--retrograde match the reversed sequence
--threshold=F minimum similarity score (default 1.00)
--window=N max edit-distance window (default = source.len)
output one line per match: offset, transformation type, similarity
score, and the matched substring. similarity is a normalised
Mongeau–Sankoff distance over pitch-interval sequences.
¶ References
- Mongeau, Marcelle, and David Sankoff. “Comparison of Musical Sequences.” Computers and the Humanities 24, nos. 3–4 (1990): 161–175. — the edit-distance formalism the matcher implements.
- Jeppesen, Knud. Counterpoint: The Polyphonic Vocal Style of the Sixteenth Century. New York: Dover, 1992 [1930]. — classical pedagogy on Renaissance melodic incipit-matching.
¶ Source
loading source…