Automatic Functional Harmonic Analysis

Embed Size (px)

Citation preview

  • 8/17/2019 Automatic Functional Harmonic Analysis

    1/17

     Automatic FunctionalHarmonic Analysis

    W. Bas De Haas,∗ Jos ´ e Pedro Magalh ˜ aes,†

    Frans Wiering,∗ and Remco C. Veltkamp∗∗Department of Information andComputing SciencesUtrecht UniversityP.O. Box 80.0893508 TB Utrecht, The Netherlands

    {W.B.deHaas, F.Wiering, R.C.Veltkamp}@uu.nl†Department of Computer ScienceUniversity of OxfordWolfson Building, Parks RoadOxford OX1 3QD, United [email protected]

    Abstract:   Music scholars have been studying tonal harmony intensively for centuries, yielding numerous theoriesand models. Unfortunately, a large number of these theories are formulated in a rather informal fashion and lackmathematical precision. In this article we present HarmTrace, a functional model of Western tonal harmony thatbuilds 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, HarmTraceautomatically derives the harmonic relations between chords. For this, we use advanced functional programmingtechniques that are uniquely available in the Haskell programming language. We show that our system is fast, easy tomodify and maintain, robust against noisy data, and that its harmonic analyses comply with Western tonal harmonytheory.

    For ages, musicians, composers, and musicologistshave proposed theories regarding the structure ofmusic to better understand how it is perceived,performed, and appreciated. In particular, tonal har-mony exhibits a considerable amount of structure

    and regularity. The first theories describing tonalharmony date back at least to the 18th century(Rameau 1722). Since then, a rich body of literaturethat aims at explaining the harmonic regularities inboth informal and formal models has emerged (e.g.,Lerdahl and Jackendoff 1996). Such models haveattracted numerous computer music researchersto investigate the automation of the analysis andgeneration of harmony. Most of these theories,however, have proven to be very hard to implement(e.g., Clarke 1986). We are not aware of a model thathas a working implementation that effectively ana-lyzes tonal harmony and deals robustly with noisy

    data, while remaining simple and easy to main-tain, and scaling well to handle musical corpora ofconsiderable size. In this article we present Harm-Trace (Harmony Analysis and Retrieval of Music

    Computer Music Journal, 37:4, pp. 37–53, Winter 2014

    doi:10.1162/COMJ a 00209c 2013 Massachusetts Institute of Technology.Published under a Creative Commons Attribution-

    NonCommercial 3.0 Unported (CC BY-NC 3.0) license

    with Type-level Representations of Abstract ChordEntities), a system that meets these requirementsusing state-of-the-art functional programming tech-niques. HarmTrace allows us to easily adapt theharmonic specifications, empirically evaluate the

    harmonic analyses, and use these analyses fortasks such as similarity estimation and automaticannotation of large corpora.

    The HarmTrace harmony model draws on theideas of  Rohrmeier (2007, 2011). Rohrmeier mod-eled the core rules of Western tonal harmony as a(large) context-free grammar (CFG, see Chomsky1957). Later, De Haas et al. (2009) implemented thisgrammar and specifically tuned it for jazz harmony,with the aim of modeling harmonic similarity.The HarmTrace system transfers these ideas to afunctional setting, solving typical problems thatoccur in context-free parsing (e.g., the rejection of

    pieces that cannot be parsed) and controlling thenumber of ambiguous solutions. Because it relieson advanced functional programming techniquesnot readily available in most programming lan-guages, HarmTrace is inextricably bound to Haskell(Peyton Jones 2003). Haskell is a purely functionalprogramming language with strong static typing.It is purely functional because its functions, likeregular mathematical functions, are guaranteed to

    De Haas et al.   37

  • 8/17/2019 Automatic Functional Harmonic Analysis

    2/17

    Piece 

    Ton 

    C

    Dom 

    Dom 

    V 7

    V 7

    G7

    V  / V 

    II 7

    D

    (b)(a)

    7

    Sub

    IV 

    F

    Ton 

    C

    Figure 1. A typical chordsequence (a) and its

     harmonic analysis, as generated by HarmTrace(b). The chord labels are

     printed below the score,and the scale degrees and

     functional analysis abovethe score. For simplicity,we ignored voice-leading.Ton, Dom, and Sub  denotetonic, dominant, andsubdominant, respectively.

    produce the same output when given the sameinput. It is strongly typed because it enforces re-strictions on the arguments to functions, and it doesso statically (i.e., at compilation time). Throughits main implementation, the Glasgow HaskellCompiler (GHC, http://haskell.org/ghc), Haskelloffers state-of-the-art functional programming tech-niques, like error-correcting combinator parsers,type-level computations, and datatype-genericity (polytypic functions), that are not available in anyother mainstream language. These features provedto be essential to HarmTrace, as we will show.

    Naturally, any Turing-complete language can

    be used to implement a particular algorithm ormodel; this also holds for implementing HarmTrace.Most programming languages, however, do not offerfeatures, such as type-indexed computations, thatmake implementing HarmTrace much easier. Weprefer Haskell over, e.g., C, Java, or LISP, becauseits strong type system gives us better guaranteesof correctness, makes the development processclearer and easier, and allows for compiler type-directed optimizations (e.g., fusion laws). Othernon-mainstream programming languages with typecomputations exist, such as Coq and Agda, but theydo not have practical library support.

    Following Rohrmeier, a core assumption thatunderlies our harmony model is that Western tonalharmony is organized hierarchically and transcendsPiston’s table of usual root progressions (Piston 1991,ch. 3, p. 21). As a consequence, within a sequenceof chords some chords can be removed because oftheir subordinate role, leaving the global harmonystructure intact, whereas removing other chordscan significantly change how the chord sequence

    is perceived. This is illustrated in the sequencedisplayed in Figure 1a: the D7 chord in this sequencecan be removed without changing the generalstructure of the harmony, although removing the G7

    or the C at the end would cause the sequence to beperceived very differently. This implies that withina sequence not all chords are equally important, andmust be organized hierarchically. This hierarchicalorganization is reflected in the tree structure shownin Figure 1b. The subdominant F has a subordinaterole to the dominant G7, which is locally preparedby a secondary dominant D7. The tonic C releasesthe harmonic tension built up by the F, D7, and G7.

    As in our earlier work with Rohrmeier (De Haaset al. 2009), the development of HarmTrace has beendriven by its application in content-based music-information retrieval (MIR, Downie 2003) research.Within MIR, the notion of musical similarity playsa prominent role because it allows ordering musicalpieces in a corpus. Using such an ordering, onecan retrieve harmonically related pieces, like coversongs, classical variations, or all blues pieces in acorpus. For performing such searches, a measure ofharmonic similarity is essential. Because our systemcaptures the global and local relations betweenchords, it can be used to improve systems that can

    benefit from this contextual information. It hasbeen shown that analyzing the hierarchical relationsbetween chords in a sequence improves the qualityof a harmonic-similarity measure in retrieval tasks(De Haas et al. 2009, 2011; Magalh ães and De Haas2011). Another application area for HarmTrace isautomatic chord transcription (De Haas, Magalh ães,and Wiering 2012). This is a common MIR taskthat aims at recognizing a chord sequence from the

    38   Computer Music Journal

  • 8/17/2019 Automatic Functional Harmonic Analysis

    3/17

    audio signal. For every beat position, the chords thatmatch the spectrum well are selected from a chorddictionary. Subsequently, the HarmTrace model isused to select the candidate sequence that best fitsthe modeled rules of tonal harmony. Chordify, anInternet startup, uses HarmTrace to make automaticchord transcription accessible to the general public(http://chordify.net, see also De Haas et al. 2012).

    The application to MIR explains some of thechoices made in the development of HarmTrace. Inparticular, because a large corpus of chord sequences,mainly from the jazz repertoire, is available forretrieval tasks, the harmony model exhibits a biastowards jazz harmony. In this article we describe themusical aspects of HarmTrace; its Haskell-specificimplementation aspects are described elsewhere(Magalh ães and De Haas 2011).

    A fully functional model of tonal harmony thatcan quickly analyze chord sequences offers severalother benefits. Musicologists study the harmonicstructure of pieces and annotate them by hand. Thisis a time-consuming enterprise, especially whenlarge corpora are involved. With the automaticannotation techniques that we present here, thiscan be done quickly, even for large corpora possibly

    containing errors. Additionally, HarmTrace couldaid in (automatic) composition by generating se-quences of chords, generating harmonically realisticcontinuations given a sequence of chords, or auto-matically harmonizing a melody (Koops, Magalh ães,and De Haas 2013).

    This article starts by discussing a relevantselection of the large body of existing literature onharmony theory and modeling in the next section.Subsequently, we explain our harmony model,followed by an evaluation of some detailed, exampleanalyses created by this model. Next, we show thatHarmTrace can deal with large amounts of noisy

    data. Finally, we conclude the article by discussingthe limitations of our system and differences fromother models.

    Related Work 

    The 19th and 20th centuries have yielded a wealthof theoretical models of Western tonal music; tonal

    harmony, in particular, has received considerableattention. Most theories that describe the relation-ships between sequential chords capture notions oforder and regularity; some combinations of chordssound natural whereas others sound awkward (e.g.,Rameau 1722). These observations led music the-orists to develop ways to analyze the function of achord in its tonal context (e.g., Riemann ca. 1895).Unfortunately, the majority of these theories areformulated rather informally and lack descriptionswith mathematical precision. In this section we givea condensed overview of the theories that playedan important role in the formation of the harmonymodel we present in this article.

    Lerdahl and Jackendoff’s  Generative Theory of Tonal Music (GTTM, 1996) is a seminal work thatfurther formalized the ideas of Schenker (1935).GTTM structures Western tonal compositionsby defining recursive, hierarchical dependencyrelationships between musical elements usingwell-formedness and constraint-based preferencerules. The GTTM framework distinguishes fourkinds of hierarchical structure: meter, grouping,time-span reduction, and prolongational reduction.Although GTTM can be considered one of the

    greatest contributions to music theory and musiccognition of the last few decades, implementingthe theory is difficult because the often vague andambiguous preference rules lead to a wide rangeof possible analyses (Clarke 1986; Temperley 2001,ch. 1; Hamanaka, Hirata, and Tojo 2006).

    The recursive formalization proposed by Ler-dahl and Jackendoff suggests a strong connectionbetween language and music. Many other authorshave argued that tonal harmony should be organizedin a hierarchical way similar to language, leading tonumerous linguistically inspired models since the1960s (Roads 1979). One of the pioneers to propose

    a grammatical approach to harmony was Winograd(1968). More recently, Steedman (1984, 1996) mod-eled the typical twelve-bar blues progression with acategorial grammar; Chemillier (2004) elaborates onthese ideas by transferring them to a CFG. Similarly,Pachet (1999) proposes a set of rewrite rules forjazz harmony comparable to Steedman’s grammar.Pachet furthermore shows that these rules can belearned from chord sequence data in an automated

    De Haas et al.   39

  • 8/17/2019 Automatic Functional Harmonic Analysis

    4/17

    fashion. Additionally, quasi-grammatical systemsfor Schenkerian analysis have been proposed re-cently  (Marsden 2010). Furthermore, Choi (2011)developed a system for analyzing the harmony ofjazz chord sequences; this system identifies commonharmonic phenomena, like secondary dominantsand tritone substitutions, and labels the chords in-volved accordingly. The relation between music andlanguage is not merely a theoretical one; a growingbody of evidence, also from neuropsychology andneuroimaging, suggests that music and languageare more closely related than was previously be-lieved (Patel 2003). An in-depth overview of theanimated debate on the relation between musicand language is beyond the scope of this article,however.

    The generative formalism proposed by Rohrmeier(2007, 2011), which the HarmTrace model drawsextensively from, expands upon many of theseearlier approaches in a number of ways. Rohrmeiergives an encompassing account of how relation-ships in tonal harmony can be modeled using agenerative CFG with variable binding. His gram-mar models form, phrasing, theoretical harmonicfunction (Riemann ca. 1895), prolongation of scale

    degrees (Schenker 1935;  Lerdahl and Jackendoff1996), and modulation. Rohrmeier’s model differsfrom earlier grammatical formalisms in variousways. Steedman’s approach (1984, 1996) uses sevencontext-sensitive rules (with variations) to explainthe structure of blues progressions. Steedman’sgrammar does not go beyond the jazz blues domain,however, and it remains unclear how it could beadapted to support other styles. Rohrmeier’s for-malism also differs from GTTM: The latter aimsat describing the core principles of tonal cognition,and harmony is covered mainly as a prolongationalphenomenon, whereas Rohrmeier’s formalism de-

    scribes the structure of tonal harmony from a music-theoretical perspective with concrete context-freerules. Rohrmeier acknowledges that a full accountof tonal harmony would require a large numberof varying style-specific rules, and his formalismaims to capture only the core rules of Western tonalharmony.

    De Haas et al. (2009) performed a first attemptto implement the ideas of Rohrmeier. Although the

    results were promising, the context-free parsingtechniques used in that work hampered boththeoretical as well as practical improvements. First,a sequence of chords that did not precisely matchthe context-free specification was rejected and noexplanatory information was given to the user.For example, appending one awkward chord to anotherwise grammatically correct sequence of chordsforced the parser to reject the complete sequence, notreturning any partial information about what it hadparsed.

    Second, musical harmony is ambiguous andchords can have multiple meanings depending onthe tonal context in which they occur. This isreflected in all the grammatical models discussedearlier. A major drawback of CFGs is that they arevery limited in ways of controlling the ambiguityof the specification. It is possible to use rule-weightings and to set low weights to rules thatexplain rare phenomena. This allows for orderingthe ambiguous solutions by the total relevance ofthe rules used. This does not overcome the fact that,for some pieces, the number of parse trees growsexponentially as function of the number of inputchords.

    Finally, writing context-free rules by hand isa tedious and error-prone enterprise, especiallybecause the grammatical models can become ratherlarge. For instance, a rule generalizing over anarbitrary scale degree has to be expanded for eachscale degree, I, II, III, etc. Hence, some form ofhigh-level grammar generation system is needed toallow for generalizing over scale degree and chordtype, and to control conditional rule execution.

    Another important model that has influenced thedevelopment of HarmTrace is that of Temperley(2001) and Temperley and Sleator (1999). They givean elaborate formal account of Western tonal music,

    and also provide an efficient implementation. Thisrule-based system, which is partly inspired byGTTM, can perform an analysis of the chord rootsand the key given a symbolic score, but does notformalize the hierarchical relations between chords.Our system continues where Temperley’s left off:Based on the available chord and key information ofthe piece, we model the global and local dependencyrelations between these chords.

    40   Computer Music Journal

  • 8/17/2019 Automatic Functional Harmonic Analysis

    5/17

    Piece 

    Ton 

    "C:maj"

    Dom 

    Dom 

    Dom 

    V 7

    "G:7"

    Sub

    Vd /II ·

    II m

    "D:min"

    Vd /VI ·

    VI m

    "A:min"

    Vd /III ·

    III m

    "E:min"

    VII m

    "B:hdim"

    Sub

    IV 

    "F:maj"

    Ton 

    "C:maj"

    Figure 2. An example of adiatonic cycle-of-fifths

     progression in C major.The leaves represent the

     input chords, using thesyntax of Harte et al.

    ( 2005 ), and the internal nodes denote the harmonic structure. TheVd /X nodes representdiatonic fifth successions.

     The HarmTrace System

    In this section we explain how we model theregularities and hierarchical dependencies of tonalharmony. HarmTrace transfers the ideas developedby De Haas et al. (2009) to a setting based onfunctional programming. Whereas the contributionsof the majority of models we discussed in theprevious section are purely theoretical, we presenta system that can be evaluated empirically and isusable in practice. This comes at a price, however:Our present model does not support full modulation,

    i.e., modulation to every possible key. The modelcan only handle change of mode—going from majorto minor or vice versa—without changing the rootof the key. (We also use the term   parallel keysto describe this relationship.) As a consequence,this requires the model to have information aboutthe key of the piece. Also, because we mainly usejazz-oriented input data in this article, we alsoinclude some specifications that describe typicalphenomena in jazz harmony. Figure 2 shows anexample analysis as produced by HarmTrace. Thechord labels that were used as input are the leavesof the tree, and the internal nodes represent the

    harmonic relations between the chords.Music, and harmony in particular, is intrinsi-

    cally ambiguous; certain chords can have multiplemeanings within a tonal context. Although a modelof tonal harmony should reflect some ambiguity,defining many ambiguous specifications can makethe number of possible analyses grow exponen-tially for certain chord progressions. In most ofthe ambiguous cases it is clear from the context

    which of the possible solutions is the preferred one,however. Hence, we can select the favored analysisby constraining the application of the specificationleading to the undesired analysis. We are able to doso because we rely on strongly typed data structures,which allow us to formulate our rules in a veryprecise manner. In cases where it is less clear fromthe context which solution is preferred, we accept asmall number of ambiguous analyses.

    The HarmTrace system explores the relationsbetween (generalized) algebraic data types andcontext-free production rules. A CFG defines alanguage: Given a set of production rules and a setof words (or tokens), it accepts only combinations oftokens that are valid sequences of the language. Thenotion of an algebraic datatype is central in Haskell.Similarly to a CFG, a datatype defines the structureof values that are accepted. Hence, a collection ofdatatypes can be viewed as a very powerful CFG:The type-checker accepts a combination of valuesif their structure matches the structure prescribed bythe datatype, and rejects this combination if it doesnot. Within HarmTrace, the datatypes representthe relations between the structural elements intonal harmony, and the chords are the values. An

    important difference between a CFG and a Haskelldatatype, however, is that datatypes provide moremuch modeling freedom and control, especiallythe generalized algebraic datatypes (Schrijverset al. 2009) that we use. These datatypes allow us torestrict the number of applications of a specification,constrain the conditions for application, and orderthe specifications by their importance. Furthermore,they allow for the definition of specifications thatonly apply to certain keys or modes, the exclusion ofthe application of transposition functions to specificscale degrees (e.g., Spec. 18, described later), and thepreference of certain specifications over others. For

    technical details, we refer to Magalh ães and De Haas(2011). The source code is available online athttp://hackage.haskell.org/package/HarmTrace-0.6.

    A Model of Tonal Harmony

    We now elaborate on how our harmony datatypesare organized. Haskell knowledge is not required to

    De Haas et al.   41

  • 8/17/2019 Automatic Functional Harmonic Analysis

    6/17

    understand our model: We use a simplified syntaxto describe the datatype specifications that is in-spired by the syntax used to describe CFGs. Usersof HarmTrace need only know Haskell if they wishto change the model in any way; simply usingthe current model to obtain analyses can be donewithout any Haskell knowledge. In the followingsubsections we group related datatype specifications(abbreviated as Spec.), and explain their musicalinterpretation and background. First, we introducea variable  M for the mode of the key of the piece,which can be major or minor. The mode variableis used to parametrize all the specifications of ourharmonic datatype specification; some specifica-tions hold for both modes (inidicated byM), whereasother specifications hold only for the major or minormode (respectively indicated by “Maj” and “Min”).Similarly to a CFG, we use a   |  to denote alterna-tives, and a  +  to represent optional repetitions of adatatype.

    Functional Categories

    1.   Piece M  →  Func +M

    2.   Func M  →  Ton M   |  Dom M   M ∈ {Maj, Min}

    3.   Dom M  →  SubM   Dom M

    Spec. 1–3 define that a valid chord sequence, Piece M,consists of at least one and possibly more func-tional categories. A functional category classifieschords as being part of a tonic (Ton M), dominant(Dom M), or subdominant (SubM) structure, wherea subdominant structure must always precede adominant structure. These functions constitutethe top-level categories of the harmonic analy-sis and model the global development of tonaltension: A subdominant builds up tonal tension,

    the dominant exhibits maximum tension, and thetonic releases tension. The functional categoriescapture the idea proposed by Riemann (ca. 1895)that every chord within a tonality can be reducedto one of these harmonic functions. The order ofthe dominants and tonics is not constrained bythe model, and they are not grouped into largerphrases.

    From Functions to Scale Degrees

    4.   Ton Maj  →  I Maj  |  I MajIV MajI Maj  |  III mMaj

    5.   Ton Min  →  I m

    Min   |  I m

    MinIV mMinI 

    mMin  |  III Maj

    6.   Dom M  →  V 7M

     |  V M

    7.   Dom Maj  →  VII mMaj   M ∈ {Maj, Min}

    8.   Dom Min  →  VII Min9.   SubM  →  II 

    mM

    10.   SubMaj  →  IV  Maj  |  III mMajIV Maj

    11.   SubMin  →  IV mMin  |  III MinIV Min

    Spec. 4–11 translate the tonic, dominant, andsubdominant datatypes into scale-degree datatypes.Apart from a few minor differences, Spec. 4–11follow Rohrmeier’s (2007) model. A tonic translatesto a first degree, a dominant to a fifth degree, and thesubdominant to a fourth degree in both major andminor keys. We denote scale-degree datatypes withRoman numerals, but because our model jointlyspecifies datatypes for major as well as minor mode,we deviate from notation that is commonly usedin classical harmony and represent scale degreesas intervals relative to the diatonic major scale.For example,   III m unequivocally denotes the minor

    chord built on the note a major third interval abovethe key’s root and does not depend on the mode ofthe key. Similarly, a III  denotes a major chord builton the root a minor third interval above the key’sroot.

    A scale degree datatype is parametrized by amode, a chord class, and the scale degree, i.e.,the interval between the chord root and the keyroot. The chord class categorizes scale degrees asone of four types of chords (denoted in lowercasewith superscripts) and is used to constrain theapplication of certain specifications, e.g., Spec. 16–17(defined later). The four classes are major (no

    superscript), minor (m), dominant seventh (7), anddiminished (0). Chords in the minor class containa minor or diminished triad and can have possiblyaltered or non-altered additions, except for thediminished seventh. Chords categorized as majorcontain a major triad and can be extended bynon-altered additions, with the exception of thedominant seventh chord (with additions). Chords

    42   Computer Music Journal

  • 8/17/2019 Automatic Functional Harmonic Analysis

    7/17

    of the dominant class have a major triad and aminor seventh, or an augmented triad. Chords inthe dominant class can be extended with alteredor non-altered notes. Finally, the diminished classcontains only the diminished seventh chord. Theusage of chord classes allows us to define certainspecifications that only hold for dominant chords,whereas other specifications might hold only forminor chords, etc.

    Tonics can furthermore initiate a plagal cadence(Spec. 4–5). We deliberately chose to model theplagal cadence with scale degrees and not withSub   and   Ton  because this reduces the number ofpossible analyses. Also a  SubM  can translate intoa   II m

    M because of its preparatory role, and the

    dominant translates into the seventh scale degree,VII 

    mMaj  (VII Min in minor). Similarly, we could have

    chosen to model the  SubM to translate also to  VI mMaj

    (VI Maj in minor). We chose to solve this by creatingspecifications for chains of diatonic fifths instead(Spec. 18–19; see, for instance, Figure 2).

    The Ton M translating into III mMaj (III Min in minor)

    is perhaps the most unexpected transformation (andwe deviate from Rohrmeier’s 2007 model here).Often the third degree can be explained as either a

    preparation of a secondary dominant (Spec. 17), asbeing part of diatonic chain of fifths (Spec. 19), or assupporting the subdominant (Spec. 10–11). In certainprogressions, however, it cannot be explained byany of these specifications, and is best assigned atonic function because it has two notes in commonwith the tonic and does not create strong harmonictension.

    From Scale Degrees to Chords

    12.   I Maj  →  "C:maj" |  "C:maj6" |  "C:maj7" |"C:maj9" |  . . .

    13.   I m

    Min  →  "C:min" |  "C:min7" |  "C:min9" |"C:min(13)" |  . . .

    14.   V 7Maj  → "G:7" |  "G:7(b9,13)" |"G:(#11)" |  "G:7(#9)" |  . . .

    15.   VII 0M

     →  "B:dim(bb7)"

    Finally, scale degrees are translated into theactual surface chords, which are used as input

    for the model. The chord notation used is that ofHarte et al. (2005). The conversions are trivial andillustrated by a small number of specifications above,but the model accepts all chords in Harte’s syntax.The model uses a key-relative representation; inSpec. 12–15 we used chords in the key of C. Hence,a   I Maj   translates to the set of C chords with a

    major triad, optionally augmented with additionalchord notes that do not make the chord minor ordominant. Similarly, V  7Maj translates to all G chords

    with a major triad and a minor seventh, etc. Tosimplify the treatment of chords differing only by

    these additional chord notes, we cluster chordswith the same class and same scale degree (e.g.,"C:min7" "C:min9") in one datatype.

    Secondary Dominants

    16.   XCM

     →  V /X7M XC

    M  C ∈ {∅, m, 7 , 0}

    17.   X7M

     →  V /XmM X

    7M

      X ∈ {I , II , II , . . . , VII }

    Besides these basic elements of tonal harmony,we distinguish various scale-degree substitutionsand transformations. For this we introduce thefunction   V /X  which transposes an arbitrary scale

    degree  X  a fifth up. Herewith, Spec. 16 accountsfor the classical preparation of a scale degree by itssecondary dominant, stating that every scale degree,independently of its mode, chord class, and rootinterval, can be preceded by a chord of the dominantclass, one fifth up. In the case of chord class, wedenoted the independence of a chord class withthe chord class variable  C. The empty symbol,  ∅,represents the major class (no superscript). (Notethat in all specifications that contain transpositionfunctions, terms like   Y /XC

    M  should always be

    interpreted as (Y /X)CM

    .) Similarly, every dominantscale degree can be prepared with the minor chord

    one fifth above (Spec. 17). These two specificationstogether allow for the derivation of the typicaland prominently present ii-V-I progressions in jazzharmony. (The ii-V-I progression is a very commoncadential chord progression in jazz harmony, butit also occurs in other musical genres. The I-chord can practically be an arbitrary chord in asequence which is preceded by its relative secondary

    De Haas et al.   43

  • 8/17/2019 Automatic Functional Harmonic Analysis

    8/17

    dominant a fifth interval up, the V, and its relativesubdominant another fifth interval up, the ii.)The explicit annotation of these structures isvery common in jazz analysis and education (see,for instance, Jaffe 1996), and also Rohrmeier (2007,2011) incorporates Spec. 16 in his model. Spec. 16–17interfere with Spec. 4–11, however, causing multipleanalyses. Because we prefer, e.g., a   II m,   V 7, and   I to be explained as   Sub,  Dom , and  Ton , we constrainthe application of Spec. 16 and 17 to the cases whereSpec. 4–11 do not apply. The rationale behind thischoice is more of a pragmatic than of a musicalnature, and the user of the model might also decideon a different specification preference.

    Diatonic Chains of Fifths

    18.   XmMaj  →  Vd /XmMaj   X

    mMaj

    19.   XMin  →  Vd /XMin   XMin

    The model also accounts for the diatonic chains offifths in major (Spec. 18) and minor (Spec. 19) keys.These diatonic-chain specifications are necessaryto explain the typical cycle-of-fifths progressions:I IV VII 

    mIII 

    mVI 

    mII 

    mV 7 I   (see Figure 2 for the

    major case, as well as the  Autumn Leaves  examplein the next section). These strong chord progressionsare very commonly found throughout Western tonalmusic. Also, Rohrmeier’s (2011) model has a rulededicated specifically to this progression. To reducemultiple ambiguous solutions, we constrain themajor-key specification to apply only to the minorchords, because   I ,   IV  , and   V 7 translate directly toTon ,  Sub , and  Dom , respectively. Similarly, Spec. 19captures the same phenomenon in a minor key.Here, we restrict the application of the specificationonly to the major chords because, again, I m, IV m, andV 7 translate directly to Ton ,  Sub , and  Dom  in minor.

    We implemented one exception to the diatonicminor specification that allows the VI   to precedethe   II m in minor. Here, the major chord precedes aminor chord. See the E Am75 in the analysis of

     Autumn Leaves, later in this article.

    Tritone Substitution

    20.   X7M

     →  V /X7M

    The harmony model in HarmTrace allows forvarious scale-degree transformations. Every chord ofthe dominant class can be transformed into its tri-tone substitution with Spec. 20. This specificationuses another transposition function  V /X  whichtransposes a scale degree  X  a diminished fifth—atritone—up (or down). The tritone substitution spec-ification allows for the derivation of progressionswith a chromatic baseline, e.g., Am G7 G, and isvery common in jazz harmony (see, for instance,Jaffe 1996). Also, a tritone specification was earlierused in a similar model in De Haas et al.  (2009).Because we want the application of the Spec. 16–20 to terminate, we limit the number of possiblerecursive applications of these rules (see the Parsingsection).

    Diminished Sevenths

    21.   X0M

     →  III /X0M

    22.   X7M

     →  I I 79/X0M

    Diminished seventh chords can have various rolesin tonal harmony. An interesting characteristic ofthese chords—consisting only of notes separated by

    minor third intervals—is that they are completelysymmetrical. Hence, a diminished seventh chordhas four enharmonic equivalent chords that can bereached by transposing the chord by a minor thirdwith the transposition function  III /X  (Spec. 21).In general, we treat diminished seventh chords asdominant-seventh chords with a   9 and no rootnote, which is a common interpretation of thischord (Saslaw 2013). For instance, in a progressionAm7 A0 G7, the A0 closely resembles the G79,because a G79 chord consists of G, B, D, F, andA, and an A0 chord consists of A, B, D, andF. This similarity is captured in Spec. 22, where

    II /X  transposes a scale degree one semitone up.Similarly, by combining secondary dominants(Spec. 16) with Spec. 22, e.g., F E0 (  ≈  D79) G, andan application of Spec. 21, e.g., F F0 (≈E0) G, wecan account for most of the ascending diminishedchord progressions. Within harmony theory, thisphenomenon is usually labeled as VII /X, where F0

    would be the   VII /V   (in C major) in the previousexample. Because our model can explain it without

    44   Computer Music Journal

  • 8/17/2019 Automatic Functional Harmonic Analysis

    9/17

    a separate   VII /X  specification, there is no need toadd one.

    Parallel Keys and the Neapolitan

    23.   Func Maj  →  Func Min

    24.   Func Min  →  Func Maj

    25.   SubMin  → II Min

    We support borrowings from the parallel key bychanging the mode but not the root of the key inthe  Func M  datatype (Spec. 23 and 24). Although theparallel keys are often considered rather distantlyrelated (there is a difference of three accidentals inthe key signature), borrowing from minor in majoroccurs frequently in jazz harmony, and sometimesin classical music. These specifications account,for instance, for the picardy third—ending a minorpiece on a major tonic. The actual implementationof Spec. 23 and 24 differs marginally to overcomeendless recurring transitions between major andminor. Finally, the Neapolitan chord   II Min   iscategorized as being part of a   SubMin   structure(Spec. 25), which is also reachable in a major keythrough Spec. 23. Although it might be considered

    an independent musical event, it often has asubdominant function (Drabkin 2013).The datatype specifications that we have

    presented in this section match the Haskell codeclosely. Nevertheless, to maintain clarity, someminor implementation details were omitted; thesecan be found in the real datatype specifications ofthe model, i.e., the Haskell code.

    Modulation

    HarmTrace supports chord borrowing from parallel

    keys, and its secondary dominant specificationscan be used to explain local key changes, but itdoes not support modulating to all possible keys.Although adding a modulation specification to themodel is straightforward, this would quickly lead toan avalanche of ambiguous analyses. For example,all specifications of the model are currentlyparametrized by a mode, which can be major,minor, or mode agnostic. Extending this parameter

    to contain the key of the piece, in line withRohrmeier’s (2011) model, is problematic: even witha constrained modulation specification that allowsmodulation only to specific other keys, and restrictsthe number of modulations, the total number ofambiguous analyses quickly explodes, given therules of the previous section. If a user wishes tohave such a modulation specification (and this isvery well possible from a specification point ofview), we recommend using a much smaller model.Such a model should not, for instance, containrules for explicitly labeling chains of secondarydominants, but a secondary dominant would beanalyzed as a local modulation (like Schenkeriantonicization). Even with a much smaller model,however, keeping the number of different analysesunder control might be challenging. Hence, wechose to first explore the usability of HarmTracewithout modulation, keeping the model fast andflexible.

    Another, more practical, solution is using externalkey information, either obtained from key signaturesin the score, or by applying an automatic key-findingalgorithm. Within the audio domain, key-findingalgorithms have improved considerably in the

    last few years, providing annotations of both theglobal key and key changes. Within the symbolicdomain, the key is often annotated explicitlyor can be derived using symbolic key-findingalgorithms (e.g.,  Temperley 2001). Informationabout the key can then be used to segment thechord sequences into sections that contain onlya single key, and HarmTrace can be applied tothese sections individually. For instance, in earlierwork we applied HarmTrace to improve harmonicsimilarity estimation, using information aboutkey that was available in the data (De Haas et al.2011). We have also used HarmTrace for a chord

    transcription task, using a key-finding algorithm(De Haas, Magalh ães, and Wiering 2012). The key-finding algorithm used in this latter work wassimilar to that used by  Temperley  (2001, ch. 7).Various different approaches to key finding exist(for a fairly recent overview, see Noland and Sandler2009). These concrete applications of HarmTraceshow that the availability of key data does not haveto hamper practical use.

    De Haas et al.   45

  • 8/17/2019 Automatic Functional Harmonic Analysis

    10/17

    Parsing

    Once we have a formal specification as a datatype,the next step is to define a parser that transformstextual chord labels into values of our datatype.Writing a parser that parses labels into our datatypewould normally mean writing tedious code thatclosely resembles the datatype specification. InHaskell however, we can use datatype-generic pro-gramming techniques (Jeuring et al. 2009) to avoidwriting most of the repetitive portions of the code.(These techniques are not to be confused with regu-lar polymorphism, as in Java generics.) Moreover,we derive not only the parser automatically, butalso a pretty-printer for displaying the harmonyanalysis in tree form, and functions for comparingthese analyses. This makes the development andfine-tuning of the model much easier, as only thedatatypes have to be changed, and the code adaptsitself automatically. The technical details of theimplementation of our model, and of the generic-programming techniques we use, are covered in anearlier publication (Magalh ães and De Haas 2011).

    Because music is an ever-changing, culturallydependent, and extremely diverse art form, we

    cannot hope to model all valid harmonic relations inour datatype. Furthermore, song data may containmistakes or mistyped chords, perhaps featureextraction noise, or malformed data of dubiousharmonic validity. In HarmTrace we use a parsinglibrary featuring error-correction: Chords that donot fit the structure are automatically deletedor preceded by inserted chords, according to thedatatype structure (Swierstra 2009).

    The error-correction process uses heuristics tofind a good parse tree in a reasonable amount oftime. When faced with a chord that does not fitthe harmony model, it will consider all possible

    combinations of deletion and insertion of chords (upto a fixed depth of three steps) to adapt the chordsequence to the model. In this way, the simplestcorrections (involving the fewest insertions or dele-tions) are chosen. We could also assign different coststo each specification, in order to prefer some rulesover others. In practice, we did not find this neces-sary. The order in which the rules are specified alsomatters, as earlier rules take precedence over laterrules; we use this fact to guidethe correction process.

    For most songs, parsing proceeds with no correc-tions, or only very few. Songs with a very high errorratio denote multiple modulations, bad input, or awrong key assignment. Note that, depending on theseverity of “unexpectedness” of a chord, there mightbe multiple error-corrections necessary to create avalid analysis (e.g., one deletion and two insertions).

    In our model, one particular parameter has alarge influence on the parsing and error-correctionprocess. This parameter controls the number ofrecursive applications of the specifications forsecondary dominant and the like (Spec. 16–20). Itmust be set carefully, because setting it to a very lowvalue will lead to bad analyses, and setting it to a highvalue will make the internally generated model verylarge, resulting in increased error-correction timesand often sub-optimal error-correction solutions.For the examples and results in this article we haveused values between five and seven.

    Example Analyses

    In this section we demonstrate the analytic powerof the HarmTrace system. The input presented to

    HarmTrace consists of a sequence of plain-text chordlabels in the syntax defined by Harte et al. (2005), andthe output consists of a parse tree similar to thoseoften used in natural language processing. In thesetrees, the input chord labels are the leaves, whichare subsequently grouped into scale degrees, scale-degree transformations, and functional categories,and finally collected in a Piece  node, as prescribedby the rules of the model. The notation used inthe parse trees is identical to the notation used todescribe the datatype specifications in the previoussection. Musical harmony can be very ambiguous,and sometimes multiple analyses are defensible.

    A strength of HarmTrace is that, by changing thespecifications in the previous section, it can beeasily adapted to meet the musical intuitions of itsusers.

    We start by analyzing the B section of the Autumn Leaves   jazz standard as found in   TheReal Book  (Sher 1988). The parse tree of this piecein the key of G minor is depicted in Figure 3.Within the piece, the three A0 D7 Gm sequencestranslate into subdominant, dominant, and tonic

    46   Computer Music Journal

  • 8/17/2019 Automatic Functional Harmonic Analysis

    11/17

    Piece 

    Ton 

    I m

    Gm

    Dom 

    Dom 

    V 7

    D713

    Sub

    II m

    Am75

    Vd /II ·

    VI 

    E∆

    V /VI 7

    III 7

    B7

    V /III m

    VII m

    Fm7

    V /VII 7

    IV 7

    C9

    Ton 

    I m

    Gm7

    Dom 

    Dom 

    Dom 

    V 7

    D7

    Sub

    II m

    Am75

    Vd /II ·

    VI 

    E∆

    Vd /VI ·

    III 

    B∆

    V /III 7

    VII 7

    F7

    Sub

    IV m

    Cm7

    Ton 

    I m

    Gm7

    Dom 

    Dom 

    V 7

    D7

    Sub

    II m

    Am75

    Figure 3. The harmonicanalysis of the B section of the jazz standard AutumnLeaves, as derived by HarmTrace. Forconvenience, we left outthe mode subscript Min

    and printed the chord labels as commonly found in lead sheets. The key of the piece is G minor. The denotes an added majorseventh.

    Figure 3

    Piece 

    Dom 

    Dom 

    Dom 

    Dom 

    C6

    Sub

    IV 

    B

    V /IV 7

    I 7

    F7

    V /I m

    V m

    Cm

    Sub

    IV 

    B

    V /IV 7

    II 79/I 7

    II 0

    III 0

    A0

    Sub

    IV 

    B

    Ton 

    F

    Dom 

    C

    V /V 7

    II 79/II 7

    III 0

    V 0

    B0

    Ton 

    F

    Dom 

    Dom 

    C

    Sub

    II m

    Gm7

    Vd /II ·

    VI m

    Dm

    Ton 

    F

    Figure 4. The automaticanalysis of the first two

     phrases of J. S. Bach’s Ichdank’ dir schon durchdeinen Sohn, BWV 349, inthe key of F major.

    Figure 4

    categories (Spec. 9, 6, and 5, respectively), formingii-V progressions, towards the tonic of the piece.The second and third  Dom  branches of  Piece  displaydifferent types of descending fifth movements,both of which build up tension towards a D7: Theprogressions from F to B   are labeled either as asecondary dominant or as a diatonic descendingfifth, depending on whether the chord is dominant

    or major (Spec. 16 or 19). In the current analysis,the Cm chord is viewed only as a subdominant ofthe Gm chord. Additionally, the Cm could havebeen seen as being part of a ii-V-I motion to the E

    chord. HarmTrace misses this additional analysis,however, because the maximal number of recursiveapplications has been reached.

    Although the model has a bias towards a jazzrepertoire, it can be used to analyze Bach chorales aswell. In Figure 4 we present the HarmTrace analysis

    Piece 

    Dom 

    V 7

    G7

    Ton 

    I m

    Cm6

    Dom 

    Dom 

    Dom 

    V 7

    G759

    Sub

    II m

    Dm75

    Sub

    II 

    D∆

    V /II 7

    VI 7

    A7

    V /VI m

    III m

    Em7

    Ton 

    I m

    Cm6

    Dom 

    Dom 

    Dom 

    V 7

    G759

    Sub

    II m

    Dm75

    Sub

    IV m

    Fm7

    Ton 

    I m

    Cm6

    Figure 5. An analysis of 

    Blue Bossa in C minor.

    Figure 5

    of the first nine measures of Bach’s harmonizationof the chorale melody Ich dank’ dir schon durchdeinen Sohn. The key of the piece is F major. Afteran introduction of the tonic, a diatonic chain offifths prepares the dominant, C, which subsequentlyresolves to the tonic. The next branch preparesa C with a B0, which is   VII /V . As explained inthe previous section, the B0 is enharmonicallyequivalent to A0 (I I I 0) which is very similar to

    a G79 (denoted by   I I 79/II , Spec. 22), which is inturn the V /V , preparing the C chord in the key of F.The final branch creates some harmonic movementaround the B  by preparing the second B  with aVII /IV . The   VII /X  derivation is identical to thisone, but transposed down a whole step. The fragmentconcludes with a descending fifth preparation of thesubdominant, followed by the dominant.

    In Figure 5 we show the analysis of anotherwell-known standard, Blue Bossa. The progression

    De Haas et al.   47

  • 8/17/2019 Automatic Functional Harmonic Analysis

    12/17

    Piece 

    Ton 

    C

    Dom 

    G

    V /V 7

    (II   9)/II 7

    III 0

    IV 0

    F0

    V /III m

    VI m

    Am

    V /VI 7

    III 7

    E7

    Dom 

    Dom 

    G

    V /V 7

    II 7

    D

    (a) (b)

    7

    Sub

    IV 

    F

    V /IV 7

    I 7

    C7

    Ton 

    C

    Figure 6. Two analyses of a phrase from  Tebe Poem by Dmitry Bortniansky (1751–1825). We comparean analysis adapted fromRohrmeier ( 2011 ),appearing above the score

    (a), with an analysis produced by HarmTrace(b). The nodes labeled TR

     in Rohrmeier’s analysis indicate “tonal regions,” aconcept not included inour model.

    Figure 6

    Piece 

    Ton 

    B6

    Dom 

    V 7

    F7

    V /V 7

    II 7

    C7

    V /II m

    VI m

    Gm6Gm7Gm∆Gm

    V /VI 7

    III 7

    D7

    Dom 

    Dom 

    V 7

    F7

    V /V 7

    II 7

    C7

    V /II m

    VI m

    Gm7

    Sub

    IV 

    E6

    V /IV 7

    I 7

    B7

    V /I m

    V m

    Fm7

    Ton 

    B6

    Dom 

    V 7

    F7

    V /V 7

    II 7

    C7

    V /II m

    VI m

    Gm6Gm7Gm∆Gm

    V /VI 7

    III 7

    D75

    Figure 7. An excerpt of theanalysis of  It Don’t Mean aThing (If It Ain’t Got ThatSwing).

    Figure 7

    starts by introducing the tonic, Cm, followed by aperfect cadence. The B-part displayed in the second

    Dom  branch shows a ii-V-motion to the NeapolitanII   (Spec. 25) and is followed by a ii-V-I to Cm.

    Figure 6 displays the score and two analyses ofan extract from Tebe Poem, by Dmitry Bortniansky.The analysis in Figure 6a is the theoretical anal-ysis proposed by  Rohrmeier (2011). Although thenotation used by Rohrmeier differs slightly fromthe notation used in this article, the analyses areclearly similar. There are also some differences.

    Rohrmeier connects the tonic, dominant, and sub-dominant nodes in tonal regions whereas HarmTrace

    (see Figure 6b) does not. We elaborate on this issuein the Discussion section. Another difference inderivation is that because we treat the F0 (≈D79) asa  V /V , the E7 and Am are analyzed as being part ofa larger chain of fifths.

    In Figure 7 we show the HarmTrace analysis ofthe jazz standard It Don’t Mean a Thing (If It Ain’tGot That Swing). The analysis shows how similarGm chords are grouped under one   VI m node. It

    48   Computer Music Journal

  • 8/17/2019 Automatic Functional Harmonic Analysis

    13/17

    Piece 

    Dom 

    Dom 

    Dom 

    V 7

    F7

    Sub

    II m

    Cm7

    V /II 7

    VI 7

    G75

    Sub

    II m

    Cm7

    V /II 7

    VI 7

    G75

    V /VI 7

    IV

    Deleted

    E∆

    III 7

    D75

    Ton 

    B∆

    Piece 

    Ton 

    B∆

    Dom 

    Dom 

    V 7

    F7

    Sub

    II m

    Inserted

    Vd /II m

    VI m

    Gm6

    V /VI 7

    III 7

    D7

    V /III m

    VII m

    Am75

    Vd /II m

    VI m

    Gm6

    V /VI 7

    III 7

    D7

    V /III m

    VII m

    Am

    (a) (b)

    75

    Figure 8. Two examplesthat illustrate errorcorrection: excerpts fromthe jazz standard SomedayMy Prince Will Come (a)and the B section of thestandard There Is NoGreater Love (b).

    furthermore illustrates how the Sub  and  Dom  nodesare prepared by chains of secondary dominants.

    We conclude this section with two small exam-ples that contain error corrections. These correctionsshould not be interpreted as corrections of musicalerrors, but they illustrate the behavior of HarmTracein cases where harmonies cannot be explained bythe model. The example in Figure 8a is an excerpt

    of the jazz standard Someday My Prince Will Come,Figure 8b is taken from the jazz standard There IsNo Greater Love. In Someday My Prince Will Come,the model cannot explain the E where it occurs.Because the D7 can immediately resolve to the G7,the parser deletes the E. The model specificationdoes not allow a   Sub  to translate into a   VI m scaledegree. Adding such a specification would cause alarge number of ambiguous solutions, if the diatonicfifth specification (Spec. 19) were not constrained.Therefore, in Figure 8b, the model needs a diatonicchain of fifths to explain the   VI m and the parsersolves this by inserting a  II m. Corrections like the

    ones in Figure 8 represent typical examples of errorcorrections in HarmTrace.

    Experimental Results

    To demonstrate that HarmTrace can be efficientlyand effectively used in practice, we evaluate itsparsing performance on two chord sequence data

    sets: a small data set we have used in earlier work(De Haas et al. 2009), and a larger data set (usedin   De Haas, Veltkamp, and Wiering 2013). Werefer to these two data sets as   small  and   large,respectively. The small data set contains 72 chordsequences that describe mainly jazz pieces. Thelarge  data set contains 5,028 chord sequencesthat describe jazz, Latin, and pop pieces, as well

    as a few classical works. Both data sets consistof textual chord sequences extracted from user-generated Band-in-a-Box files that were collectedon the Internet. (Band-in-a-Box [Gannon 1990]is a commercial software package that generatesaccompaniment, given a chord sequence.) For theextraction of the plain-text chord labels we haveextended software developed by Mauch et al. (2007).To our knowledge, the  large data set is the largestdata set of symbolic chord sequences available tothe research community, as of June 2013.

    The  small data set contains a selection of piecesthat were checked manually and “make sense”

    harmonically, and the large data set includes manysongs that are harmonically atypical. This is becausethe files are user-generated, so they contain peculiarand unfinished pieces, wrong key assignments, andother errors; it can therefore be considered “realworld” data. Also, the   large  data set containspieces that modulate, and even some pieces thatmight be considered atonal (e.g., John Coltrane’sGiant Steps). We deliberately chose to use a “real

    De Haas et al.   49

  • 8/17/2019 Automatic Functional Harmonic Analysis

    14/17

    Table 1. Parsing Results

    Data Set Deletions Insertions Corrections Chords Parse Time Total Time

    small   0.83 2.79 3.63 42.49 10.00 0.72large   3.38 9.85 13.24 62.05 76.53 384.81

    Numbers of deletions, insertions, and total corrections per song; total number of chords per song; parsing time per song (in msec);

    total parsing time (in sec).

    world” data set to show that HarmTrace is robustagainst noisy data, offers good performance in termsof parsing speed, and still delivers analyses thatmake sense.

    Parsing Results

    When parsing the data we measure the numberof parsed chords, deleted chords, and insertedchords, as well as parsing time. These numbers aresummarized in Table 1.  Both runs were performedon the same Intel Core 2 6600 machine runningat 2.4 GHz with 3 GB of random-access memorycompiled using GHC version 7.0.3.

    On the   small  data set the HarmTrace modelperforms very well. The songs are parsed quicklyand, on average, fewer than one chord per songis deleted. Also, fewer than three insertions arenecessary, on average, for a piece to parse. It wouldhave been possible to adapt the model in such waythat the   small  data set would parse without anyerrors, as was done by De Haas et al. (2009). We choseto accept this small number of error corrections andkeep our grammar small and easy to comprehend.The data set is parsed within a second.

    For the   large   data set, the parsing time persong increases considerably, due to a larger number

    ambiguous solutions and increased error-correction.The 5,028 chord sequences are still parsed rea-sonably quickly, in 6 min 25 sec. The number oferror corrections increases considerably, but theparser never crashes or refuses to produce validoutput. The higher number of error correctionsis expected, because this data set contains songswith modulations, atonal harmonies, and a varietyof errors. Still, HarmTrace keeps the number of

    deleted chords under 6 percent of the total chordsparsed.

    When we compare the parsing results of thesmall  data set with the results of an older, Java-based parser (De Haas et al. 2009), we notice thatHarmTrace is much faster. The Java-based parsertook more than 9 min to parse this data set. Wecannot compare the parsing results of the   largedata set because the majority of the pieces arerejected by the grammar used by the older parser.This emphasizes how important the error-correctionprocess is. Even with error correction, HarmTraceparses the  large data set faster than the Java-basedparser parses the  small data set.

    Discussion

    We have presented HarmTrace, a system that au-tomatically analyses sequences of musical chordlabels. Implementing our system in Haskell hasproven to be a profitable decision, given the advan-tages of error-correcting parsers and datatype-genericprogramming. We have shown that HarmTrace canhandle corpora of considerable size, parses chordprogressions quickly, and is robust against noisydata. HarmTrace currently does not support fullmodulation, but it can explain changes between

    parallel major and minor keys. That the lack offull modulation does not have to hamper prac-tical application is shown by the application ofHarmTrace to practical MIR tasks like automaticharmonic-similarity estimation, chord transcrip-tion, and automatic harmonization. Although themodel presented has a bias towards jazz harmony,we have shown that it can be used to analyze someclassical works as well.

    50   Computer Music Journal

  • 8/17/2019 Automatic Functional Harmonic Analysis

    15/17

    If we compare HarmTrace to other models oftonal harmony, we notice various differences.The theoretical work of   Steedman   (1984), forinstance, focuses only on the structure of the (veryparticular) style of twelve-bar blues, whereas ourmodel aims to formalize the core of tonal harmonywith a bias towards jazz harmony, including thetwelve-bar blues. Although our work draws onthe work of   Rohrmeier   (2007,   2011), there arealso considerable contrasts. The most pronounceddifference from Rohrmeier’s CFG is that the latterfeatures modulation and tonicization. By tonicizingto a local tonic, chords are analyzed with respectto that local tonic. As a consequence, his approachcan explain secondary dominants by tonicization,whereas the HarmTrace model uses a more jazz-oriented approach to harmony by identifying ii-V-Imotions, (e.g., in Figure 3). For instance, in aprogression in the key of C major, after movingto the subdominant, F can be viewed as a localtonic, allowing the derivation of Gm and C aslocal subdominant and local dominant. A benefit ofRohrmeier’s approach is that it is also possible toderive B C as a local subdominant/dominant pair.A specification for this would be easy to add to the

    HarmTrace model. Implementing both tonicizationsand secondary dominants, as Rohrmeier suggests,would be problematic, however, because bothrules explain the same phenomena. After all, thepreparation of F by C can be explained both bythe tonicization rules as well as by the secondarydominant rules. This would inevitably lead to anexplosion of ambiguous solutions for a harmonyprogression featuring secondary dominants.

    Another difference is that Rohrmeier groupstonics and dominants into higher-order phrases orfunctional regions. He acknowledges that theserules are highly ambiguous, but chooses to keep

    them for theoretical completeness. The problemis that the harmonic information alone generallydoes not provide enough information for determin-ing phrase boundaries. For instance, it is unclearwhether   Ton Dom Ton   represents a half-cadencephrase followed by a tonic (Ton Dom ) (Ton ), or anintroduction of the tonic followed by a perfect-cadence phrase (Ton ) (Dom Ton ). We believe thatsuch clusterings should be done in a post-processing

    step, based on metrical positions and phrase-lengthconstraints.

    On the whole, when we compare HarmTrace toother models of tonal harmony, we observe thatmost models remain purely theoretical. This isregrettable, because although theoretical work canyield valuable insights, having an implementationof a model allows it to be evaluated empiricallyand used in practice. HarmTrace has been clearlydemonstrating its practical use by its application toharmonic similarity estimation, chord recognition,and automatic harmonization. As we have seen inthis article, it may take state-of-the-art programmingtechniques to create a model that is maintainable,has expressive power, and yet remains fast. Weare confident that HarmTrace will contribute tonew insights in the modeling of harmonic analysis,and that it will prove useful in practical musicapplications.

     Acknowledgments

    W. Bas De Haas was funded by the NetherlandsOrganization for Scientific Research, NWO-VIDI

    grant 276-35-001. José Pedro Magalh ães was sup-ported by EPSRC grant EP/J010995/1. Frans Wieringand Remco C. Veltkamp are supported by the FESproject COMMIT/. We thank Martin Rohrmeier forthe inspiring discussions and ideas about modelingharmony. We thank Anja Volk and two anonymousreviewers for comments on a draft version of thisarticle.

    References

    Chemillier, M. 2004. “Toward A Formal Study of JazzChord Sequences Generated by Steedman’s Grammar.”Soft Computing  8(9):617–622.

    Choi, A. 2011. “Jazz Harmonic Analysis as OptimalTonality Segmentation.”  Computer Music Journal35(2):49–66.

    Chomsky, N. 1957.   Syntactic Structures. The Hague:Mouton.

    Clarke, E. 1986. “Theory, Analysis, and the Psychologyof Music: A Critical Evaluation of Lerdahl, F. and

    De Haas et al.   51

    http://www.mitpressjournals.org/action/showLinks?system=10.1162%2FCOMJ_a_00056http://www.mitpressjournals.org/action/showLinks?system=10.1162%2FCOMJ_a_00056

  • 8/17/2019 Automatic Functional Harmonic Analysis

    16/17

    Jackendoff, R.,  A Generative Theory of Tonal Music.”Psychology of Music 14(1):3–16.

    Downie, J. S. 2003. “Music Information Retrieval.” Annual Review of Information Science and Technology 

    37(1):295–340.Drabkin, W. 2013.   Neapolitan Sixth Chord. Oxford

    Music Online. Oxford: Oxford University Press. Avail-able online at http://www.OxfordMusicOnline.com/subscriber/article/grove/music/19658 (subscriptionrequired). Accessed 25 June 2013.

    Gannon, P. 1990. “Band-in-a-Box.” Available online athttp://www.pgmusic.com/. Accessed 25 June 2013.

    De Haas, W. B., J. P. Magalhães, and F. Wiering. 2012.“Improving Audio Chord Transcription by ExploitingHarmonic and Metric Knowledge.” In   Proceedingsof the International Society for Music InformationRetrieval Conference, pp. 295–300.

    De Haas, W. B., R. C. Veltkamp, and F. Wiering. 2013.“A Geometrical Distance Measure for Determining theSimilarity of Musical Harmony.”  International Journalof Multimedia Information Retrieval  2(3):189–202.dx.doi.org/10.1007/s13735-013-0036-6.

    De Haas, W. B.,et al.2009.“Modeling Harmonic SimilarityUsing a Generative Grammar of Tonal Harmony.” InProceedings of the International Conference on MusicInformation Retrieval, pp. 549–554.

    De Haas, W. B., et al. 2011. “HarmTrace: ImprovingHarmonic Similarity Estimation Using FunctionalHarmony Analysis.” In  Proceedings of the Interna-tional Conference on Music Information Retrieval,pp. 66–72.

    De Haas, W. B., et al. 2012. “Chordify: Chord Transcriptionfor the Masses.” Demonstration presented at theInternational Society for Music Information RetrievalConference, 8–12 October, Porto, Portugal. Availableonline at http://dreixel.net/research/pdf/cctfm.pdf.Accessed June 2013.

    Hamanaka, M., K. Hirata, and S. Tojo. 2006. “Implement-ing  A Generative Theory of Tonal Music.”  Journal of New Music Research 35(4):249–277.

    Harte,C., et al.2005.“Symbolic Representation of MusicalChords: A Proposed Syntax for Text Annotations.” InProceedings of the International Symposium on MusicInformation Retrieval, pp. 66–71.

    Jaffe, A. 1996. Jazz Harmony . Rottenburg: Advance Music,2nd edition.

    Jeuring, J., et al. 2009. “Libraries for Generic Program-ming in Haskell.” In P. Koopman, R. Plasmeijer, andD. Swierstra, eds.  Advanced Functional Programming,6th International School,  Lecture Notes in ComputerScience, vol. 5832. Berlin: Springer, pp. 165–229.

    Koops, H. V., J. P. Magalhães, and W. B. de Haas. 2013. “AFunctional Approach to Automatic Melody Harmon-isation.” In  Proceedings of the First ACM SIGPLAN Workshop on Functional Art, Music, Modeling &Design (FARM ’13).

    Lerdahl, F., and R. Jackendoff. 1996.  A GenerativeTheory of Tonal Music. Cambridge, Massachusetts:MIT Press.

    Magalh ães, J. P., and W. B. de Haas. 2011. “FunctionalModelling of Musical Harmony: An Experience Report.”In  Proceedings of the ACM SIGPLAN InternationalConference on Functional Programming , pp. 156–162.

    Marsden, A. 2010. “Schenkerian Analysis by Computer:A Proof of Concept.”  Journal of New Music Research39(3):269–289.

    Mauch, M., et al. 2007. “Discovering Chord IdiomsThrough Beatles and Real Book Songs.” In  Proceedingsof the International Conference on Music InformationRetrieval, pp. 255–258.

    Noland, K., and M. Sandler. 2009. “Influences of SignalProcessing, Tone Profiles, and Chord Progressions ona Model for Estimating the Musical Key from Audio.”Computer Music Journal  33(1):42–56.

    Pachet, F. 1999. “Surprising Harmonies.”  InternationalJournal of Computing Anticipatory Systems 4:139–161.

    Patel, A. D. 2003. “Language, Music, Syntax and theBrain.” Nature Neuroscience 6:674–681.

    Peyton Jones, S. 2003. “Haskell 98 Language and Li-braries: The Revised Report.”  Journal of FunctionalProgramming  13(1):7–255.

    Piston, W. 1991. Harmony . London: Gollancz, 7th edition.Revised and expanded by Mark DeVoto.

    Rameau, J.-P. 1722.  Trait ´ e de l’harmonie. Paris: Ballard.Translated by P. Gossett as Treatise on Harmony . 1971.New York: Dover.

    Riemann, H. ca. 1895. Harmony Simplified: Or the Theory of the Tonal Functions of Chords. London: Augener.Originally published as  Vereinfachte Harmonielehre.Oder: Die Lehre von den tonalen Funktionen der

     Akkorde.Roads, C. 1979. “Grammars as Representations for

    Music.” Computer Music Journal 3(1):48–55.Rohrmeier, M. 2007. “A Generative Grammar Approach

    to Diatonic Harmonic Structure.” In Proceedings of theSound and Music Computing Conference, pp. 97–100.

    Rohrmeier, M. 2011. “Towards a Generative Syntax ofTonal Harmony.” Journal of Mathematics and Music5(1):35–53.

    Saslaw, J. 2013. Diminished Seventh Chord. Oxford MusicOnline. Oxford: Oxford University Press. Available

    52   Computer Music Journal

    http://www.mitpressjournals.org/action/showLinks?crossref=10.1177%2F0305735686141001http://www.mitpressjournals.org/action/showLinks?crossref=10.1002%2Faris.1440370108http://www.mitpressjournals.org/action/showLinks?crossref=10.1007%2Fs13735-013-0036-6http://www.mitpressjournals.org/action/showLinks?crossref=10.1007%2Fs13735-013-0036-6http://www.mitpressjournals.org/action/showLinks?crossref=10.1080%2F09298210701563238http://www.mitpressjournals.org/action/showLinks?crossref=10.1080%2F09298210701563238http://www.mitpressjournals.org/action/showLinks?crossref=10.1080%2F09298215.2010.503898http://www.mitpressjournals.org/action/showLinks?system=10.1162%2Fcomj.2009.33.1.42http://www.mitpressjournals.org/action/showLinks?crossref=10.1038%2Fnn1082http://www.mitpressjournals.org/action/showLinks?crossref=10.2307%2F3679756http://www.mitpressjournals.org/action/showLinks?crossref=10.1080%2F17459737.2011.573676http://www.mitpressjournals.org/action/showLinks?crossref=10.1177%2F0305735686141001http://www.mitpressjournals.org/action/showLinks?system=10.1162%2Fcomj.2009.33.1.42http://www.mitpressjournals.org/action/showLinks?crossref=10.2307%2F3679756http://www.mitpressjournals.org/action/showLinks?crossref=10.1080%2F09298210701563238http://www.mitpressjournals.org/action/showLinks?crossref=10.1080%2F09298210701563238http://www.mitpressjournals.org/action/showLinks?crossref=10.1038%2Fnn1082http://www.mitpressjournals.org/action/showLinks?crossref=10.1080%2F09298215.2010.503898http://www.mitpressjournals.org/action/showLinks?crossref=10.1080%2F17459737.2011.573676http://www.mitpressjournals.org/action/showLinks?crossref=10.1007%2Fs13735-013-0036-6http://www.mitpressjournals.org/action/showLinks?crossref=10.1007%2Fs13735-013-0036-6http://www.mitpressjournals.org/action/showLinks?crossref=10.1002%2Faris.1440370108

  • 8/17/2019 Automatic Functional Harmonic Analysis

    17/17

    online at http://www.OxfordMusicOnline.com/subscriber/article/grove/music/07806 (subscriptionrequired). Accessed 25 June 2013.

    Schenker, H. 1935.  Neue musikalische Theorien undPhantasien III: Der freie Satz. Vienna: UniversalEdition.

    Schrijvers, T., et al. 2009. “Complete and Decidable TypeInference for GADTs.” In   Proceedings of the ACM SIGPLAN International Conference on FunctionalProgramming , pp. 341–352.

    Sher, C., ed. 1988.   The New Real Book. Petaluma,California: Sher Music.

    Steedman, M. J. 1984. “A Generative Grammar for JazzChord Sequences.” Music Perception 2(1):52–77.

    Steedman, M. J. 1996. “The Blues and the AbstractTruth: Music and Mental Models.” In J. Oakhill andA. Garnham, eds. Mental Models in Cognitive Science.Mahwah, New Jersey: Erlbaum, pp. 305–318.

    Swierstra, S. D. 2009.   Combinator Parsing: A ShortTutorial. Berlin: Springer, pp. 252–300.

    Temperley, D. 2001.   The Cognition of Basic MusicalStructures. Cambridge, Massachusetts: MIT Press.

    Temperley, D., and D. Sleator. 1999. “Modeling Meter andHarmony: A Preference-Rule Approach.”  ComputerMusic Journal 23(1):10–27.

    Winograd, T. 1968. “Linguistics and the ComputerAnalysis of Tonal Harmony.” Journal of Music Theory 12(1):2–49.

    De Haas et al.   53

    http://www.mitpressjournals.org/action/showLinks?crossref=10.1145%2F1596550.1596599http://www.mitpressjournals.org/action/showLinks?crossref=10.1145%2F1596550.1596599http://www.mitpressjournals.org/action/showLinks?crossref=10.1145%2F1596550.1596599http://www.mitpressjournals.org/action/showLinks?crossref=10.2307%2F40285282http://www.mitpressjournals.org/action/showLinks?system=10.1162%2F014892699559616http://www.mitpressjournals.org/action/showLinks?system=10.1162%2F014892699559616http://www.mitpressjournals.org/action/showLinks?crossref=10.2307%2F842885http://www.mitpressjournals.org/action/showLinks?crossref=10.2307%2F842885http://www.mitpressjournals.org/action/showLinks?system=10.1162%2F014892699559616http://www.mitpressjournals.org/action/showLinks?system=10.1162%2F014892699559616http://www.mitpressjournals.org/action/showLinks?crossref=10.2307%2F40285282http://www.mitpressjournals.org/action/showLinks?crossref=10.1145%2F1596550.1596599http://www.mitpressjournals.org/action/showLinks?crossref=10.1145%2F1596550.1596599http://www.mitpressjournals.org/action/showLinks?crossref=10.1145%2F1596550.1596599