Previous topic

music21.chant

Next topic

music21.clef

Table Of Contents

Table Of Contents

This Page

music21.chord

This module defines the Chord object, a sub-class of GeneralNote as well as other methods, functions, and objects related to chords.

Functions

music21.chord.fromForteClass(notation)

Return a Chord given a Forte-class notation. The Forte class can be specified as string (e.g., 3-11) or as a list of cardinality and number (e.g., [8,1]).

If no match is available, None is returned.

>>> chord.fromForteClass('3-11')
<music21.chord.Chord C E- G>
>>> chord.fromForteClass('3-11b')
<music21.chord.Chord C E G>
>>> chord.fromForteClass('3-11a')
<music21.chord.Chord C E- G>
>>> chord.fromForteClass((11,1))
<music21.chord.Chord C C# D E- E F F# G G# A B->
music21.chord.fromIntervalVector(notation, getZRelation=False)

Return one or more Chords given an interval vector.

>>> chord.fromIntervalVector([0,0,0,0,0,1])
<music21.chord.Chord C F#>
>>> chord.fromIntervalVector((5,5,5,5,5,5)) == None
True
>>> chord.fromIntervalVector((1,1,1,1,1,1))
<music21.chord.Chord C C# E F#>
>>> chord.fromIntervalVector((1,1,1,1,1,1), getZRelation=True)
<music21.chord.Chord C C# E- G>
>>> chord.fromIntervalVector((1,1,1,1,1,1)).getZRelation()
<music21.chord.Chord C C# E- G>

Chord

class music21.chord.Chord(notes=[], **keywords)

Class for dealing with chords

A Chord functions like a Note object but has multiple pitches.

Create chords by passing a string of pitch names

>>> dmaj = chord.Chord(["D","F#","A"])
>>> dmaj
<music21.chord.Chord D F# A>

Pitch names can also include octaves:

>>> dmaj = chord.Chord(["D3","F#4","A5"])
>>> dmaj
<music21.chord.Chord D3 F#4 A5>

Or you can combine already created Notes or Pitches:

>>> Cnote = note.Note()
>>> Cnote.name = 'C'
>>> Enote = note.Note()
>>> Enote.name = 'E'
>>> Gnote = note.Note()
>>> Gnote.name = 'G'

And then create a chord with note objects:

>>> cmaj = chord.Chord([Cnote, Enote, Gnote])
>>> cmaj # default octave of 4 is used for these notes, since octave was not specified
<music21.chord.Chord C4 E4 G4>

Chord has the ability to determine the root of a chord, as well as the bass note of a chord. In addition, Chord is capable of determining what type of chord a particular chord is, whether it is a triad or a seventh, major or minor, etc, as well as what inversion the chord is in.

A chord can also be created from pitch class numbers:

>>> c = chord.Chord([0, 2, 3, 5])
>>> c.pitches
(<music21.pitch.Pitch C>, <music21.pitch.Pitch D>, <music21.pitch.Pitch E->, <music21.pitch.Pitch F>)

Or from MIDI numbers:

>>> c = chord.Chord([72, 76, 79])
>>> c.pitches
(<music21.pitch.Pitch C5>, <music21.pitch.Pitch E5>, <music21.pitch.Pitch G5>)

Chord bases

Chord read-only properties

Chord.chordTablesAddress

Return a three-element tuple that represents that raw data location for information on the set class interpretation of this Chord.

The data format is a Forte set class cardinality, index number, and inversion status (where 0 is invariant, and -1 and 1 represent inverted or not, respectively).

>>> c = chord.Chord(["C4", "E4", "G#4"])
>>> c.chordTablesAddress
(3, 12, 0)
Chord.commonName

Return the most common name associated with this Chord as a string. does not currently check enharmonic equivalents.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.commonName
'minor triad'
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.commonName
'major triad'
>>> c3 = chord.Chord(['c', 'd-', 'e', 'f#'])
>>> c3.commonName
'all-interval tetrachord'
Chord.fifth

Shortcut for getChordStep(5):

>>> cMaj1stInv = chord.Chord(['E3','C4','G5'])
>>> cMaj1stInv.fifth
<music21.pitch.Pitch G5>
>>> cMaj1stInv.fifth.midi
79
Chord.forteClass

Return the Forte set class name as a string. This assumes a Tn formation, where inversion distinctions are represented.

(synonym: forteClassTn)

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.forteClass
'3-11A'
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.forteClass
'3-11B'
Chord.forteClassNumber

Return the number of the Forte set class within the defined set group. That is, if the set is 3-11, this method returns 11.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.forteClassNumber
11
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.forteClassNumber
11
Chord.forteClassTn

A synonym for “forteClass”

Return the Forte Tn set class name, where inversion distinctions are represented:

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.forteClass
'3-11A'
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.forteClassTn
'3-11B'
Chord.forteClassTnI

Return the Forte TnI class name, where inversion distinctions are not represented.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.forteClassTnI
'3-11'
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.forteClassTnI
'3-11'
Chord.fullName

Return the most complete representation of this Note, providing duration and pitch information.

>>> c = chord.Chord(["D","F#","A"])
>>> c.fullName
'Chord {D | F-sharp | A} Quarter'
>>> chord.Chord(['d1', 'e4-', 'b3-'], quarterLength=2/3.).fullName
'Chord {D in octave 1 | E-flat in octave 4 | B-flat in octave 3} Quarter Triplet (0.67QL)'
Chord.hasZRelation

Return True or False if the Chord has a Z-relation.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.hasZRelation
False
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.hasZRelation
False
Chord.intervalVector

Return the interval vector for this Chord as a list of integers.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.intervalVector
[0, 0, 1, 1, 1, 0]
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.intervalVector
[0, 0, 1, 1, 1, 0]
Chord.intervalVectorString

Return the interval vector as a string representation.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.intervalVectorString
'<001110>'
Chord.isPrimeFormInversion

Return True or False if the Chord represents a set class inversion.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.isPrimeFormInversion
False
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.isPrimeFormInversion
True
Chord.multisetCardinality

Return an integer representing the cardinality of the mutliset, or the number of pitch values.

>>> c1 = chord.Chord(["D4", "A4", "F#5", "D6"])
>>> c1.multisetCardinality
4
Chord.normalForm

Return the normal form of the Chord represented as a list of integers:

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.normalForm
[0, 3, 7]
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.normalForm
[0, 4, 7]
Chord.normalFormString

Return a string representation of the normal form of the Chord.

>>> c1 = chord.Chord(['f#', 'e-', 'g'])
>>> c1.normalFormString
'<034>'
Chord.orderedPitchClasses

Return an list of pitch class integers, ordered form lowest to highest.

>>> c1 = chord.Chord(["D4", "A4", "F#5", "D6"])
>>> c1.orderedPitchClasses
[2, 6, 9]
Chord.orderedPitchClassesString

Return a string representation of the pitch class values.

>>> c1 = chord.Chord(['f#', 'e-', 'g'])
>>> c1.orderedPitchClassesString
'<367>'
>>> # redundancies are removed
>>> c1 = chord.Chord(['f#', 'e-', 'e-', 'g'])
>>> c1.orderedPitchClassesString
'<367>'
Chord.pitchClassCardinality

Return a the cardinality of pitch classes, or the number of unique pitch classes, in the Chord:

>>> c1 = chord.Chord(["D4", "A4", "F#5", "D6"])
>>> c1.pitchClassCardinality
3
Chord.pitchClasses

Return a list of all pitch classes in the chord as integers.

>>> c1 = chord.Chord(["D4", "A4", "F#5", "D6"])
>>> c1.pitchClasses
[2, 9, 6, 2]
Chord.pitchedCommonName

Return the common name of this Chord preceded by its root, if a root is available:

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.pitchedCommonName
'C-minor triad'
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.pitchedCommonName
'C-major triad'
Chord.primeForm

Return a representation of the Chord as a prime-form list of pitch class integers:

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.primeForm
[0, 3, 7]
>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.primeForm
[0, 3, 7]
Chord.primeFormString

Return a representation of the Chord as a prime-form set class string.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.primeFormString
'<037>'
>>> c1 = chord.Chord(['c', 'e', 'g'])
>>> c1.primeFormString
'<037>'
Chord.quality

Returns the quality of the underlying triad of a triad or seventh, either major, minor, diminished, augmented, or other:

>>> a = chord.Chord(['a', 'c', 'e'])
>>> a.quality
'minor'

Inversions don’t matter, nor do added tones so long as a root can be found:

>>> a = chord.Chord(['f', 'b', 'd', 'g'])
>>> a.quality
'major'
>>> a = chord.Chord(['c', 'a-', 'e'])
>>> a.quality
'augmented'
>>> a = chord.Chord(['c','c#','d'])
>>> a.quality
'other'

Incomplete triads are returned as major or minor:

>>> a = chord.Chord(['c','e-'])
>>> a.quality
'minor'
>>> a = chord.Chord(['e-','g'])
>>> a.quality
'major'
Chord.scaleDegrees

Returns a list of two-element tuples for each pitch in the chord where the first element of the tuple is the scale degree as an int and the second is an Accidental object that specifies the alteration from the scale degree (could be None if the note is not part of the scale).

It is easiest to see the utility of this method using a chord subclass, music21.roman.RomanNumeral, but it is also callable from this Chord object if the Chord has a Key or Scale context set for it.

>>> k = key.Key('f#')  # 3-sharps minor
>>> rn = roman.RomanNumeral('V', k)
>>> rn.key
<music21.key.Key of f# minor>
>>> rn.pitches
(<music21.pitch.Pitch C#5>, <music21.pitch.Pitch E#5>, <music21.pitch.Pitch G#5>)
>>> rn.scaleDegrees
[(5, None), (7, <accidental sharp>), (2, None)]
>>> rn2 = roman.RomanNumeral('N6', k)
>>> rn2.pitches
(<music21.pitch.Pitch B4>, <music21.pitch.Pitch D5>, <music21.pitch.Pitch G5>)
>>> rn2.scaleDegrees # N.B. -- natural form used for minor!
[(4, None), (6, None), (2, <accidental flat>)]

As mentioned above, the property can also get its scale from context if the chord is embedded in a Stream. Let’s create the same V in f#-minor again, but give it a context of c-sharp minor, and then c-minor instead:

>>> chord1 = chord.Chord(["C#5", "E#5", "G#5"])
>>> st1 = stream.Stream()
>>> st1.append(key.Key('c#'))   # c-sharp minor
>>> st1.append(chord1)
>>> chord1.scaleDegrees
[(1, None), (3, <accidental sharp>), (5, None)]
>>> st2 = stream.Stream()
>>> chord2 = chord.Chord(["C#5", "E#5", "G#5"])
>>> st2.append(key.Key('c'))    # c minor
>>> st2.append(chord2)          # same pitches as before gives different scaleDegrees
>>> chord2.scaleDegrees
[(1, <accidental sharp>), (3, <accidental double-sharp>), (5, <accidental sharp>)]
>>> st3 = stream.Stream()
>>> st3.append(key.Key('C'))    # C major
>>> chord2 = chord.Chord(["C4","C#4","D4","E-4","E4","F4"])  # 1st 1/2 of chromatic
>>> st3.append(chord2)
>>> chord2.scaleDegrees
[(1, None), (1, <accidental sharp>), (2, None), (3, <accidental flat>), (3, None), (4, None)]
Chord.seventh

shortcut for getChordStep(7)

>>> bDim7_2ndInv = chord.Chord(['F2','A-3','B4','D5'])
>>> bDim7_2ndInv.seventh
<music21.pitch.Pitch A-3>
Chord.third

Shortcut for getChordStep(3):

>>> cMaj1stInv = chord.Chord(['E3','C4','G5'])
>>> cMaj1stInv.third
<music21.pitch.Pitch E3>
>>> cMaj1stInv.third.octave
3

Read-only properties inherited from Music21Object:

Chord read/write properties

Chord.color

Get or set the Note color.

>>> a = chord.Chord(['c4', 'e4', 'g4'])
>>> a.duration.type = 'whole'
>>> a.color = '#235409'
>>> a.color
'#235409'
>>> a.editorial.color
'#235409'
>>> a.setColor('#ff0000', 'e4')
>>> a.getColor('c4')
'#235409'
>>> for p in a.pitches: print a.getColor(p)
#235409
#ff0000
#235409
Chord.duration

Get and set the duration of this Chord as a Duration object.

>>> c = chord.Chord(['a', 'c', 'e'])
>>> c.duration
<music21.duration.Duration 1.0>

Durations can be overridden after the fact:

>>> d = duration.Duration()
>>> d.quarterLength = 2
>>> c.duration = d
>>> c.duration
<music21.duration.Duration 2.0>
>>> c.duration == d
True
>>> c.duration is d
True
Chord.pitchNames

Return a list of Pitch names from each Pitch object’s name attribute.

>>> c = chord.Chord(['g#', 'd-'])
>>> c.pitchNames
['G#', 'D-']
>>> c.pitchNames = ['c2', 'g2']
>>> c.pitchNames
['C', 'G']
Chord.pitches

Get or set a list of all Pitch objects in this Chord.

>>> c = chord.Chord(["C4", "E4", "G#4"])
>>> c.pitches
(<music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>, <music21.pitch.Pitch G#4>)
>>> [p.midi for p in c.pitches]
[60, 64, 68]
>>> d = chord.Chord()
>>> d.pitches = c.pitches
>>> d.pitches
(<music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>, <music21.pitch.Pitch G#4>)
>>> c = chord.Chord(['C4', 'A4', 'E5'])
>>> c.bass()
<music21.pitch.Pitch C4>
>>> c.root()
<music21.pitch.Pitch A4>
>>> c.pitches = ['C#4', 'A#4', 'E#5']
>>> c.bass()
<music21.pitch.Pitch C#4>
>>> c.root()
<music21.pitch.Pitch A#4>

TODO: presently, whenever pitches are accessed, it sets the _chordTablesAddressNeedsUpdating value to True this is b/c the pitches list can be accessed and appended to. A better way to do this needs to be found.

Chord.tie

Get or set a single tie based on all the ties in this Chord.

This overloads the behavior of the tie attribute found in all NotRest classes.

If setting a tie, tie is applied to all pitches.

>>> c1 = chord.Chord(['c4','g4'])
>>> tie1 = tie.Tie('start')
>>> c1.tie = tie1
>>> c1.tie
<music21.tie.Tie start>
>>> c1.getTie(c1.pitches[1])
<music21.tie.Tie start>
Chord.volume

Get or set the Volume object for this Chord.

When setting the .volume property, all pitches are treated as having the same Volume object.

>>> c = chord.Chord(['g#', 'd-'])
>>> c.volume
<music21.volume.Volume realized=0.71>
>>> c.volume = volume.Volume(velocity=64)
>>> c.volume.velocityIsRelative = False
>>> c.volume
<music21.volume.Volume realized=0.5>
>>> c.volume = [volume.Volume(velocity=96), volume.Volume(velocity=96)]
>>> c.hasComponentVolumes()
True
>>> c._volume == None
True
>>> c.volume.velocity
96
>>> c.volume.velocityIsRelative = False
>>> c.volume  # return a new volume that is an average
<music21.volume.Volume realized=0.76>

Read/write properties inherited from NotRest:

Read/write properties inherited from GeneralNote:

Read/write properties inherited from Music21Object:

Chord methods

Chord.annotateIntervals(inPlace=True, stripSpecifiers=True, sortPitches=True)

Add lyrics to the chord that show the distance of each note from the bass. By default we show only the generic interval:

>>> c1 = chord.Chord(['C2','E2','G2','C3'])
>>> c2 = c1.annotateIntervals(inPlace = False)
>>> c2.lyrics
[<music21.note.Lyric number=1 syllabic=single text="8">, <music21.note.Lyric number=2 syllabic=single text="5">, <music21.note.Lyric number=3 syllabic=single text="3">]
>>> [l.text for l in c2.lyrics]
['8', '5', '3']

The stripSpecifiers parameter can be used to show only the intervals size (3, 5, etc) or the complete interval specification (m3, P5, etc.)

>>> c3 = c1.annotateIntervals(inPlace = False, stripSpecifiers = False)
>>> c3.lyrics
[<music21.note.Lyric number=1 syllabic=single text="P8">, <music21.note.Lyric number=2 syllabic=single text="P5">, <music21.note.Lyric number=3 syllabic=single text="M3">]
>>> [l.text for l in c3.lyrics]
['P8', 'P5', 'M3']

This chord was giving us problems:

>>> c4 = chord.Chord(['G4', 'E4', 'B3', 'E3'])
>>> c4.annotateIntervals(stripSpecifiers = False)
>>> [l.text for l in c4.lyrics]
['m3', 'P8', 'P5']

If sortPitches is false it still gives problems...

>>> c4 = chord.Chord(['G4', 'E4', 'B3', 'E3'])
>>> c4.annotateIntervals(stripSpecifiers = False, sortPitches = False)
>>> [l.text for l in c4.lyrics]
['m3', 'm6', 'm3']
>>> c = chord.Chord(['c4', 'd-4', 'g4'])
>>> c.annotateIntervals()
>>> [l.text for l in c.lyrics]
['5', '2']
>>> c = chord.Chord(['c4', 'd-4', 'g4'])
>>> c.annotateIntervals(stripSpecifiers=False)
>>> [l.text for l in c.lyrics]
['P5', 'm2']
>>> c = chord.Chord(['c4', 'd---4', 'g4'])
>>> c.annotateIntervals(stripSpecifiers=False)
>>> [l.text for l in c.lyrics]
['P5', 'dd2']

## TODO – decide, should inPlace be False like others?

Chord.areZRelations(other)

Check of chord other is also a z relations

>>> c1 = chord.Chord(["C", "c#", "e", "f#"])
>>> c2 = chord.Chord(["C", "c#", "e-", "g"])
>>> c3 = chord.Chord(["C", "c#", "f#", "g"])
>>> c1.areZRelations(c2)
True
>>> c1.areZRelations(c3)
False
Chord.bass(newbass=0, find=True)

Return the bass Pitch or set it to the given Pitch:

>>> cmaj1stInv = chord.Chord(['C4', 'E3', 'G5'])
>>> cmaj1stInv.bass()
<music21.pitch.Pitch E3>

The bass is usually defined to the lowest note in the chord, but we want to be able to override this. You might want an implied bass for instance some people (following the music theorist Rameau) call a diminished seventh chord (vii7) a dominant chord with an omitted bass – here we will specify the bass to be a note not in the chord:

>>> vo9 = chord.Chord(['B3', 'D4', 'F4', 'A-4'])
>>> vo9.bass()
<music21.pitch.Pitch B3>
>>> vo9.bass(pitch.Pitch('G3'))
>>> vo9.bass()
<music21.pitch.Pitch G3>

By default this method uses an algorithm to find the bass among the chord’s pitches, if no bass has been previously specified. If this is not intended, set find to False when calling this method, and ‘None’ will be returned if no bass is specified

>>> c = chord.Chord(['E3','G3','B4'])
>>> c.bass(find=False) == None
True
>>> d = harmony.ChordSymbol('CM')
>>> d.bass()
<music21.pitch.Pitch C3>
>>> d = harmony.ChordSymbol('Cm/E-')
>>> d.bass()
<music21.pitch.Pitch E-3>
Chord.canBeDominantV()

Returns True if the chord is a Major Triad or a Dominant Seventh:

>>> a = chord.Chord(['g', 'b', 'd', 'f'])
>>> a.canBeDominantV()
True
Chord.canBeTonic()

Returns True if the chord is a major or minor triad:

>>> a = chord.Chord(['g', 'b', 'd', 'f'])
>>> a.canBeTonic()
False
>>> a = chord.Chord(['g', 'b', 'd'])
>>> a.canBeTonic()
True
Chord.closedPosition(forceOctave=None, inPlace=False, leaveRedundantPitches=False)

Returns a new Chord object with the same pitch classes, but now in closed position.

If forcedOctave is provided, the bass of the chord will be shifted to that provided octave.

If inPlace is True then the original chord is returned with new pitches.

>>> chord1 = chord.Chord(["C#4", "G5", "E6"])
>>> chord2 = chord1.closedPosition()
>>> chord2
<music21.chord.Chord C#4 E4 G4>

Force octave changes the octave of the bass note (and all notes above it...)

>>> c2 = chord.Chord(["C#4", "G5", "E6"])
>>> c2.closedPosition(forceOctave = 2)
<music21.chord.Chord C#2 E2 G2>
>>> c3 = chord.Chord(["C#4", "G5", "E6"])
>>> c3.closedPosition(forceOctave = 6)
<music21.chord.Chord C#6 E6 G6>

Redundant pitches are removed by default, but can be retained...

>>> c4 = chord.Chord(["C#4", "C5", "F7", "F8"])
>>> c5 = c4.closedPosition(4, inPlace = False)
>>> c5
<music21.chord.Chord C#4 F4 C5>
>>> c6 = c4.closedPosition(4, inPlace = False, leaveRedundantPitches=True)
>>> c6
<music21.chord.Chord C#4 F4 F4 C5>

Implicit octaves work fine...

>>> c7 = chord.Chord(["A4", "B4", "A"])
>>> c7.closedPosition(4, inPlace = True)
>>> c7
<music21.chord.Chord A4 B4>
Chord.containsSeventh()

Returns True if the chord contains at least one of each of Third, Fifth, and Seventh. raises an exception if the Root can’t be determined

>>> cchord = chord.Chord(['C', 'E', 'G', 'B'])
>>> other = chord.Chord(['C', 'D', 'E', 'F', 'G', 'B'])
>>> cchord.containsSeventh() # returns True
True
>>> other.containsSeventh() # returns True
True
Chord.containsTriad()

Returns True or False if there is no triad above the root. “Contains vs. Is”: A dominant-seventh chord contains a triad.

>>> cchord = chord.Chord(['C', 'E', 'G'])
>>> other = chord.Chord(['C', 'D', 'E', 'F', 'G'])
>>> cchord.containsTriad() #returns True
True
>>> other.containsTriad() #returns True
True
>>> scale = chord.Chord(['C', 'D-', 'E', 'F#', 'G', 'A#', 'B'])
>>> scale.containsTriad() #returns True
True
Chord.findRoot()

Looks for the root usually by finding the note with the most 3rds above it.

Generally use root() instead, since if a chord doesn’t know its root, root() will run findRoot() automatically.

Example:

>>> cmaj = chord.Chord(['E', 'G', 'C'])
>>> cmaj.findRoot()
<music21.pitch.Pitch C>

For some chords we make an exception. For instance, this chord in B-flat minor:

>>> aDim7no3rd = chord.Chord(['A3', 'E-4', 'G4'])

Could be considered an type of E-flat 11 chord with a 3rd, but no 5th, 7th, or 9th, in 5th inversion. That doesn’t make sense, so we should call it an A dim 7th chord with no 3rd.

>>> aDim7no3rd.findRoot()
<music21.pitch.Pitch A3>
>>> aDim7no3rdInv = chord.Chord(['E-3', 'A4', 'G4'])
>>> aDim7no3rdInv.findRoot()
<music21.pitch.Pitch A4>

The root of a 13th chord (which could be any chord in any inversion) is designed to be the bass:

>>> chord.Chord("F3 A3 C4 E-4 G-4 B4 D5").findRoot()
<music21.pitch.Pitch F3>
>>> lotsOfNotes = chord.Chord(['E3','C4','G4','B-4','E5','G5'])
>>> r = lotsOfNotes.findRoot()
>>> r
<music21.pitch.Pitch C4>
>>> r is lotsOfNotes.pitches[1]
True
Chord.geometricNormalForm()

Geometric Normal Form, as first defined by Dmitri Tymoczko, orders pitch classes such that the spacing is prioritized with the smallest spacing between the first and second pitch class first, then the smallest spacing between second and third pitch class, and so on. This form has unique properties that make it useful.

geometricNormalForm returns a list of pitch class integers in geometric normal form.

Example 1: A major triad has geometricNormalForm of 038 not 047.

>>> c1 = chord.Chord("E4 C5 G6 C7")
>>> pcList = c1.geometricNormalForm()
>>> pcList
[0, 3, 8]
>>> c2 = chord.Chord(pcList)
>>> c2.orderedPitchClassesString
'<038>'

Compare this to the usual normalForm:

>>> c1.normalForm
[0, 4, 7]
Chord.getChordStep(chordStep, testRoot=None)

Returns the (first) pitch at the provided scaleDegree (Thus, it’s exactly like semitonesFromChordStep, except it instead of the number of semitones.)

Returns None if none can be found.

>>> cmaj = chord.Chord(['C', 'E', 'G'])
>>> cmaj.getChordStep(3) # will retur the third of the chord
<music21.pitch.Pitch E>
>>> g = cmaj.getChordStep(5) # will return the fifth of the chord
>>> g.name
'G'
>>> cmaj.getChordStep(6) is None
True
Chord.getColor(pitchTarget)

For a pitch in this Chord, return the color stored in self.editorial, or, if set for each component, return the color assigned to this component.

Chord.getNotehead(p)

Given a pitch in this Chord, return an associated notehead attribute, or return ‘normal’ if not defined for that Pitch.

If the pitch is not found, None will be returned.

>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> n2.notehead = 'diamond'
>>> c1 = chord.Chord([n1, n2])
>>> c1.getNotehead(c1.pitches[1])
'diamond'
>>> c1.getNotehead(c1.pitches[0])
'normal'
>>> c1.getNotehead(pitch.Pitch('A#6')) is None
True
Chord.getStemDirection(p)

Given a pitch in this Chord, return an associated stem attribute, or return ‘unspecified’ if not defined for that Pitch.

If the pitch is not found, None will be returned.

>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> n2.stemDirection = 'double'
>>> c1 = chord.Chord([n1, n2])
>>> c1.getStemDirection(c1.pitches[1])
'double'
>>> c1.getStemDirection(c1.pitches[0])
'unspecified'
Chord.getTie(p)

Given a pitch in this Chord, return an associated Tie object, or return None if not defined for that Pitch.

>>> c1 = chord.Chord(['d', 'e-', 'b-'])
>>> t1 = tie.Tie('start')
>>> c1.setTie(t1, c1.pitches[2]) # just to b-
>>> c1.getTie(c1.pitches[2]) == t1
True
>>> c1.getTie(c1.pitches[0]) == None
True
Chord.getVolume(p)

For a given Pitch in this Chord, return the Volume object.

Chord.getZRelation()

Return a Z relation if it exists, otherwise return None.

>>> chord.fromIntervalVector((1,1,1,1,1,1))
<music21.chord.Chord C C# E F#>
>>> chord.fromIntervalVector((1,1,1,1,1,1)).getZRelation()
<music21.chord.Chord C C# E- G>
Chord.hasAnyRepeatedDiatonicNote(testRoot=None)

Returns True if for any diatonic note (e.g., C or C# = C) there are two or more different notes (such as E and E-) in the chord. If there are no repeated scale degrees, return false.

>>> cchord = chord.Chord (['C', 'E', 'E-', 'G'])
>>> other = chord.Chord (['C', 'E', 'F-', 'G'])
>>> cchord.hasAnyRepeatedDiatonicNote()
True
>>> other.hasAnyRepeatedDiatonicNote() # returns false (chromatically identical notes of different scale degrees do not count).
False
Chord.hasComponentVolumes()

Utility method to determine if this object has component Volume objects assigned to each note-component.

>>> c1 = chord.Chord(['c4', 'd-1', 'g6'])
>>> c1.volume = [60, 20, 120]
>>> [n.volume.velocity for n in c1]
[60, 20, 120]
>>> c1.hasComponentVolumes()
True
>>> c2 = chord.Chord(['c4', 'd-1', 'g6'])
>>> c2.volume.velocity = 23
>>> c2.hasComponentVolumes()
False
>>> c3 = chord.Chord(['c4', 'd-1', 'g6'])
>>> c3.volume = [.2, .5, .8]
>>> [n.volume.velocity for n in c3]
[25, 64, 102]
>>> c4 = chord.Chord(['c4', 'd-1', 'g6'])
>>> c4.volume = 89
>>> c4.volume.velocity
89
>>> c4.hasComponentVolumes()
False
Chord.hasRepeatedChordStep(chordStep, testRoot=None)

Returns True if chordStep above testRoot (or self.root()) has two or more different notes (such as E and E-) in it. Otherwise returns false.

>>> cchord = chord.Chord (['G2', 'E4', 'E-5', 'C6'])
>>> cchord.hasRepeatedChordStep(3)
True
>>> cchord.hasRepeatedChordStep(5)
False
Chord.intervalFromChordStep(chordStep, testRoot=None)

Exactly like semitonesFromChordStep, except it returns the interval itself instead of the number of semitones:

>>> cmaj = chord.Chord(['C', 'E', 'G'])
>>> cmaj.intervalFromChordStep(3) #will return the interval between C and E
<music21.interval.Interval M3>
>>> cmaj.intervalFromChordStep(5) #will return the interval between C and G
<music21.interval.Interval P5>
>>> print(cmaj.intervalFromChordStep(6))
None
Chord.inversion(newInversion=None, find=True, testRoot=None, transposeOnSet=True)

Returns an integer representing which inversion (if any) the chord is in. Chord does not have to be complete, but determines the inversion by looking at the relationship of the bass note to the root. Returns max value of 5 for inversion of a thirteenth chord. Returns 0 if bass to root interval is 1 or if interval is not a common inversion (1st-5th). Octave of bass and root are irrelevant to this calculation of inversion.

Method doesn’t check to see if inversion is reasonable according to the chord provided (if only two pitches given, an inversion is still returned) see inversionIsValid() for checker method on ChordSymbolObjects.

>>> a = chord.Chord(['g4', 'b4', 'd5', 'f5'])
>>> a.inversion()
0
>>> a.inversion(1)
>>> a
<music21.chord.Chord B4 D5 F5 G5>
>>> a.inversion(1)


With implicit octaves, D becomes the bass (since octaves start on C):

>>> a = chord.Chord(['g', 'b', 'd', 'f'])
>>> a.inversion()
2

Note that in inverting a chord with implicit octaves, some
pitches will gain octave designations, but not necessarily all of them:

>>> a.inversion(1)
>>> a
<music21.chord.Chord B D5 F5 G5>
>>> CTriad1stInversion = chord.Chord(['E1', 'G1', 'C2'])
>>> CTriad1stInversion.inversion()
1
>>> CTriad2ndInversion = chord.Chord(['G1', 'E2', 'C2'])
>>> CTriad2ndInversion.inversion()
2
>>> DSeventh3rdInversion = chord.Chord(['C4', 'B4'])
>>> DSeventh3rdInversion.bass(pitch.Pitch('B4'))
>>> DSeventh3rdInversion.inversion()
3
>>> GNinth4thInversion = chord.Chord(['G4', 'B4', 'D5', 'F5', 'A4'])
>>> GNinth4thInversion.bass(pitch.Pitch('A4'))
>>> GNinth4thInversion.inversion()
4
>>> BbEleventh5thInversion = chord.Chord(['B-','D','F','A','C','E-'])
>>> BbEleventh5thInversion.bass(pitch.Pitch('E-4'))
>>> BbEleventh5thInversion.inversion()
5
>>> GMajRepeats = chord.Chord(['G4','B5','G6','B6','D7'])
>>> GMajRepeats.inversion(2)
>>> GMajRepeats
<music21.chord.Chord D7 G7 B7 G8 B8>

>>> GMajRepeats.inversion(3)
Traceback (most recent call last):
ChordException: Could not invert chord...inversion may not exist

If testRoot is True then that temporary root is used instead of self.root()

Chord.inversionName()

Returns an integer representing the common abbreviation for the inversion the chord is in. If chord is not in a common inversion, returns None.

Third inversion sevenths return 42 not 2.

>>> a = chord.Chord(['G3', 'B3', 'F3', 'D3'])
>>> a.inversionName()
43
Chord.isAugmentedSixth()

returns True if the chord is an Augmented 6th chord in first inversion. (N.B. a French/Swiss sixth technically needs to be in second inversion)

>>> c = chord.Chord(['A-3','C4','E-4','F#4'])
>>> c.isAugmentedSixth()
True

Spelling matters

>>> c.pitches[3].getEnharmonic(inPlace = True)
>>> c
<music21.chord.Chord A-3 C4 E-4 G-4>
>>> c.isAugmentedSixth()
False
Chord.isAugmentedTriad()

Returns True if chord is an Augmented Triad, that is, if it contains only notes that are either in unison with the root, a major third above the root, or an augmented fifth above the root. Additionally, must contain at least one of each third and fifth above the root. Chord might NOT seem to have to be spelled correctly because incorrectly spelled Augmented Triads are usually augmented triads in some other inversion (e.g. C-E-Ab is a 2nd inversion aug triad; C-Fb-Ab is 1st inversion). However, B#-Fb-Ab does return False as expeccted).

Returns false if is not an augmented triad.

>>> c = chord.Chord(["C4", "E4", "G#4"])
>>> c.isAugmentedTriad()
True
>>> c = chord.Chord(["C4", "E4", "G4"])
>>> c.isAugmentedTriad()
False

Other spellings will give other roots! >>> c = chord.Chord([“C4”, “E4”, “A-4”]) >>> c.isAugmentedTriad() True >>> c.root() <music21.pitch.Pitch A-4>

>>> c = chord.Chord(["C4", "F-4", "A-4"])
>>> c.isAugmentedTriad()
True
>>> c = chord.Chord(["B#4", "F-4", "A-4"])
>>> c.isAugmentedTriad()
False
Chord.isConsonant()
returns True if the chord is
one pitch two pitches: uses isConsonant() , which checks if interval is a major or minor third or sixth or perfect fifth. three pitches: if chord is a major or minor triad not in second inversion.

These rules define all common-practice consonances (and earlier back to about 1300 all imperfect consonances)

>>> c1 = chord.Chord(['C3', 'E4', 'G5'])
>>> c1.isConsonant()
True
>>> c2 = chord.Chord(['G3', 'E-4', 'C5'])
>>> c2.isConsonant()
False
>>> c3 = chord.Chord(['F2','A2','C3','E-3'])
>>> c3.isConsonant()
False
>>> c4 = chord.Chord(['C1','G1','C2','G2','C3','G3'])
>>> c4.isConsonant()
True
>>> c5 = chord.Chord(['G1','C2','G2','C3','G3'])
>>> c5.isConsonant()
False
>>> c6 = chord.Chord(['F#'])
>>> c6.isConsonant()
True
>>> c7 = chord.Chord(['C1','C#1','D-1'])
>>> c7.isConsonant()
False

Spelling does matter

>>> c8 = chord.Chord(['D-4','G#4'])
>>> c8.isConsonant()
False
>>> c9 = chord.Chord(['D3','A2','D2','D2','A4'])
>>> c9.isConsonant()
True
>>> c10 = chord.Chord(['D3','A2','D2','D2','A1'])
>>> c10.isConsonant()
False
>>> c11 = chord.Chord(['F3','D4','A4'])
>>> c11.isConsonant()
True
>>> c12 = chord.Chord(['F3','D4','A4','E#4'])
>>> c12.isConsonant()
False
Chord.isDiminishedSeventh()

Returns True if chord is a Diminished Seventh, that is, if it contains only notes that are either in unison with the root, a minor third above the root, a diminished fifth, or a minor seventh above the root. Additionally, must contain at least one of each third and fifth above the root. Chord must be spelled correctly. Otherwise returns false.

>>> a = chord.Chord(['c', 'e-', 'g-', 'b--'])
>>> a.isDiminishedSeventh()
True
Chord.isDiminishedTriad()

Returns True if chord is a Diminished Triad, that is, if it contains only notes that are either in unison with the root, a minor third above the root, or a diminished fifth above the root. Additionally, must contain at least one of each third and fifth above the root. Chord must be spelled correctly. Otherwise returns false.

>>> cchord = chord.Chord(['C', 'E-', 'G-'])
>>> other = chord.Chord(['C', 'E-', 'F#'])
>>> cchord.isDiminishedTriad() #returns True
True
>>> other.isDiminishedTriad() #returns False
False
Chord.isDominantSeventh()

Returns True if chord is a Dominant Seventh, that is, if it contains only notes that are either in unison with the root, a major third above the root, a perfect fifth, or a major seventh above the root. Additionally, must contain at least one of each third and fifth above the root. Chord must be spelled correctly. Otherwise returns false.

>>> a = chord.Chord(['b', 'g', 'd', 'f'])
>>> a.isDominantSeventh()
True
Chord.isFalseDiminishedSeventh()

Returns True if chord is a Diminished Seventh, that is, if it contains only notes that are either in unison with the root, a minor third above the root, a diminished fifth, or a minor seventh above the root. Additionally, must contain at least one of each third and fifth above the root. Chord MAY BE SPELLED INCORRECTLY. Otherwise returns false.

Chord.isFrenchAugmentedSixth()

Returns True if the chord is a French augmented sixth chord (flat 6th scale degree in bass, tonic, second scale degree, and raised 4th).

N.B. The findRoot() method of music21.chord Chord determines the root based on the note with the most thirds above it. However, under this definition, a 1st-inversion french augmented sixth chord resembles a second inversion chord, not the first inversion subdominant chord it is based upon. We fix this by adjusting the root. First, however, we check to see if the chord is in second inversion to begin with, otherwise its not a Fr+6 chord. This is to avoid ChordException errors.

>>> fr6a = chord.Chord(['A-3','C4','D4','F#4'])
>>> fr6a.isFrenchAugmentedSixth()
True
>>> fr6b = chord.Chord(['A-3','C4','E--4','F#4'])
>>> fr6b.isFrenchAugmentedSixth()
False
Chord.isGermanAugmentedSixth()
Chord.isHalfDiminishedSeventh()

Returns True if chord is a Half Diminished Seventh, that is, if it contains only notes that are either in unison with the root, a minor third above the root, a diminished fifth, or a major seventh above the root. Additionally, must contain at least one of each third, fifth, and seventh above the root. Chord must be spelled correctly. Otherwise returns false.

>>> c1 = chord.Chord(['C4','E-4','G-4','B-4'])
>>> c1.isHalfDiminishedSeventh()
True

Incorrectly spelled chords are not considered half-diminished sevenths >>> c2 = chord.Chord([‘C4’,’E-4’,’G-4’,’A#4’]) >>> c2.isHalfDiminishedSeventh() False

Nor are incomplete chords >>> c3 = chord.Chord([‘C4’, ‘G-4’,’B-4’]) >>> c3.isHalfDiminishedSeventh() False

Chord.isIncompleteMajorTriad()

Returns True if the chord is an incomplete Major triad, or, essentially, a dyad of root and major third

>>> c1 = chord.Chord(['C4','E3'])
>>> c1.isMajorTriad()
False
>>> c1.isIncompleteMajorTriad()
True

Note that complete major triads return False:

>>> c2 = chord.Chord(['C4','E3', 'G5'])
>>> c2.isIncompleteMajorTriad()
False
Chord.isIncompleteMinorTriad()

returns True if the chord is an incomplete Minor triad, or, essentially, a dyad of root and minor third

>>> c1 = chord.Chord(['C4','E-3'])
>>> c1.isMinorTriad()
False
>>> c1.isIncompleteMinorTriad()
True
>>> c2 = chord.Chord(['C4','E-3', 'G5'])
>>> c2.isIncompleteMinorTriad()
False
Chord.isItalianAugmentedSixth(restrictDoublings=False)

Returns true if the chord is a properly spelled Italian augmented sixth chord in first inversion.

If restrictDoublings is set to True then only the tonic may be doubled.

>>> c1 = chord.Chord(['A-4','C5','F#6'])
>>> c1.isItalianAugmentedSixth()
True

Spelling and inversions matter

>>> c2 = chord.Chord(['A-4','C5','G-6'])
>>> c2.isItalianAugmentedSixth()
False
>>> c3 = chord.Chord(['F#4','C5','A-6'])
>>> c3.isItalianAugmentedSixth()
False

If doubling rules are turned on then only the tonic can be doubled:

>>> c4 = chord.Chord(['A-4','C5','F#6', 'C6', 'C7'])
>>> c4.isItalianAugmentedSixth(restrictDoublings = True)
True
>>> c5 = chord.Chord(['A-4','C5','F#6', 'C5', 'F#7'])
>>> c5.isItalianAugmentedSixth(restrictDoublings = True)
False
>>> c5.isItalianAugmentedSixth(restrictDoublings = False)
True
Chord.isMajorTriad()

Returns True if chord is a Major Triad, that is, if it contains only notes that are either in unison with the root, a major third above the root, or a perfect fifth above the root. Additionally, must contain at least one of each third and fifth above the root. Chord must be spelled correctly. Otherwise returns false.

Example:

>>> cchord = chord.Chord(['C', 'E', 'G'])
>>> other = chord.Chord(['C', 'G'])
>>> cchord.isMajorTriad() # returns True
True
>>> other.isMajorTriad() # returns False
False
Chord.isMinorTriad()

Returns True if chord is a Minor Triad, that is, if it contains only notes that are either in unison with the root, a minor third above the root, or a perfect fifth above the root. Additionally, must contain at least one of each third and fifth above the root. Chord must be spelled correctly. Otherwise returns false.

Example:

>>> cchord = chord.Chord(['C', 'E-', 'G'])
>>> other = chord.Chord(['C', 'E', 'G'])
>>> cchord.isMinorTriad() # returns True
True
>>> other.isMinorTriad() # returns False
False
Chord.isSeventh()

Returns True if chord contains at least one of each of Third, Fifth, and Seventh, and every note in the chord is a Third, Fifth, or Seventh, such that there are no repeated scale degrees (ex: E and E-). Else return false.

Example:

>>> cchord = chord.Chord(['C', 'E', 'G', 'B'])
>>> other = chord.Chord(['C', 'D', 'E', 'F', 'G', 'B'])
>>> cchord.isSeventh() # returns True
True
>>> other.isSeventh() # returns False
False
Chord.isSwissAugmentedSixth()

Returns true is it is a respelled German augmented 6th chord with sharp 2 instead of flat 3. This chord has many names, Swiss Augmented Sixth, Alsatian Chord, English A6, Norwegian, etc. as well as doubly-augmented sixth, which is a bit of a misnomer since it is the 4th that is doubly augmented, not the sixth.

Chord.isTriad()

Returns boolean.

“Contains vs. Is:” A dominant-seventh chord is NOT a triad. returns True if the chord contains at least one Third and one Fifth and all notes are equivalent to either of those notes. Only returns True if triad is spelled correctly.

>>> cchord = chord.Chord(['C4', 'E4', 'A4'])
>>> other = chord.Chord(['C', 'D', 'E', 'F', 'G'])
>>> cchord.isTriad() # returns True
True
>>> other.isTriad()
False
>>> incorrectlySpelled = chord.Chord(['C','D#','G'])
>>> incorrectlySpelled.isTriad()
False
>>> incorrectlySpelled.pitches[1].getEnharmonic(inPlace = True)
>>> incorrectlySpelled.isTriad()
True
Chord.removeRedundantPitchClasses(inPlace=True)

Remove all but the FIRST instance of a pitch class with more than one instance of that pitch class.

If inPlace is True, a copy is not made and None is returned; otherwise a copy is made and that copy is returned.

>>> c1 = chord.Chord(['c2', 'e3', 'g4', 'e3'])
>>> c1.removeRedundantPitchClasses(inPlace=True)
>>> c1.pitches
(<music21.pitch.Pitch C2>, <music21.pitch.Pitch G4>, <music21.pitch.Pitch E3>)
>>> c2 = chord.Chord(['c5', 'e3', 'g4', 'c2', 'e3', 'f-4'])
>>> c2.removeRedundantPitchClasses(inPlace=True)
>>> c2.pitches
(<music21.pitch.Pitch C5>, <music21.pitch.Pitch G4>, <music21.pitch.Pitch E3>)
Chord.removeRedundantPitchNames(inPlace=True)

Remove all but the FIRST instance of a pitch class with more than one instance of that pitch name regardless of octave (but note that spelling matters, so that in the example, the F-flat stays even though there is already an E.)

If inPlace is True, a copy is not made and None is returned; otherwise a copy is made and that copy is returned.

>>> c2 = chord.Chord(['c5', 'e3', 'g4', 'c2', 'e3', 'f-4'])
>>> c2
<music21.chord.Chord C5 E3 G4 C2 E3 F-4>
>>> c2.removeRedundantPitchNames(inPlace = True)
>>> c2
<music21.chord.Chord C5 G4 E3 F-4>
Chord.removeRedundantPitches(inPlace=True)

Remove all but one instance of a pitch that appears twice.

It removes based on the name of the note and the octave, so the same note name in two different octaves is retained.

If inPlace is True, a copy is not made and None is returned; otherwise a copy is made and that copy is returned.

>>> c1 = chord.Chord(['c2', 'e3', 'g4', 'e3'])
>>> c1
<music21.chord.Chord C2 E3 G4 E3>
>>> c1.removeRedundantPitches(inPlace=True)
>>> c1
<music21.chord.Chord C2 G4 E3>
>>> c1.forteClass
'3-11B'
>>> c2 = chord.Chord(['c2', 'e3', 'g4', 'c5'])
>>> c2c = c2.removeRedundantPitches(inPlace=False)
>>> c2c
<music21.chord.Chord C2 E3 G4 C5>

It is a known bug that because pitch.nameWithOctave gives the same value for B-flat in octave 1 as B-natural in octave negative 1, negative octaves can screw up this method. With all the things left to do for music21, it doesn’t seem a bug worth squashing at this moment, but FYI:

>>> p1 = pitch.Pitch('B-')
>>> p1.octave = 1
>>> p2 = pitch.Pitch('B')
>>> p2.octave = -1
>>> c3 = chord.Chord([p1, p2])
>>> c3.removeRedundantPitches(inPlace=True)
>>> c3.pitches
(<music21.pitch.Pitch B-1>,)

The first pitch survives:

>>> c3.pitches[0] is p1
True
>>> c3.pitches[0] is p2
False
Chord.root(newroot=False, find=True)

Returns or sets the Root of the chord. If not set, will run findRoot (q.v.)

>>> cmaj = chord.Chord(['E3', 'C4', 'G5'])
>>> cmaj.root()
<music21.pitch.Pitch C4>

By default this method uses an algorithm to find the root among the chord’s pitches, if no root has been previously specified. If this is not intended, set find to False when calling this method, and ‘None’ will be returned if no root is specified

>>> c = chord.Chord(['E3','G3','B4'])
>>> c.root(find=False) == None
True
>>> d = harmony.ChordSymbol('CM/E')
>>> d.root(find=False) == None
True
>>> d.root()
<music21.pitch.Pitch C4>
Chord.seekChordTablesAddress()

Utility method to return the address to the chord table.

Table addresses are TN based three character codes: cardinaltiy, Forte index number, inversion

Inversion is either 0 (for symmetrical) or -1/1

NOTE: time consuming, and only should be run when necessary.

>>> c1 = chord.Chord(['c3'])
>>> c1.orderedPitchClasses
[0]
>>> c1.seekChordTablesAddress()
(1, 1, 0)
>>> c1 = chord.Chord(
...     ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'b']
...     )
>>> c1.seekChordTablesAddress()
(11, 1, 0)
>>> c1 = chord.Chord(['c', 'e', 'g'])
>>> c1.seekChordTablesAddress()
(3, 11, -1)
>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.seekChordTablesAddress()
(3, 11, 1)
>>> c1 = chord.Chord(['c', 'c#', 'd#', 'e', 'f#', 'g#', 'a#'])
>>> c1.seekChordTablesAddress()
(7, 34, 0)
>>> c1 = chord.Chord(['c', 'c#', 'd'])
>>> c1.seekChordTablesAddress()
(3, 1, 0)
Chord.semiClosedPosition(forceOctave=None, inPlace=False, leaveRedundantPitches=False)

Similar to ClosedPosition() in that it moves everything within an octave EXCEPT if there’s already a pitch at that step, then it puts it up an octave. It’s a very useful display standard for dense post-tonal chords.

>>> c1 = chord.Chord(['C3','E5','C#6','E-7', 'G8','C9','E#9'])
>>> c2 = c1.semiClosedPosition(inPlace=False)
>>> c2
<music21.chord.Chord C3 E-3 G3 C#4 E4 E#5>

leaveRedundantPitches still works, and gives them a new octave!

>>> c3 = c1.semiClosedPosition(
...     inPlace=False,
...     leaveRedundantPitches=True,
...     )
>>> c3
<music21.chord.Chord C3 E-3 G3 C4 E4 C#5 E#5>

of course forceOctave still works, as does inPlace=True.

>>> c1.semiClosedPosition(
...     forceOctave=2,
...     inPlace=True,
...     leaveRedundantPitches=True,
...     )
>>> c1
<music21.chord.Chord C2 E-2 G2 C3 E3 C#4 E#4>
Chord.semitonesFromChordStep(chordStep, testRoot=None)

Returns the number of semitones (mod12) above the root that the chordStep lies (i.e., 3 = third of the chord; 5 = fifth, etc.) if one exists. Or None if it does not exist.

You can optionally specify a note.Note object to try as the root. It does not change the Chord.root object. We use these methods to figure out what the root of the triad is.

Currently there is a bug that in the case of a triply diminished third (e.g., “c” => “e—-”), this function will incorrectly claim no third exists. Perhaps this should be construed as a feature.

In the case of chords such as C, E-, E, semitonesFromChordStep(3) will return the number for the first third, in this case 3. It will not return 4, nor a list object (3,4). You probably do not want to be using tonal chord manipulation functions on chords such as these anyway. Check for such cases with chord.hasAnyRepeatedDiatonicNote first.

Tools with the expression “chordStep” in them refer to the diatonic third, fifth, etc., of the chord. They have little to do with the scale degree of the scale or key that the chord is embedded within. See “chord.scaleDegrees” for this functionality.

>>> cchord = chord.Chord(['E3', 'C4', 'G5'])
>>> cchord.semitonesFromChordStep(3) # distance from C to E
4
>>> cchord.semitonesFromChordStep(5) # C to G
7
>>> print cchord.semitonesFromChordStep(6) # will return None
None
>>> achord = chord.Chord(['a2', 'c4', 'c#5', 'e#7'])
>>> achord.semitonesFromChordStep(3) # returns the semitones to the FIRST third.
3
>>> achord.semitonesFromChordStep(5)
8
>>> print achord.semitonesFromChordStep(2) # will return None
None
Chord.setColor(value, pitchTarget=None)

Set color for specific pitch.

Chord.setNotehead(nh, pitchTarget)

Given a notehead attribute as a string and a pitch object in this Chord, set the notehead attribute of that pitch to the value of that notehead. Valid notehead type names are found in note.noteheadTypeNames (see below):

>>> for noteheadType in note.noteheadTypeNames:
...    noteheadType
...
'arrow down'
'arrow up'
'back slashed'
'circle dot'
'circle-x'
'cluster'
'cross'
'diamond'
'do'
'fa'
'inverted triangle'
'la'
'left triangle'
'mi'
'none'
'normal'
're'
'rectangle'
'slash'
'slashed'
'so'
'square'
'ti'
'triangle'
'x'
>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> c1 = chord.Chord([n1, n2])
>>> c1.setNotehead('diamond', c1.pitches[1]) # just to g
>>> c1.getNotehead(c1.pitches[1])
'diamond'
>>> c1.getNotehead(c1.pitches[0])
'normal'

If a chord has two of the same pitch, but each associated with a different notehead, then object equality must be used to distinguish between the two.

>>> c2 = chord.Chord(['D4','D4'])
>>> secondD4 = c2.pitches[1]
>>> c2.setNotehead('diamond', secondD4)
>>> for i in [0,1]:
...     c2.getNotehead(c2.pitches[i])
...
'normal'
'diamond'
Chord.setStemDirection(stem, pitchTarget)

Given a stem attribute as a string and a pitch object in this Chord, set the stem attribute of that pitch to the value of that stem. Valid stem directions are found note.stemDirectionNames (see below).

>>> for name in note.stemDirectionNames:
...     name
...
'double'
'down'
'noStem'
'none'
'unspecified'
'up'
>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> c1 = chord.Chord([n1, n2])
>>> c1.setStemDirection('double', c1.pitches[1]) # just to g
>>> c1.getStemDirection(c1.pitches[1])
'double'
>>> c1.getStemDirection(c1.pitches[0])
'unspecified'

If a chord has two of the same pitch, but each associated with a different stem, then object equality must be used to distinguish between the two.

>>> c2 = chord.Chord(['D4','D4'])
>>> secondD4 = c2.pitches[1]
>>> c2.setStemDirection('double', secondD4)
>>> for i in [0,1]:
...    print c2.getStemDirection(c2.pitches[i])
...
unspecified
double
Chord.setTie(t, pitchTarget)

Given a tie object (or a tie type string) and a pitch in this Chord, set the pitch’s tie attribute in this chord to that tie type.

>>> c1 = chord.Chord(['d3', 'e-4', 'b-4'])
>>> t1 = tie.Tie('start')
>>> c1.setTie(t1, 'b-4') # or it can be done with a pitch.Pitch object
>>> c1.getTie(c1.pitches[2]) == t1
True

Setting a tie with a chord with the same pitch twice requires getting the exact pitch object out to be sure which one...

>>> c2 = chord.Chord(['D4','D4'])
>>> secondD4 = c2.pitches[1]
>>> c2.setTie('start', secondD4)
>>> for i in [0,1]:
...    print c2.getTie(c2.pitches[i])
...
None
<music21.tie.Tie start>
Chord.setVolume(vol, pitchTarget=None)

Set the Volume object of a specific pitch target. If no pitch target is given, the first pitch is used.

Chord.sortAscending(inPlace=False)
Chord.sortChromaticAscending()

Same as sortAscending but notes are sorted by midi number, so F## sorts above G-.

Chord.sortDiatonicAscending(inPlace=False)

The notes are sorted by Scale degree and then by Offset (so F## sorts below G-). Notes that are the identical pitch retain their order

After talking with Daniel Jackson, let’s try to make the chord object as immutable as possible, so we return a new Chord object with the notes arranged from lowest to highest

>>> cMajUnsorted = chord.Chord(['E4', 'C4', 'G4'])
>>> cMajSorted = cMajUnsorted.sortDiatonicAscending()
>>> cMajSorted.pitches[0].name
'C'
>>> c2 = chord.Chord(['E4', 'C4', 'G4'])
>>> junk = c2.sortDiatonicAscending(inPlace=True)
>>> c2
<music21.chord.Chord C4 E4 G4>
Chord.sortFrequencyAscending()

Same as above, but uses a note’s frequency to determine height; so that C# would be below D- in 1/4-comma meantone, equal in equal temperament, but below it in (most) just intonation types.

Chord.transpose(value, inPlace=False)

Transpose the Note by the user-provided value. If the value is an integer, the transposition is treated in half steps and enharmonics might be simplified (not done yet). If the value is a string, any Interval string specification can be provided.

If inPlace is set to True (default = False) then the original chord is changed. Otherwise a new Chord is returned.

We take a three-note chord (G, A, C#) and transpose it up a minor third, getting the chord B-flat, C, E.

>>> a = chord.Chord(['g4', 'a3', 'c#6'])
>>> b = a.transpose('m3')
>>> b
<music21.chord.Chord B-4 C4 E6>

Here we create the interval object first (rather than giving a string) and specify transposing down six semitones, instead of saying A-4.

>>> aInterval = interval.Interval(-6)
>>> b = a.transpose(aInterval)
>>> b
<music21.chord.Chord C#4 D#3 F##5>

If inPlace is True then rather than returning a new chord, the chord itself is changed.

>>> a.transpose(aInterval, inPlace=True)
>>> a
<music21.chord.Chord C#4 D#3 F##5>

Methods inherited from GeneralNote:

Methods inherited from Music21Object:

Chord instance variables

Chord.articulations

a list of articulations (such as Staccato, etc.) that are stored on this Note.

Chord.beams

A music21.beam.Beams object.

Chord.expressions

a list of expressions (such as Fermata, etc.) that are stored on this Note.

Chord.isChord

Boolean read-only value describing if this GeneralNote object is a Chord. Is True

Chord.isNote

Boolean read-only value describing if this GeneralNote object is a Note. Is False

Chord.isRest

Boolean read-only value describing if this GeneralNote object is a Rest. Is False

Chord.lyrics

A list of Lyric objects.

Chord.tie

either None or a Tie object.

Instance variables inherited from NotRest:

  • lyrics
  • beams
  • isRest
  • tie
  • isChord
  • expressions
  • isNote
  • articulations

Instance variables inherited from GeneralNote:

Instance variables inherited from Music21Object: