Beruflich Dokumente
Kultur Dokumente
The MIT Faculty has made this article openly available. Please share
how this access benefits you. Your story matters.
ABSTRACT labeling is another task that initially seems easy but rapid-
ly becomes extremely troublesome for several reasons.
Music21 is an object-oriented toolkit for analyzing, Are grace-notes accented or unaccented? Only a musical-
searching, and transforming music in symbolic (score- ly-trained ear that also knows the norms of an era can tell.
based) forms. The modular approach of the project allows Incompletely-filled measures, such as pickup measures
musicians and researchers to write simple scripts rapidly and mid-bar repeats, present problems for algorithms. As
and reuse them in other projects. The toolkit aims to pro- the researcher’s corpus expands, the time spent on meta-
vide powerful software tools integrated with sophisticated research expands with it. What began as a straightforward
musical knowledge to both musicians with little pro- project becomes a set of tedious separate labors: trans-
gramming experience (especially musicologists) and to forming data from multiple formats into one, moving
programmers with only modest music theory skills. transposing instruments into sounding pitch, editorial ac-
This paper introduces the music21 system, demon- cidentals in early music, or finding ways of visualizing
strating how to use it and the types of problems it is well- troublesome moments for debugging.
suited toward advancing. We include numerous examples Researchers in other fields can call upon general-
of its power and flexibility, including demonstrations of purpose toolkits to deal with time-consuming yet largely
graphing data and generating annotated musical scores. solved problems. For instance, a scientist working with a
large body of text has easy access to open-source libraries
1. INTRODUCTION: WHY MUSIC21? for removing punctuation, converting among text-
Computers have transformed so many aspects of musi- encoding formats, correcting spelling, identifying parts of
cology—from writing and editing papers, to studying speech, sentence diagramming, automatic translation, and
manuscripts with digital files, to creating databases of of course rendering text in a variety of media. Libraries
composers’ letters, to typesetting editions—that it is in- and programs to help with the musical equivalents of
credible that most analytical tasks that music historians each of these tasks do exist, but few exchange data with
perform remain largely untouched by technology. The each other in standardized formats. Even fewer are de-
study of the rich troves of musical data in scores, signed in modern, high-level programming languages. As
sketches, intabulations, lead-sheets, and other sources of a result of these difficulties, computational solutions to
symbolic music data is still done almost exclusively by musicological problems are rarely employed even when
hand. Even when databases and spreadsheets are em- they would save time, expand the scope of projects, or
ployed, they are usually created for a single purpose. quickly find important exceptions to overly broad pro-
Such specialized approaches cannot easily be reused. nouncements.
Computer scientists often assume that, compared to The music21 project (http://web.mit.edu/music21)
working with scanned images of scores or sound files, expands the audience for computational musicology by
manipulating symbolic data should be a cinch. Most of creating a new toolkit built from the ground up with intui-
the information from a score can easily be converted to tive simplicity and object-oriented design throughout.
text-based or numeric formats that general-purpose statis- (The “21” in the title comes from the designation for
tical or information-retrieval tools can manipulate. In MIT’s classes in Music, Course 21M.) The advantages of
practice the complexities of music notation and theory object-oriented design have led to its wide adoption in
result in these tools rarely being sufficient. many realms of software engineering. These design prin-
For instance, a researcher might want to compare ciples have been employed in music synthesis and gener-
how closely the music of two composers adheres to a par- ation systems over the past 25 years [2, 9, 10] but have
ticular scale (say, the major scale). What begins as a not been thoroughly integrated into packages for the
straightforward statistical problem requiring little musical analysis of music as symbolic data. Humdrum, the most
knowledge—simply encode which notes are in the scale widely adopted software package [6], its contemporary
of the piece’s key and which are not—can quickly grow ports [7, 11], and publications using these packages show
beyond the capabilities of general statistics packages. the great promise of computational approaches to music
Suppose that after some initial work, our researcher de- theory and musicology. Yet Humdrum can be difficult to
cides that notes on stronger beats should be weighed use: both programmers and non-programmers alike may
more heavily than those on weaker beats. Now she must find its reliance on a chain of shell-scripts, rather than ob-
either add the information about beats by hand to each ject-oriented libraries, limiting and not intuitive.
note or write a new algorithm that labels the beats. Beat Nicholas Cook has called upon programmers to
create for musicologists “a modular approach involving
637
11th International Society for Music Information Retrieval Conference (ISMIR 2010)
an unlimited number of individual software tools” [3]. A high-level objects. The framework includes many objects,
framework built with intuitive, reusable, and expandable including Pitches, Chords, Durations, TimeSignatures,
objects satisfies Cook’s call without sacrificing power for Intervals, Instruments, and standard Ornaments. Through
more complex tasks. method calls, objects can perform their own analyses and
As a new, open-source, cross-platform toolkit written transformations. For instance, Chords can find their own
in Python, music21 provides such a modular approach, roots, create closed-position versions of themselves,
melding object-oriented music representation and analy- compute their Forte prime forms, and so on. Researchers
sis with a concise and simple programming interface. can extend objects for their own needs, such as altering
Simplicity of use, ease of expansion, and access to exist- the pitch of open Violin strings to study scordatura, spe-
ing data are critical to the design of music21. The toolkit cializing (subclassing) the Note class into MensuralNote
imports Humdrum/Kern, MusicXML [4], and user- for studying Renaissance Music, or grouping Measures
defined formats (with MIDI and MuseData forthcoming). into Hypermeters. The object-oriented design of mu-
Because it is written in Python, music21 can tap into sic21 simplifies writing these extensions.
many other libraries, integrating internet resources (such
as geomapping with Google Maps), visualization soft- 3. STREAMS: POWERFUL, NESTABLE,
ware, and sophisticated database searches with musical CONTAINERS OF TIMED ELEMENTS
analysis.
This brief paper gives an overview of the music21 At the core of music21 is a novel grouping of musical
toolkit. Through examples of musicological applications information into Streams: nestable containers that allow
that the system enables, the main distinguishing features researchers to quickly find simultaneous events, follow a
are illustrated: simplicity of use and expansion. voice, or represent instruments playing in different tempi
and meters. Elements within Streams are accessed with
2. SCRIPTING AND OBJECTS methods such as getElementById(), an approach simi-
larly to the Document Object Model (DOM) of retrieving
Music21 is built in Python, a well-established program- elements from within XML and HTML documents. Like
ming language packaged with Macintosh and Unix com- nearly every music21 object, Streams can immediately
puters and freely downloadable for Windows users. The be visually displayed in Lilypond or with programs that
toolkit adds a set of related libraries, providing sophisti- import MusicXML (such as Finale and Sibelius).
cated musical knowledge to Python. As shown in Figure Through the Stream model, a program can find notes or
1, after adding the system with “from music21 chords satisfying criteria that change from section to sec-
import *”, straightforward tasks such as displaying or tion of a piece, such as all notes that are the seventh-
playing a short melody, getting a twelve-tone matrix, or degree of the current key (as identified either manually or
converting from Humdrum’s Kern format to MusicXML with an included key-detection algorithm) and then re-
can each be accomplished with a single line of code. trieve information such as the last-defined clef, dynamic,
or metrical accent level at that point.
Many tools to visualize, process, and annotate
Display a simple melody in musical notation: Streams come with the music21 framework. These tools
tinyNotation.TinyNotationStream( include graphing modules, analytical tools, and conveni-
"c4 d8 f g16 a g f#", "3/4").show()
ence routines for metrical analysis [8], phrase extraction,
and identification of non-harmonic tones. Figure 2 de-
monstrates the use of metrical analysis, derived from
nested hierarchical subdivisions of the time signature [1],
Print the twelve-tone matrix for a tone row (in this case the to annotate two Bach chorales in different meters.
opening of Schoenberg’s Fourth String Quartet):
print(serial.rowToMatrix( from music21.analysis import metrical
[2,1,9,10,5,3,4,0,8,7,6,11]) )
or since most of the 2nd-Viennese school rows are already # load a Bach Chorale from the music21 corpus of supplied pieces
available as objects, you could instead type: bwv30_6 = corpus.parseWork('bach/bwv30.6.xml')
print(serial.RowSchoenbergOp37().matrix() )
# get just the bass part using DOM-like method calls
bass = bwv30_6.getElementById('Bass')
Convert a file from Humdrum’s **kern data format to Mu-
sicXML for editing in Finale or Sibelius: # get measures 1 through 10
parse('/users/documents/composition.krn'). excerpt = bass.getMeasureRange(1,10)
write('xml')
# apply a Lerdahl/Jackendoff-style metrical analysis to the piece.
Figure 1. Three simple examples of one-line mu- metrical.labelBeatDepth(excerpt)
sic21 scripts.
# display measure 0 (pickup) to measure 6 in the default viewer
# (here Finale Reader 2009)
excerpt.show()
Though single-line tasks are simpler to accomplish in
music21 than in existing packages, the full power of the
new toolkit comes from bringing together and extending
638
11th International Society for Music Information Retrieval Conference (ISMIR 2010)
4.1 An Integrated
I and Virtual Corrpus of Music for
Researchers
Musicc21 comes witth a corpus pac ckage, a large collec-
c
tion of freely-distributa
fr able music for analysis and testing,
t
includingg a complete collection of the Bach Chhorales,
numerou us Beethoven String Quartets, and exampples of
Renaissaance polyphonny. The virtuall corpus extennds the
corpus package
p even further. Similaar to a collecttion of
URL bookmarks to m music resourcess, additional reeperto-
ries, avaailable online, can be autommatically downnloaded
when firrst requested aand then madee available to thet re-
searcher for future usee. The corpus includes bothh Kern
and MussicXML files. Future system m expansions will
w not
only grow the tools forr analysis, but also the breaddth and
depth off the corpus of w
works.
4.2 Perm missive Licensse and Full Doocumentation
Music21 is a toollkit: a collectioon of tools thaat work
together in a wide rannge of contextts. The promisse of a
toolkit iss only achievedd if users can expand and inttegrate
# perform the samee process on a diffe
ferent chorale in 3//4 time softwaree components iin their own work.
w Thus, music21
bwv11_6
b = corrpus.parseWor rk('bach/bwv1 11.6.xml') is releassed under thee Lesser General Public LicenseL
alto
a = bwv11_ _6.getElement tById('Alto') )
excerpt
e = altto.getMeasure eRange(13,20) )
(LGPL), allowing its use within both free and comm mercial
metrical.labe
m elBeatDepth(e excerpt) softwaree. So that impleementation and d documentatioon stay
excerpt.show(
e () synchron nized, the toollkit also featuures high-qualiity, in-
dexed, and
a searchable documentationn of all modulles and
classes, automatically created from the source codde and
test r
routines. Thhe music2 21 site (http://
web.mit..edu/music21) hosts up-to-ddate informatioon, do-
cumentattion and releaase links. Codde browsing, ffeature
requests,, and bug reporrts are housed at Google Codde.
5. EXAMPLES
S
Better thhan an explanaation of high-llevel features, a few
specific examples illusstrate the toolkkit’s promise. These
examples are chosen for both their novel and prractical
utility.
5.1 Find ding Chords w within Melodicc Fragments
The sccript in Figure 3 searches thee entire secondd violin
part of a MusicXML sscore of Beeth hoven’s Großee Fuge,
op. 133, to find measuures that melod dically express domi-
Figure
F 2. Anaalytical tools, such
s as this metrical
m accentt nant seveenth chords in consecutive notes.
n It then diisplays
laabeler, are inccluded with muusic21 and work with mostt the chorrd in closed pposition, the suurrounding meeasure,
Streams
S (includding Scores annd Parts). Herre, excerpts off and the Forte prime form. (Runniing the same query
tw
wo Bach choraales, each in a different meteer, are labeledd across baarlines would aadd just a few lines
l of code).
with
w dots corressponding to theeir metric strenngths.
op133 = corpus.parseWork(
'beethoven/opus133.xml')
violin2 = op133.getElementById('2nd Violin')
4.
4 FURTHER
R FEATURES
# an emptty container for later display
In additionn to providing sophisticated resources in a display = stream.Stream()
modern
m prograamming language, the musi ic21 packagee
taakes advantagge of some off the best conttemporary ap-- for thisMeasure in violin2.measures:
proaches
p to sofftware distributtion, licensing,, development,, # get a list
l of consecutive notes, skipping unnisons, octaves,
and
a documentaation. These approaches
a assure both thee # and reests (and putting nnothing in their plaaces)
lo
ongevity of thee system acrosss multiple platforms as welll notes = thisMeasure.findConsecutiveNotes(
as
a the ability of o the system to t grow and inncorporate thee skipUnisons = True, skipOctav ves = True,
skipRests = True, noNone = Tr rue)
work
w of contribbutors.
pitches = stream.Stream(notes).pitches
639
11th International Society for Music Information Retrieval Conference (ISMIR 2010)
if testChhord.isDomina antSeventh(): :
# A dominant-seventh chorrd was found in thiis measure.
chordMe
easure = stre
eam.Measure())
chordMe
easure.append
d(
test
tChord.closed
dPosition())
display
y.append(chor
rdMeasure)
display
y.append(this
sMeasure)
display.show(
d ()
Figure
F 3. The results
r of a seaarch for chordss expressed
melodically.
m
5.2
5 Distributio ons of Notes by
b Pitch and Duration
D
Figure 4 deemonstrates thhe ability of muusic21 graphss
to
o help visualizze trends that are
a otherwise difficult
d to dis--
cern.
c These graaphs plot threee features: pitcch, duration off
notes,
n and how
w frequently theese pitches and d durations aree
used.
u From twoo small excerptts of pieces in 3/4 by Mozartt
(a minuet, in reed) and by Chopin (a mazurk ka, in blue), itt
can
c be seen thaat pitches in thhe Mozart exaample follow a
ty
ype of bell-cuurve distribution, with few hiigh notes, few w
lo
ow notes, and many notes tooward the midd dle of the regi--
stral
s space. Chhopin’s usage jumps
j throughhout the piano.
The
T differences in pitch usaage suggest that this line off
in
nquiry is wortth pursuing furrther, but no connection
c be--
tw
ween duration and pitch appears. Music21 1’s easy-to-usee
graphing
g methoods help researrchers find the best visualiza--
tiion tool for thheir data, easilly switching among
a diversee 4 Differencess in pitch disttribution betweeen
Figure 4.
formats.
f Mozart and
a Chopin.
from
f .musicxml imp
music21. port testFile
es as xml
from
f .humdrum impo
music21. ort testFiles
s as kern The Mozart and Chopin exampples, while shhowing
distinctivve individual usage, show little correlatioon be-
# display 3D grapphs of count, pitch,, and duration tween piitch and duratiion. Many other pieces do. An A ex-
mozartStream
m = music21.pa arse(
xml.mozar rtTrioK581Exc cerpt) treme example
e is MMessiaen’s “M Mode de valeurs et
notes
n = mozar rtStream.flat t.stripTies() ) d’intensiités” from Quaatre études de rythme, perhaaps the
g = graph.Plo ot3DBarsPitch hSpaceQuarter rLength( first worrk of total serrialism. A perrfect correlatioon be-
notes, co olors=['r'])
g.process()
g
tween piitch and durattion, as found in the middlee voice
(isolated
d for clarity), iss plotted in Figure 5. An asppect of
640
11th International Society for Music Information Retrieval Conference (ISMIR 2010)
messiaen = converter.parse(
'd:/valeurs_part2.xml')
notes = messiaen.flat.stripTies()
g = graph.PlotScatterWeightedPitch\
SpaceQuarterLength(notes, xLog = False,
title='Messiaen, Mode de Valeurs,
middle voice')
g.process()
Figure 6. A graph of pitch class usage over time in
Beethoven’s Große Fuge.
641
11th International Society for Music Information Retrieval Conference (ISMIR 2010)
# we also color the affected notes so that if we display the music The next stage of development will add native sup-
# the notes stick out. Different colors indicate different rules port for additional input and output formats, including
n1.editorial.color = "blue"
n2.editorial.color = "forestGreen" MIDI. Further, libraries of additional processing, analy-
n3.editorial.color = "blue" sis, visualization routines, as well as new and expanded
object models (such as non-Western scales), will be add-
Figure 7. Applying ficta accidentals with music21. ed to the system. We are presently focusing on creating
simple solutions for common-practice music theory tasks
The results of applying one or all the rules to an in- via short music21 scripts, and within a year hope to be
dividual cadence or piece can be seen immediately. Fig- able to solve almost every common music theory problem
ure 8 shows the rules applied to one piece where they encountered by first-year conservatory students.
create two “closest-approaches” to perfect consonances
(major sixth to octave and minor third to unison). These 7. ACKNOWLEDGEMENTS
are the outcomes one expects from a good set of regulae
for musica ficta. The authors thank the Seaver Institute for their ge-
nerous funding of music21. Additional thanks are also
# get a particular worksheet of an Excel spreadsheet extended to three anonymous reviewers for their helpful
ballataObj = cadencebook.BallataSheet()
comments.
# create an object for row 267
pieceObj = ballataObj.makeWork(267)
# run the four rules (as described above) 8. REFERENCES
applyCapua(pieceObj)
# display the first cadence of the piece (second snippet) by [1] Ariza, C. and M. Cuthbert. 2010. “Modeling Beats,
# running it through Lilypond and generating a PNG file Accents, Beams, and Time Signatures Hierarchically
pieceObj.snippets[1].lily.showPNG()
with music21 Meter Objects.” In Proceedings of the
International Computer Music Conference. San
Francisco: International Computer Music Association.
[2] Buxton, W. and W. Reeves, R. Baecker, L. Mezei.
1978. “The Use of Hierarchy and Instance in a Data
Structure for Computer Music.” Computer Music
Journal 2 (4): 10-20.
[3] Cook, N. 2004. “Computational and Comparative
Musicology.” In Empirical Musicology: Aims,
Figure 8. Music21 code for automatically adding musica Methods, Prospects. N. Cook and E. Clarke, eds. New
ficta to Francesco (Landini), De[h], pon’ quest’amor, York: Oxford University Press. 103-126.
first cadence. [4] Good, M. 2001. “An Internet-Friendly Format for
Sheet Music.” In Proceedings of XML 2001.
[5] Herlinger, J. 2004. “Nicolaus de Capua, Antonio Za-
cara da Teramo, and musica ficta.” In Antonio Zacara
In other pieces, Nicolaus’s rules have an injurious effect, da Teramo e il suo tempo. F. Zimei, ed. Lucca: LIM.
as Figure 9 shows. With the toolkit, we were able to run 67–89.
the rules on the entire database of Trecento ballatas and [6] Huron, D. 1997. “Humdrum and Kern: Selective
determine that Nicolaus’s rules cannot be used indiscri- Feature Encoding.” In Beyond MIDI: the Handbook
minately. Far too many cases appeared where the pro- of Musical Codes. E. Selfridge-Field, ed. Cambridge:
posed ficta hurt the harmony. One of the main advantages MIT Press. 375-401.
of the music21 framework is making such observations [7] Knopke, I. 2008. “The PerlHumdrum and
on large collections of musical data possible. PerlLilypond Toolkits for Symbolic Music
Information Retrieval.” ISMIR 2008 147-152.
[8] Lerdahl, F. and R. Jackendoff. 1983. A Generative
Theory of Tonal Music. Cambridge: MIT Press.
[9] Pope, S. T. 1987. “A Smalltalk-80-based Music
Toolkit.” In Proceedings of the International
Computer Music Conference. San Francisco:
International Computer Music Association. 166-173.
Figure 9. Francesco, D’amor mi biasmo, incipit after au- [10] Pope, S. T. 1989. “Machine Tongues XI: Object-
tomatically applying ficta accidentals. Oriented Software Design.” Computer Music Journal
13 (2): 9-22.
[11] Sapp, C. S. 2008. “Museinfo: Musical Information
6. FUTURE WORK Programming in C++.” Internet:
http://museinfo.sapp.org.
The first alpha releases of music21 introduce fun-
damental objects and containers and, as shown above,
offer powerful tools for symbolic music processing.
642