User’s Guide, Chapter 7: Chords

Chords, as the name might suggest, are objects that combine multiple Pitch objects on a single stem. They can be found in the music21.chord module. The most general way to create a Chord object is by passing in a list of pitch names you want in the chord:

from music21 import *
cMinor = chord.Chord(["C4","G4","E-5"])

Note and Chord objects, since both are subclasses of the GeneralNote object share many features in common:

cMinor.duration.type = 'half'

But since a Chord contains many pitches, it does not have a .pitch attribute:


AttributeError                            Traceback (most recent call last)

<ipython-input-4-682233136f94> in <module>()
----> 1 cMinor.pitch

AttributeError: 'Chord' object has no attribute 'pitch'

Instead it has a .pitches attribute which returns a Tuple of pitches in the Chord.

 (<music21.pitch.Pitch C4>, <music21.pitch.Pitch G4>, <music21.pitch.Pitch E-5>)

Okay, but you already knew what pitches were in the Chord since you just created it! What else can you do with it?

How about determining if it is a major or a minor triad?


You can also figure out if it is in inversion or not:


Chords in root position have inversion of 0. But consider this other chord:

cMajor = chord.Chord(["E3","C4","G4"])

With this chord, two other methods become important:

 <music21.pitch.Pitch C4>
 <music21.pitch.Pitch E3>

You can find the third and fifth of the Chord with .third and .fifth. Note that these properties do not have () after them. This was a mistake in how we created music21 and hopefully this will all be fixed and consistent soon:

 <music21.pitch.Pitch E3>
 <music21.pitch.Pitch G4>

There is also a .seventh property, but it won’t do anything here:


The result of that is None which we can test like so...

cMajor.seventh is None

Displaying Chords

We can display the Chord object just like any Note (Don’t worry if this isn’t working for you yet...we’ll get this set up in Chapter 8)

These chords are a bit “spacey”, so let’s get c in closedPosition():

cClosed = cMinor.closedPosition()

Notice that cMinor is unchanged. The closed position chord is only cClosed:

If we wanted to change the Chord object itself, we call .closedPosition(inPlace=True) which alters the original. Since the original is altered, we don’t need to put x = ... in front of it


There is also a method, semiClosedPosition() which acts like .closedPosition except that if there is already a pitch at that step (i.e., D-flat and D-sharp are both step “D”), then the note is moved up an octave. This is useful for displaying complex, post tonal chords in the most compact form possible:

c1 = chord.Chord(['C4', 'E5', 'C#6', 'E-7', 'G8', 'C9', 'E#9'])
c2 = c1.semiClosedPosition()

We can get the common name of each of these Chords:

cn1 = cMinor.commonName
 minor triad
 major triad

More complex chords have less common “commonNames”. Here’s one that the American composer Elliott Carter liked a lot.

elliottCarterChord = chord.Chord(['C4','D-4','E4','F#4'])
 'all-interval tetrachord'

More ways of creating chords; Chords and Streams

There are other ways of creating a Chord if you’d like. One way is from a bunch of already created Note objects:

d = note.Note('D4')
fSharp = note.Note('F#4')
a = note.Note('A5')
dMajor = chord.Chord([d, fSharp, a])

Or we can pass a string with note names separated by spaces:

e7 = chord.Chord("E4 G#4 B4 D5")

The octaves are optional, especially if everything is within an octave:

es = chord.Chord("E- G B-")

But you will definitely want them if a chord crosses the boundary of an octave (between B and C). Unless you love 6-4 chords, this is probably not what you want:

fMajor = chord.Chord("F A C")

Notice that because C sorts before F and A that the chord is in second inversion, or 64. We can figure out the inversion of a Chord like so:

print(fMajor.inversion(), fMajor.inversionName())
 2 64

In addition to .commonName, there are a few other “name” properties that might be interesting:

 'Chord {F | A | C} Quarter'
 'F-major triad'

Like Note objects, we can put Chord objects inside a Stream:

stream1 = stream.Stream()

We can mix and match Notes, Rests, and Chords:

rest1 = note.Rest()
rest1.quarterLength = 0.5
noteASharp = note.Note('A#5')
noteASharp.quarterLength = 1.5

stream2 = stream.Stream()

Post-tonal chords (in brief)

There are a lot of methods for dealing with post-tonal aspects of chords. If you’re not interested in twentieth century music, go ahead and skip to the next chapter, but, here are some fun things.

The intervalVector of a chord is a list of the number of [semitones, whole-tones, minor-thirds/augmented-seconds, major-thirds, perfect fourths, and tritones] in the chord or inversion. A minor triad, for instance, has one minor third (C to E-flat), one major third (E-flat to G), and one perfect fourth (G to C above, since octave does not matter):

 [0, 0, 1, 1, 1, 0]

A major triad has the same interval vector:

 [0, 0, 1, 1, 1, 0]

The elliottCarterChord is unique in that it has an .intervalVector of all 1’s:

 [1, 1, 1, 1, 1, 1]

Well, it’s almost unique: there is another chord with the same .intervalVector. That Chord is called its Z-relation or Z-pair.

otherECChord = elliottCarterChord.getZRelation()
 <music21.chord.Chord C D- E- G>
 [1, 1, 1, 1, 1, 1]

The other post-tonal tools you might be interested in are given below. We’ll return to them in a later chapter, but here are three important ones:

 [0, 1, 4, 6]
 [0, 1, 4, 6]

If you really only care about semitones, you can create a chord just with the pitchClasses:

oddChord = chord.Chord([1, 3, 7, 9, 10])

There’s a little problem with the A and A# being on the same space that makes it hard to read. Let’s flip the A# to Bb:


If you use pitchClasses above 11, then they are treated as MIDI numbers, where 60 = MiddleC, 72 = C5, etc. Enharmonic spelling is chosen automatically.

midiChordType = chord.Chord([60, 65, 70, 75])

Okay, so now you’ve learned the basics (and more!) of Notes and Chords. If you haven’t been able to see them on your own, Chapter 8: Installing MusicXML Readers will fix it. It’s also going to cover the basic file formats of music21.