net/publication/243972445
CITATIONS READS
9 209
4 authors, including:
Remco C. Veltkamp
Utrecht University
278 PUBLICATIONS 6,627 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by W. Bas de Haas on 16 June 2014.
Abstract: Music scholars have been studying tonal harmony intensively for centuries, yielding numerous theories
and models. Unfortunately, a large number of these theories are formulated in a rather informal fashion and lack
mathematical precision. In this article we present HarmTrace, a functional model of Western tonal harmony that
builds on well-known theories of tonal harmony. In contrast to other approaches that remain purely theoretical, we
present an implemented system that is evaluated empirically. Given a sequence of symbolic chord labels, HarmTrace
automatically derives the harmonic relations between chords. For this, we use advanced functional programming
techniques that are uniquely available in the Haskell programming language. We show that our system is fast, easy to
modify and maintain, robust against noisy data, and that its harmonic analyses comply with Western tonal harmony
theory.
For ages, musicians, composers, and musicologists with Type-level Representations of Abstract Chord
have proposed theories regarding the structure of Entities), a system that meets these requirements
music to better understand how it is perceived, using state-of-the-art functional programming tech-
performed, and appreciated. In particular, tonal har- niques. HarmTrace allows us to easily adapt the
mony exhibits a considerable amount of structure harmonic specifications, empirically evaluate the
and regularity. The first theories describing tonal harmonic analyses, and use these analyses for
harmony date back at least to the 18th century tasks such as similarity estimation and automatic
(Rameau 1722). Since then, a rich body of literature annotation of large corpora.
that aims at explaining the harmonic regularities in The HarmTrace harmony model draws on the
both informal and formal models has emerged (e.g., ideas of Rohrmeier (2007, 2011). Rohrmeier mod-
Lerdahl and Jackendoff 1996). Such models have eled the core rules of Western tonal harmony as a
attracted numerous computer music researchers (large) context-free grammar (CFG, see Chomsky
to investigate the automation of the analysis and 1957). Later, De Haas et al. (2009) implemented this
generation of harmony. Most of these theories, grammar and specifically tuned it for jazz harmony,
however, have proven to be very hard to implement with the aim of modeling harmonic similarity.
(e.g., Clarke 1986). We are not aware of a model that The HarmTrace system transfers these ideas to a
has a working implementation that effectively ana- functional setting, solving typical problems that
lyzes tonal harmony and deals robustly with noisy occur in context-free parsing (e.g., the rejection of
data, while remaining simple and easy to main- pieces that cannot be parsed) and controlling the
tain, and scaling well to handle musical corpora of number of ambiguous solutions. Because it relies
considerable size. In this article we present Harm- on advanced functional programming techniques
Trace (Harmony Analysis and Retrieval of Music not readily available in most programming lan-
guages, HarmTrace is inextricably bound to Haskell
Computer Music Journal, 37:4, pp. 37–53, Winter 2014 (Peyton Jones 2003). Haskell is a purely functional
doi:10.1162/COMJ a 00209
c 2013 Massachusetts Institute of Technology. programming language with strong static typing.
Published under a Creative Commons Attribution- It is purely functional because its functions, like
NonCommercial 3.0 Unported (CC BY-NC 3.0) license regular mathematical functions, are guaranteed to
De Haas et al. 37
Figure 1. A typical chord functional analysis above
sequence (a) and its the score. For simplicity,
harmonic analysis, as we ignored voice-leading.
generated by HarmTrace Ton, Dom, and Sub denote
(b). The chord labels are tonic, dominant, and
printed below the score, subdominant, respectively.
and the scale degrees and
Piece
Ton Dom Ton
I Sub Dom I
7
C IV V C
7
F V /V V
7
II G7
D7
(a) (b)
produce the same output when given the same is perceived. This is illustrated in the sequence
input. It is strongly typed because it enforces re- displayed in Figure 1a: the D7 chord in this sequence
strictions on the arguments to functions, and it does can be removed without changing the general
so statically (i.e., at compilation time). Through structure of the harmony, although removing the G7
its main implementation, the Glasgow Haskell or the C at the end would cause the sequence to be
Compiler (GHC, http://haskell.org/ghc), Haskell perceived very differently. This implies that within
offers state-of-the-art functional programming tech- a sequence not all chords are equally important, and
niques, like error-correcting combinator parsers, must be organized hierarchically. This hierarchical
type-level computations, and datatype-genericity organization is reflected in the tree structure shown
(polytypic functions), that are not available in any in Figure 1b. The subdominant F has a subordinate
other mainstream language. These features proved role to the dominant G7 , which is locally prepared
to be essential to HarmTrace, as we will show. by a secondary dominant D7 . The tonic C releases
Naturally, any Turing-complete language can the harmonic tension built up by the F, D7 , and G7 .
be used to implement a particular algorithm or As in our earlier work with Rohrmeier (De Haas
model; this also holds for implementing HarmTrace. et al. 2009), the development of HarmTrace has been
Most programming languages, however, do not offer driven by its application in content-based music-
features, such as type-indexed computations, that information retrieval (MIR, Downie 2003) research.
make implementing HarmTrace much easier. We Within MIR, the notion of musical similarity plays
prefer Haskell over, e.g., C, Java, or LISP, because a prominent role because it allows ordering musical
its strong type system gives us better guarantees pieces in a corpus. Using such an ordering, one
of correctness, makes the development process can retrieve harmonically related pieces, like cover
clearer and easier, and allows for compiler type- songs, classical variations, or all blues pieces in a
directed optimizations (e.g., fusion laws). Other corpus. For performing such searches, a measure of
non-mainstream programming languages with type harmonic similarity is essential. Because our system
computations exist, such as Coq and Agda, but they captures the global and local relations between
do not have practical library support. chords, it can be used to improve systems that can
Following Rohrmeier, a core assumption that benefit from this contextual information. It has
underlies our harmony model is that Western tonal been shown that analyzing the hierarchical relations
harmony is organized hierarchically and transcends between chords in a sequence improves the quality
Piston’s table of usual root progressions (Piston 1991, of a harmonic-similarity measure in retrieval tasks
ch. 3, p. 21). As a consequence, within a sequence (De Haas et al. 2009, 2011; Magalhães and De Haas
of chords some chords can be removed because of 2011). Another application area for HarmTrace is
their subordinate role, leaving the global harmony automatic chord transcription (De Haas, Magalhães,
structure intact, whereas removing other chords and Wiering 2012). This is a common MIR task
can significantly change how the chord sequence that aims at recognizing a chord sequence from the
De Haas et al. 39
fashion. Additionally, quasi-grammatical systems results were promising, the context-free parsing
for Schenkerian analysis have been proposed re- techniques used in that work hampered both
cently (Marsden 2010). Furthermore, Choi (2011) theoretical as well as practical improvements. First,
developed a system for analyzing the harmony of a sequence of chords that did not precisely match
jazz chord sequences; this system identifies common the context-free specification was rejected and no
harmonic phenomena, like secondary dominants explanatory information was given to the user.
and tritone substitutions, and labels the chords in- For example, appending one awkward chord to an
volved accordingly. The relation between music and otherwise grammatically correct sequence of chords
language is not merely a theoretical one; a growing forced the parser to reject the complete sequence, not
body of evidence, also from neuropsychology and returning any partial information about what it had
neuroimaging, suggests that music and language parsed.
are more closely related than was previously be- Second, musical harmony is ambiguous and
lieved (Patel 2003). An in-depth overview of the chords can have multiple meanings depending on
animated debate on the relation between music the tonal context in which they occur. This is
and language is beyond the scope of this article, reflected in all the grammatical models discussed
however. earlier. A major drawback of CFGs is that they are
The generative formalism proposed by Rohrmeier very limited in ways of controlling the ambiguity
(2007, 2011), which the HarmTrace model draws of the specification. It is possible to use rule-
extensively from, expands upon many of these weightings and to set low weights to rules that
earlier approaches in a number of ways. Rohrmeier explain rare phenomena. This allows for ordering
gives an encompassing account of how relation- the ambiguous solutions by the total relevance of
ships in tonal harmony can be modeled using a the rules used. This does not overcome the fact that,
generative CFG with variable binding. His gram- for some pieces, the number of parse trees grows
mar models form, phrasing, theoretical harmonic exponentially as function of the number of input
function (Riemann ca. 1895), prolongation of scale chords.
degrees (Schenker 1935; Lerdahl and Jackendoff Finally, writing context-free rules by hand is
1996), and modulation. Rohrmeier’s model differs a tedious and error-prone enterprise, especially
from earlier grammatical formalisms in various because the grammatical models can become rather
ways. Steedman’s approach (1984, 1996) uses seven large. For instance, a rule generalizing over an
context-sensitive rules (with variations) to explain arbitrary scale degree has to be expanded for each
the structure of blues progressions. Steedman’s scale degree, I, II, III, etc. Hence, some form of
grammar does not go beyond the jazz blues domain, high-level grammar generation system is needed to
however, and it remains unclear how it could be allow for generalizing over scale degree and chord
adapted to support other styles. Rohrmeier’s for- type, and to control conditional rule execution.
malism also differs from GTTM: The latter aims Another important model that has influenced the
at describing the core principles of tonal cognition, development of HarmTrace is that of Temperley
and harmony is covered mainly as a prolongational (2001) and Temperley and Sleator (1999). They give
phenomenon, whereas Rohrmeier’s formalism de- an elaborate formal account of Western tonal music,
scribes the structure of tonal harmony from a music- and also provide an efficient implementation. This
theoretical perspective with concrete context-free rule-based system, which is partly inspired by
rules. Rohrmeier acknowledges that a full account GTTM, can perform an analysis of the chord roots
of tonal harmony would require a large number and the key given a symbolic score, but does not
of varying style-specific rules, and his formalism formalize the hierarchical relations between chords.
aims to capture only the core rules of Western tonal Our system continues where Temperley’s left off:
harmony. Based on the available chord and key information of
De Haas et al. (2009) performed a first attempt the piece, we model the global and local dependency
to implement the ideas of Rohrmeier. Although the relations between these chords.
De Haas et al. 41
understand our model: We use a simplified syntax From Functions to Scale Degrees
to describe the datatype specifications that is in-
4. Ton Maj → IMaj | IMaj IV Maj IMaj | III m
Maj
spired by the syntax used to describe CFGs. Users
of HarmTrace need only know Haskell if they wish 5. Ton Min → IMin
m
| IMin
m
IV m
Min IMin | III Maj
m
specifications for chains of diatonic fifths instead 17. X7M → V /Xm X7M X ∈ {I , II , II , . . . , VII }
M
(Spec. 18–19; see, for instance, Figure 2).
The Ton M translating into III m
Maj (III Min in minor) Besides these basic elements of tonal harmony,
is perhaps the most unexpected transformation (and we distinguish various scale-degree substitutions
we deviate from Rohrmeier’s 2007 model here). and transformations. For this we introduce the
Often the third degree can be explained as either a function V /X which transposes an arbitrary scale
preparation of a secondary dominant (Spec. 17), as degree X a fifth up. Herewith, Spec. 16 accounts
being part of diatonic chain of fifths (Spec. 19), or as for the classical preparation of a scale degree by its
supporting the subdominant (Spec. 10–11). In certain secondary dominant, stating that every scale degree,
progressions, however, it cannot be explained by independently of its mode, chord class, and root
any of these specifications, and is best assigned a interval, can be preceded by a chord of the dominant
tonic function because it has two notes in common class, one fifth up. In the case of chord class, we
with the tonic and does not create strong harmonic denoted the independence of a chord class with
tension. the chord class variable C. The empty symbol, ∅,
represents the major class (no superscript). (Note
From Scale Degrees to Chords that in all specifications that contain transposition
12. IMaj → "C:maj" | "C:maj6" | "C:maj7" | functions, terms like Y /XC M should always be
"C:maj9" | . . . interpreted as (Y /X)CM .) Similarly, every dominant
scale degree can be prepared with the minor chord
m
13. IMin → "C:min" | "C:min7" | "C:min9" | one fifth above (Spec. 17). These two specifications
"C:min(13)" | . . . together allow for the derivation of the typical
7
14. VMaj → "G:7" | "G:7(b9,13)" | and prominently present ii-V-I progressions in jazz
"G:(#11)" | "G:7(#9)" | . . . harmony. (The ii-V-I progression is a very common
15. VII 0M → "B:dim(bb7)" cadential chord progression in jazz harmony, but
it also occurs in other musical genres. The I-
Finally, scale degrees are translated into the chord can practically be an arbitrary chord in a
actual surface chords, which are used as input sequence which is preceded by its relative secondary
De Haas et al. 43
dominant a fifth interval up, the V, and its relative The harmony model in HarmTrace allows for
subdominant another fifth interval up, the ii.) various scale-degree transformations. Every chord of
The explicit annotation of these structures is the dominant class can be transformed into its tri-
very common in jazz analysis and education (see, tone substitution with Spec. 20. This specification
for instance, Jaffe 1996), and also Rohrmeier (2007, uses another transposition function V /X which
2011) incorporates Spec. 16 in his model. Spec. 16–17 transposes a scale degree X a diminished fifth—a
interfere with Spec. 4–11, however, causing multiple tritone—up (or down). The tritone substitution spec-
analyses. Because we prefer, e.g., a II m, V 7 , and I ification allows for the derivation of progressions
to be explained as Sub, Dom, and Ton, we constrain with a chromatic baseline, e.g., Am G7 G, and is
the application of Spec. 16 and 17 to the cases where very common in jazz harmony (see, for instance,
Spec. 4–11 do not apply. The rationale behind this Jaffe 1996). Also, a tritone specification was earlier
choice is more of a pragmatic than of a musical used in a similar model in De Haas et al. (2009).
nature, and the user of the model might also decide Because we want the application of the Spec. 16–
on a different specification preference. 20 to terminate, we limit the number of possible
recursive applications of these rules (see the Parsing
section).
Diatonic Chains of Fifths
Maj → Vd /XMaj
18. Xm m
Xm
Maj Diminished Sevenths
19. XMin → Vd /XMin XMin
21. X0M → III /X0M
The model also accounts for the diatonic chains of
22. X7M → I I79 /X0M
fifths in major (Spec. 18) and minor (Spec. 19) keys.
These diatonic-chain specifications are necessary Diminished seventh chords can have various roles
to explain the typical cycle-of-fifths progressions: in tonal harmony. An interesting characteristic of
I IV VII m III m VI m II m V 7 I (see Figure 2 for the these chords—consisting only of notes separated by
major case, as well as the Autumn Leaves example minor third intervals—is that they are completely
in the next section). These strong chord progressions symmetrical. Hence, a diminished seventh chord
are very commonly found throughout Western tonal has four enharmonic equivalent chords that can be
music. Also, Rohrmeier’s (2011) model has a rule reached by transposing the chord by a minor third
dedicated specifically to this progression. To reduce with the transposition function III /X (Spec. 21).
multiple ambiguous solutions, we constrain the In general, we treat diminished seventh chords as
major-key specification to apply only to the minor dominant-seventh chords with a 9 and no root
chords, because I , IV , and V 7 translate directly to note, which is a common interpretation of this
Ton, Sub, and Dom, respectively. Similarly, Spec. 19 chord (Saslaw 2013). For instance, in a progression
captures the same phenomenon in a minor key. Am7 A0 G7 , the A0 closely resembles the G79 ,
Here, we restrict the application of the specification because a G79 chord consists of G, B, D, F, and
only to the major chords because, again, I m, IV m, and A, and an A0 chord consists of A, B, D, and
V 7 translate directly to Ton, Sub, and Dom in minor. F. This similarity is captured in Spec. 22, where
We implemented one exception to the diatonic II /X transposes a scale degree one semitone up.
minor specification that allows the VI to precede Similarly, by combining secondary dominants
the II m in minor. Here, the major chord precedes a (Spec. 16) with Spec. 22, e.g., F E0 ( ≈ D79 ) G, and
minor chord. See the E Am75 in the analysis of an application of Spec. 21, e.g., F F0 (≈E0 ) G, we
Autumn Leaves, later in this article. can account for most of the ascending diminished
chord progressions. Within harmony theory, this
phenomenon is usually labeled as VII /X, where F0
Tritone Substitution
would be the VII /V (in C major) in the previous
20. X7M → V /X7M example. Because our model can explain it without
De Haas et al. 45
Parsing For most songs, parsing proceeds with no correc-
tions, or only very few. Songs with a very high error
Once we have a formal specification as a datatype, ratio denote multiple modulations, bad input, or a
the next step is to define a parser that transforms wrong key assignment. Note that, depending on the
textual chord labels into values of our datatype. severity of “unexpectedness” of a chord, there might
Writing a parser that parses labels into our datatype be multiple error-corrections necessary to create a
would normally mean writing tedious code that valid analysis (e.g., one deletion and two insertions).
closely resembles the datatype specification. In In our model, one particular parameter has a
Haskell however, we can use datatype-generic pro- large influence on the parsing and error-correction
gramming techniques (Jeuring et al. 2009) to avoid process. This parameter controls the number of
writing most of the repetitive portions of the code. recursive applications of the specifications for
(These techniques are not to be confused with regu- secondary dominant and the like (Spec. 16–20). It
lar polymorphism, as in Java generics.) Moreover, must be set carefully, because setting it to a very low
we derive not only the parser automatically, but value will lead to bad analyses, and setting it to a high
also a pretty-printer for displaying the harmony value will make the internally generated model very
analysis in tree form, and functions for comparing large, resulting in increased error-correction times
these analyses. This makes the development and and often sub-optimal error-correction solutions.
fine-tuning of the model much easier, as only the For the examples and results in this article we have
datatypes have to be changed, and the code adapts used values between five and seven.
itself automatically. The technical details of the
implementation of our model, and of the generic-
programming techniques we use, are covered in an Example Analyses
earlier publication (Magalhães and De Haas 2011).
Because music is an ever-changing, culturally In this section we demonstrate the analytic power
dependent, and extremely diverse art form, we of the HarmTrace system. The input presented to
cannot hope to model all valid harmonic relations in HarmTrace consists of a sequence of plain-text chord
our datatype. Furthermore, song data may contain labels in the syntax defined by Harte et al. (2005), and
mistakes or mistyped chords, perhaps feature the output consists of a parse tree similar to those
extraction noise, or malformed data of dubious often used in natural language processing. In these
harmonic validity. In HarmTrace we use a parsing trees, the input chord labels are the leaves, which
library featuring error-correction: Chords that do are subsequently grouped into scale degrees, scale-
not fit the structure are automatically deleted degree transformations, and functional categories,
or preceded by inserted chords, according to the and finally collected in a Piece node, as prescribed
datatype structure (Swierstra 2009). by the rules of the model. The notation used in
The error-correction process uses heuristics to the parse trees is identical to the notation used to
find a good parse tree in a reasonable amount of describe the datatype specifications in the previous
time. When faced with a chord that does not fit section. Musical harmony can be very ambiguous,
the harmony model, it will consider all possible and sometimes multiple analyses are defensible.
combinations of deletion and insertion of chords (up A strength of HarmTrace is that, by changing the
to a fixed depth of three steps) to adapt the chord specifications in the previous section, it can be
sequence to the model. In this way, the simplest easily adapted to meet the musical intuitions of its
corrections (involving the fewest insertions or dele- users.
tions) are chosen. We could also assign different costs We start by analyzing the B section of the
to each specification, in order to prefer some rules Autumn Leaves jazz standard as found in The
over others. In practice, we did not find this neces- Real Book (Sher 1988). The parse tree of this piece
sary. The order in which the rules are specified also in the key of G minor is depicted in Figure 3.
matters, as earlier rules take precedence over later Within the piece, the three A0 D7 Gm sequences
rules; we use this fact to guide the correction process. translate into subdominant, dominant, and tonic
Piece
F7 C9
Figure 3
Piece Piece
Ton Dom Ton Dom Ton Dom Ton Dom Ton Dom Ton Dom
I Sub Dom I V /V 7 V I Sub Dom
I m Sub Dom Im Sub Dom Im V7
F Vd /II · II m V F II79 /II 7 C F IV Sub Dom
Cm6 IV m Sub Dom Cm6 V /II 7 II Sub Dom Cm6 G7
VI m Gm7 C III 0 B V /IV 7 IV Sub Dom
m m 7 m
Fm7 II V7 V /VI VI DΔ II V7
Dm V 0 II79 /I 7 B V /IV 7 IV V
m
B0 II 0 V /I m I 7 B C6 Dm75 G759 III A7 Dm75 G759
III 0 Vm F7 Em7
A0 Cm Figure 5
Figure 4
De Haas et al. 47
Figure 6. Two analyses of a (a), with an analysis Figure 7. An excerpt of the
phrase from Tebe Poem by produced by HarmTrace analysis of It Don’t Mean a
Dmitry Bortniansky (b). The nodes labeled TR Thing (If It Ain’t Got That
(1751–1825). We compare in Rohrmeier’s analysis Swing).
an analysis adapted from indicate “tonal regions,” a
Rohrmeier (2011), concept not included in
appearing above the score our model.
Piece
I Sub Dom V /V 7 V I
I7 F II 7 G V /VI 7 VI m III 0
C7 D7 III 7 Am IV 0
E7 F0
(a) (b)
Figure 6
Piece
V /V 7 V7 I Sub Dom V /V 7 V7 I
Figure 7
starts by introducing the tonic, Cm, followed by a Rohrmeier connects the tonic, dominant, and sub-
perfect cadence. The B-part displayed in the second dominant nodes in tonal regions whereas HarmTrace
Dom branch shows a ii-V-motion to the Neapolitan (see Figure 6b) does not. We elaborate on this issue
II (Spec. 25) and is followed by a ii-V-I to Cm. in the Discussion section. Another difference in
Figure 6 displays the score and two analyses of derivation is that because we treat the F0 (≈D79 ) as
an extract from Tebe Poem, by Dmitry Bortniansky. a V /V , the E7 and Am are analyzed as being part of
The analysis in Figure 6a is the theoretical anal- a larger chain of fifths.
ysis proposed by Rohrmeier (2011). Although the In Figure 7 we show the HarmTrace analysis of
notation used by Rohrmeier differs slightly from the jazz standard It Don’t Mean a Thing (If It Ain’t
the notation used in this article, the analyses are Got That Swing). The analysis shows how similar
clearly similar. There are also some differences. Gm chords are grouped under one VI m node. It
Piece Piece
(a) (b)
furthermore illustrates how the Sub and Dom nodes sets: a small data set we have used in earlier work
are prepared by chains of secondary dominants. (De Haas et al. 2009), and a larger data set (used
We conclude this section with two small exam- in De Haas, Veltkamp, and Wiering 2013). We
ples that contain error corrections. These corrections refer to these two data sets as small and large,
should not be interpreted as corrections of musical respectively. The small data set contains 72 chord
errors, but they illustrate the behavior of HarmTrace sequences that describe mainly jazz pieces. The
in cases where harmonies cannot be explained by large data set contains 5,028 chord sequences
the model. The example in Figure 8a is an excerpt that describe jazz, Latin, and pop pieces, as well
of the jazz standard Someday My Prince Will Come, as a few classical works. Both data sets consist
Figure 8b is taken from the jazz standard There Is of textual chord sequences extracted from user-
No Greater Love. In Someday My Prince Will Come, generated Band-in-a-Box files that were collected
the model cannot explain the E where it occurs. on the Internet. (Band-in-a-Box [Gannon 1990]
Because the D7 can immediately resolve to the G7 , is a commercial software package that generates
the parser deletes the E . The model specification accompaniment, given a chord sequence.) For the
does not allow a Sub to translate into a VI m scale extraction of the plain-text chord labels we have
degree. Adding such a specification would cause a extended software developed by Mauch et al. (2007).
large number of ambiguous solutions, if the diatonic To our knowledge, the large data set is the largest
fifth specification (Spec. 19) were not constrained. data set of symbolic chord sequences available to
Therefore, in Figure 8b, the model needs a diatonic the research community, as of June 2013.
chain of fifths to explain the VI m and the parser The small data set contains a selection of pieces
solves this by inserting a II m. Corrections like the that were checked manually and “make sense”
ones in Figure 8 represent typical examples of error harmonically, and the large data set includes many
corrections in HarmTrace. songs that are harmonically atypical. This is because
the files are user-generated, so they contain peculiar
and unfinished pieces, wrong key assignments, and
Experimental Results other errors; it can therefore be considered “real
world” data. Also, the large data set contains
To demonstrate that HarmTrace can be efficiently pieces that modulate, and even some pieces that
and effectively used in practice, we evaluate its might be considered atonal (e.g., John Coltrane’s
parsing performance on two chord sequence data Giant Steps). We deliberately chose to use a “real
De Haas et al. 49
Table 1. Parsing Results
Data Set Deletions Insertions Corrections Chords Parse Time Total Time
world” data set to show that HarmTrace is robust deleted chords under 6 percent of the total chords
against noisy data, offers good performance in terms parsed.
of parsing speed, and still delivers analyses that When we compare the parsing results of the
make sense. small data set with the results of an older, Java-
based parser (De Haas et al. 2009), we notice that
HarmTrace is much faster. The Java-based parser
Parsing Results took more than 9 min to parse this data set. We
cannot compare the parsing results of the large
When parsing the data we measure the number data set because the majority of the pieces are
of parsed chords, deleted chords, and inserted rejected by the grammar used by the older parser.
chords, as well as parsing time. These numbers are This emphasizes how important the error-correction
summarized in Table 1. Both runs were performed process is. Even with error correction, HarmTrace
on the same Intel Core 2 6600 machine running parses the large data set faster than the Java-based
at 2.4 GHz with 3 GB of random-access memory parser parses the small data set.
compiled using GHC version 7.0.3.
On the small data set the HarmTrace model
performs very well. The songs are parsed quickly Discussion
and, on average, fewer than one chord per song
is deleted. Also, fewer than three insertions are We have presented HarmTrace, a system that au-
necessary, on average, for a piece to parse. It would tomatically analyses sequences of musical chord
have been possible to adapt the model in such way labels. Implementing our system in Haskell has
that the small data set would parse without any proven to be a profitable decision, given the advan-
errors, as was done by De Haas et al. (2009). We chose tages of error-correcting parsers and datatype-generic
to accept this small number of error corrections and programming. We have shown that HarmTrace can
keep our grammar small and easy to comprehend. handle corpora of considerable size, parses chord
The data set is parsed within a second. progressions quickly, and is robust against noisy
For the large data set, the parsing time per data. HarmTrace currently does not support full
song increases considerably, due to a larger number modulation, but it can explain changes between
ambiguous solutions and increased error-correction. parallel major and minor keys. That the lack of
The 5,028 chord sequences are still parsed rea- full modulation does not have to hamper prac-
sonably quickly, in 6 min 25 sec. The number of tical application is shown by the application of
error corrections increases considerably, but the HarmTrace to practical MIR tasks like automatic
parser never crashes or refuses to produce valid harmonic-similarity estimation, chord transcrip-
output. The higher number of error corrections tion, and automatic harmonization. Although the
is expected, because this data set contains songs model presented has a bias towards jazz harmony,
with modulations, atonal harmonies, and a variety we have shown that it can be used to analyze some
of errors. Still, HarmTrace keeps the number of classical works as well.
De Haas et al. 51
Jackendoff, R., A Generative Theory of Tonal Music.” Koops, H. V., J. P. Magalhães, and W. B. de Haas. 2013. “A
Psychology of Music 14(1):3–16. Functional Approach to Automatic Melody Harmon-
Downie, J. S. 2003. “Music Information Retrieval.” isation.” In Proceedings of the First ACM SIGPLAN
Annual Review of Information Science and Technology Workshop on Functional Art, Music, Modeling &
37(1):295–340. Design (FARM ’13).
Drabkin, W. 2013. Neapolitan Sixth Chord. Oxford Lerdahl, F., and R. Jackendoff. 1996. A Generative
Music Online. Oxford: Oxford University Press. Avail- Theory of Tonal Music. Cambridge, Massachusetts:
able online at http://www.OxfordMusicOnline.com/ MIT Press.
subscriber/article/grove/music/19658 (subscription Magalhães, J. P., and W. B. de Haas. 2011. “Functional
required). Accessed 25 June 2013. Modelling of Musical Harmony: An Experience Report.”
Gannon, P. 1990. “Band-in-a-Box.” Available online at In Proceedings of the ACM SIGPLAN International
http://www.pgmusic.com/. Accessed 25 June 2013. Conference on Functional Programming, pp. 156–
De Haas, W. B., J. P. Magalhães, and F. Wiering. 2012. 162.
“Improving Audio Chord Transcription by Exploiting Marsden, A. 2010. “Schenkerian Analysis by Computer:
Harmonic and Metric Knowledge.” In Proceedings A Proof of Concept.” Journal of New Music Research
of the International Society for Music Information 39(3):269–289.
Retrieval Conference, pp. 295–300. Mauch, M., et al. 2007. “Discovering Chord Idioms
De Haas, W. B., R. C. Veltkamp, and F. Wiering. 2013. Through Beatles and Real Book Songs.” In Proceedings
“A Geometrical Distance Measure for Determining the of the International Conference on Music Information
Similarity of Musical Harmony.” International Journal Retrieval, pp. 255–258.
of Multimedia Information Retrieval 2(3):189–202. Noland, K., and M. Sandler. 2009. “Influences of Signal
dx.doi.org/10.1007/s13735-013-0036-6. Processing, Tone Profiles, and Chord Progressions on
De Haas, W. B., et al. 2009. “Modeling Harmonic Similarity a Model for Estimating the Musical Key from Audio.”
Using a Generative Grammar of Tonal Harmony.” In Computer Music Journal 33(1):42–56.
Proceedings of the International Conference on Music Pachet, F. 1999. “Surprising Harmonies.” International
Information Retrieval, pp. 549–554. Journal of Computing Anticipatory Systems 4:139–161.
De Haas, W. B., et al. 2011. “HarmTrace: Improving Patel, A. D. 2003. “Language, Music, Syntax and the
Harmonic Similarity Estimation Using Functional Brain.” Nature Neuroscience 6:674–681.
Harmony Analysis.” In Proceedings of the Interna- Peyton Jones, S. 2003. “Haskell 98 Language and Li-
tional Conference on Music Information Retrieval, braries: The Revised Report.” Journal of Functional
pp. 66–72. Programming 13(1):7–255.
De Haas, W. B., et al. 2012. “Chordify: Chord Transcription Piston, W. 1991. Harmony. London: Gollancz, 7th edition.
for the Masses.” Demonstration presented at the Revised and expanded by Mark DeVoto.
International Society for Music Information Retrieval Rameau, J.-P. 1722. Traité de l’harmonie. Paris: Ballard.
Conference, 8–12 October, Porto, Portugal. Available Translated by P. Gossett as Treatise on Harmony. 1971.
online at http://dreixel.net/research/pdf/cctfm.pdf. New York: Dover.
Accessed June 2013. Riemann, H. ca. 1895. Harmony Simplified: Or the Theory
Hamanaka, M., K. Hirata, and S. Tojo. 2006. “Implement- of the Tonal Functions of Chords. London: Augener.
ing A Generative Theory of Tonal Music.” Journal of Originally published as Vereinfachte Harmonielehre.
New Music Research 35(4):249–277. Oder: Die Lehre von den tonalen Funktionen der
Harte, C., et al. 2005. “Symbolic Representation of Musical Akkorde.
Chords: A Proposed Syntax for Text Annotations.” In Roads, C. 1979. “Grammars as Representations for
Proceedings of the International Symposium on Music Music.” Computer Music Journal 3(1):48–55.
Information Retrieval, pp. 66–71. Rohrmeier, M. 2007. “A Generative Grammar Approach
Jaffe, A. 1996. Jazz Harmony. Rottenburg: Advance Music, to Diatonic Harmonic Structure.” In Proceedings of the
2nd edition. Sound and Music Computing Conference, pp. 97–100.
Jeuring, J., et al. 2009. “Libraries for Generic Program- Rohrmeier, M. 2011. “Towards a Generative Syntax of
ming in Haskell.” In P. Koopman, R. Plasmeijer, and Tonal Harmony.” Journal of Mathematics and Music
D. Swierstra, eds. Advanced Functional Programming, 5(1):35–53.
6th International School, Lecture Notes in Computer Saslaw, J. 2013. Diminished Seventh Chord. Oxford Music
Science, vol. 5832. Berlin: Springer, pp. 165–229. Online. Oxford: Oxford University Press. Available
De Haas et al. 53