  Understanding the structural characteristics of harmony is essential for an
effective use of music as a communication medium. Of the three expressive axes
of music (melody, rhythm, harmony), harmony is the foundation on which the
emotional content is built, and its understanding is important in areas such as
multimedia and affective computing. The common tool for studying this kind of
structure in computing science is the formal grammar but, in the case of music,
grammars run into problems due to the ambiguous nature of some of the concepts
defined in music theory. In this paper, we consider one of such constructs:
modulation, that is, the change of key in the middle of a musical piece, an
important tool used by many authors to enhance the capacity of music to express
emotions. We develop a hybrid method in which an evidence-gathering numerical
method detects modulation and then, based on the detected tonalities, a
non-ambiguous grammar can be used for analyzing the structure of each tonal
component. Experiments with music from the XVII and XVIII centuries show that
we can detect the precise point of modulation with an error of at most two
chords in almost 97% of the cases. Finally, we show examples of complete
modulation and structural analysis of musical harmonies.
