Class for dealing with chords A Chord is an object composed of Notes. Create chords by creating notes: C = note.Note(), C.name = ‘C’ E = note.Note(), E.name = ‘E’ G = note.Note(), G.name = ‘G’ And then create a chord with notes: cmaj = Chord([C, E, G]) 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. NOTE: For now, the examples used in documentation give chords made from notes that are not defined. In the future, it may be possible to define a chord without first creating notes, but for now note that notes that appear in chords are simply shorthand instead of creating notes for use in examples
inherits from: NotRest, GeneralNote, Music21Object
Chord attributes
- isChord¶
- Boolean read-only value describing if this object is a Chord.
- isNote¶
- Boolean read-only value describing if this object is a Chord.
- isRest¶
- Boolean read-only value describing if this is a Rest.
- beams¶
- A music21.note.Beams object.
Attributes inherited from NotRest: stemDirection
Attributes inherited from GeneralNote: lyrics, notations, editorial, tie, articulations
Attributes inherited from Music21Object: id, groups
Chord properties
- pitches¶
Return a list of all Pitch objects in this Chord.
>>> c = Chord(["C4", "E4", "G#4"]) >>> c.pitches [C4, E4, G#4] >>> [p.midi for p in c.pitches] [60, 64, 68]
- chordTablesAddress¶
Return a triple tuple that represents that raw data location for information on the set class interpretation of this Chord. The data format is Forte set class cardinality, index number, and inversion status (where 0 is invariant, and -1 and 1 represent inverted or not, respectively).
>>> c = Chord(["C4", "E4", "G#4"]) >>> c.chordTablesAddress (3, 12, 0)
- commonName¶
Return a list of common names as strings that are associated with this Chord.
>>> c2 = Chord(['c', 'e', 'g']) >>> c2.commonName ['major triad']
- forteClass¶
Return the Forte set class name as a string. This assumes a Tn formation, where inversion distinctions are represented.
>>> c2 = Chord(['c', 'e', 'g']) >>> c2.forteClass '3-11B'
- 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.
>>> c2 = Chord(['c', 'e', 'g']) >>> c2.forteClassNumber 11
- forteClassTn¶
Return the Forte Tn set class name, where inversion distinctions are represented.
>>> c2 = Chord(['c', 'e', 'g']) >>> c2.forteClassTn '3-11B'
- forteClassTnI¶
Return the Forte TnI class name, where inversion distinctions are not represented.
>>> c2 = Chord(['c', 'e', 'g']) >>> c2.forteClassTnI '3-11'
- hasZRelation¶
Return True or False if the Chord has a Z-relation.
>>> c1 = Chord(['c', 'e-', 'g']) >>> c1.hasZRelation False
- intervalVector¶
Return the interval vector for this Chord as a list of integers.
>>> c2 = Chord(['c', 'e', 'g']) >>> c2.intervalVector [0, 0, 1, 1, 1, 0]
- intervalVectorString¶
Return the interval vector as a string representation.
>>> c1 = Chord(['c', 'e-', 'g']) >>> c1.intervalVectorString '<001110>'
- isPrimeFormInversion¶
Return True or False if the Chord represents a set class inversion.
>>> c1 = Chord(['c', 'e-', 'g']) >>> c1.isPrimeFormInversion False >>> c2 = Chord(['c', 'e', 'g']) >>> c2.isPrimeFormInversion True
- lily¶
- The name of the note as it would appear in Lilypond format.
- multisetCardinality¶
Return an integer representing the cardinality of the mutliset, or the number of pitch values.
>>> c1 = Chord(["D4", "A4", "F#5", "D6"]) >>> c1.multisetCardinality 4
- mx¶
Returns a List of mxNotes Attributes of notes are merged from different locations: first from the duration objects, then from the pitch objects. Finally, GeneralNote attributes are added
>>> a = Chord() >>> a.quarterLength = 2 >>> b = pitch.Pitch('A-') >>> c = pitch.Pitch('D-') >>> d = pitch.Pitch('E-') >>> e = a.pitches = [b, c, d] >>> len(e) 3 >>> mxNoteList = a.mx >>> len(mxNoteList) # get three mxNotes 3 >>> mxNoteList[0].get('chord') False >>> mxNoteList[1].get('chord') True >>> mxNoteList[2].get('chord') True
- normalForm¶
Return the normal form of the Chord represented as a list of integers.
>>> c2 = Chord(['c', 'e', 'g']) >>> c2.normalForm [0, 4, 7]
- normalFormString¶
Return a string representation of the normal form of the Chord.
>>> c1 = Chord(['f#', 'e-', 'g']) >>> c1.normalFormString '<034>'
- orderedPitchClasses¶
Return an list of pitch class integers, ordered form lowest to highest.
>>> c1 = Chord(["D4", "A4", "F#5", "D6"]) >>> c1.orderedPitchClasses [2, 6, 9]
- orderedPitchClassesString¶
Return a string representation of the pitch class values.
>>> c1 = Chord(['f#', 'e-', 'g']) >>> c1.orderedPitchClassesString '<367>'
- pitchClassCardinality¶
Return a the cardinality of pitch classes, or the number of unique pitch classes, in the Chord.
>>> c1 = Chord(["D4", "A4", "F#5", "D6"]) >>> c1.pitchClassCardinality 3
- pitchClasses¶
Return a list of all pitch classes in the chord as integers.
>>> c1 = Chord(["D4", "A4", "F#5", "D6"]) >>> c1.pitchClasses [2, 9, 6, 2]
- pitchedCommonName¶
Return the common name of this Chord preceded by its root, if a root is available.
>>> c2 = Chord(['c', 'e', 'g']) >>> c2.pitchedCommonName 'C-major triad'
- primeForm¶
Return a representation of the Chord as a prime-form list of pitch class integers.
>>> c1 = Chord(['c', 'e-', 'g']) >>> c1.primeForm [0, 3, 7]
- primeFormString¶
Return a representation of the Chord as a prime-form set class string.
>>> c1 = Chord(['c', 'e-', 'g']) >>> c1.primeFormString '<037>'Properties inherited from GeneralNote: color, lyric, musicxml, quarterLength
Properties inherited from Music21Object: offset, parent, priority
Chord methods
- areZRelations(other)¶
Check of chord other is also a z relations
>>> c1 = Chord(["C", "c#", "e", "f#"]) >>> c2 = Chord(["C", "c#", "e-", "g"]) >>> c3 = Chord(["C", "c#", "f#", "g"]) >>> c1.areZRelations(c2) True >>> c1.areZRelations(c3) False
- bass(newbass=0)¶
returns the bass note or sets it to note. 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... v o9. example:
>>> cmaj = Chord(['C', 'E', 'G']) >>> cmaj.bass() # returns C C
- canBeDominantV()¶
>>> a = Chord(['g', 'b', 'd', 'f']) >>> a.canBeDominantV() True
- canBeTonic()¶
>>> a = Chord(['g', 'b', 'd', 'f']) >>> a.canBeTonic() False >>> a = Chord(['g', 'b', 'd']) >>> a.canBeTonic() True
- checkDurationSanity()¶
- TO WRITE Checks to make sure all notes have the same duration Does not run automatically
- closedPosition()¶
returns a new Chord object with the same pitch classes, but now in closed position
>>> chord1 = Chord(["C#4", "G5", "E6"]) >>> chord2 = chord1.closedPosition() >>> print(chord2.lily.value) <cis' e' g'>4
- 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 (['C', 'E', 'G', 'B']) >>> other = Chord (['C', 'D', 'E', 'F', 'G', 'B']) >>> cchord.containsSeventh() # returns True True >>> other.containsSeventh() # returns True True
- containsTriad()¶
returns True or False if there is no triad above the root. “Contains vs. Is”: A dominant-seventh chord contains a triad. example:
>>> cchord = Chord (['C', 'E', 'G']) >>> other = Chord (['C', 'D', 'E', 'F', 'G']) >>> cchord.containsTriad() #returns True True >>> other.containsTriad() #returns True True
- determineType()¶
returns an abbreviation for the type of chord it is. Add option to add inversion name to abbreviation?
>>> a = Chord(['a', 'c#', 'e']) >>> a.determineType() 'Major Triad' >>> a = Chord(['g', 'b', 'd', 'f']) >>> a.determineType() 'Dominant Seventh'
- duration(newDur=0)¶
- Duration of the chord can be defined here OR it should return the duration of the first note of the chord
- findBass()¶
Returns the lowest note in the chord The only time findBass should be called is by bass() when it is figuring out what the bass note of the chord is. Generally call bass() instead example:
>>> cmaj = Chord (['C4', 'E3', 'G4']) >>> cmaj.findBass() # returns E3 E3
- findRoot()¶
Looks for the root 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 (['C', 'E', 'G']) >>> cmaj.findRoot() # returns C C
- hasAnyRepeatedScale(testRoot=None)¶
Returns True if for any scale degree there are two or more different notes (such as E and E-) in the chord. If there are no repeated scale degrees, return false. example:
>>> cchord = Chord (['C', 'E', 'E-', 'G']) >>> other = Chord (['C', 'E', 'F-', 'G']) >>> cchord.hasAnyRepeatedScale() True >>> other.hasAnyRepeatedScale() # returns false (chromatically identical notes of different scale degrees do not count. False
- hasFifth(testRoot=None)¶
- Shortcut for hasScaleX(5)
- hasRepeatedScaleX(scaleDeg, testRoot=None)¶
Returns True if scaleDeg above testRoot (or self.root()) has two or more different notes (such as E and E-) in it. Otherwise returns false. example:
>>> cchord = Chord (['C', 'E', 'E-', 'G']) >>> cchord.hasRepeatedScaleX(3) # returns true True
- hasScaleX(scaleDegree, testRoot=None)¶
Each of these returns the number of semitones above the root that the third, fifth, etc., of the chord lies, if there exists one. Or False 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 be construed as a feature. In the case of chords such as C, E-, E, hasThird will return 3, not 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. note.Note that in Chord, we’re using “Scale” to mean a diatonic scale step. It will not tell you if a chord has a specific scale degree in another scale system. That functionality might be added to scale.py someday. example:
>>> cchord = Chord (['C', 'E', 'E-', 'G']) >>> cchord.hasScaleX(3) # 4 >>> cchord.hasScaleX(5) # will return 7 7 >>> cchord.hasScaleX(6) # will return False False
- hasSeventh(testRoot=None)¶
- Shortcut for hasScaleX(7)
- hasSpecificX(scaleDegree, testRoot=None)¶
Exactly like hasScaleX, except it returns the interval itself instead of the number of semitones. example:
>>> cmaj = Chord (['C', 'E', 'G']) >>> cmaj.hasScaleX(3) #will return the interval between C and E 4 >>> cmaj.hasScaleX(5) #will return the interval between C and G 7 >>> cmaj.hasScaleX(6) #will return False False
- hasThird(testRoot=None)¶
- Shortcut for hasScaleX(3)
- inversion()¶
returns an integer representing which standard inversion 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.
>>> a = Chord(['g', 'b', 'd', 'f']) >>> a.inversion() 2
- 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.
>>> a = Chord(['g', 'b', 'd', 'f']) >>> a.inversionName() 43
- 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.
>>> import music21.chord >>> c = music21.chord.Chord(["C4", "E4", "G#4"]) >>> c.isAugmentedTriad() True >>> c = music21.chord.Chord(["C4", "E4", "G4"]) >>> c.isAugmentedTriad() False Other spellings will give other roots! >>> c = music21.chord.Chord(["C4", "E4", "A-4"]) >>> c.isAugmentedTriad() True >>> c.root() A-4 >>> c = music21.chord.Chord(["C4", "F-4", "A-4"]) >>> c.isAugmentedTriad() True >>> c = music21.chord.Chord(["B#4", "F-4", "A-4"]) >>> c.isAugmentedTriad() False
- 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(['c', 'e-', 'g-', 'b--']) >>> a.isDiminishedSeventh() True
- 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 (['C', 'E-', 'G-']) >>> other = Chord (['C', 'E-', 'F#']) >>> cchord.isDiminishedTriad() #returns True True >>> other.isDiminishedTriad() #returns False False
- 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(['b', 'g', 'd', 'f']) >>> a.isDominantSeventh() True
- 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.
- 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(['C4','E-4','G-4','B-4']) >>> c1.isHalfDiminishedSeventh() True Incorrectly spelled chords are not considered half-diminished sevenths >>> c2 = Chord(['C4','E-4','G-4','A#4']) >>> c2.isHalfDiminishedSeventh() False Nor are incomplete chords >>> c3 = Chord(['C4', 'G-4','B-4']) >>> c3.isHalfDiminishedSeventh() False
- 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 (['C', 'E', 'G']) >>> other = Chord (['C', 'G']) >>> cchord.isMajorTriad() # returns True True >>> other.isMajorTriad() # returns False False
- 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 (['C', 'E-', 'G']) >>> other = Chord (['C', 'E', 'G']) >>> cchord.isMinorTriad() # returns True True >>> other.isMinorTriad() # returns False False
- 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 (['C', 'E', 'G', 'B']) >>> other = Chord (['C', 'D', 'E', 'F', 'G', 'B']) >>> cchord.isSeventh() # returns True True >>> other.isSeventh() # returns False False
- isTriad()¶
returns True or False “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. example:
>>> cchord = Chord (['C', 'E', 'G']) >>> other = Chord (['C', 'D', 'E', 'F', 'G']) >>> cchord.isTriad() # returns True True >>> other.isTriad() False
- numNotes()¶
- Returns the number of notes in the chord
- root(newroot=False)¶
Returns or sets the Root of the chord. if not set, will run findRoot (q.v.) example:
>>> cmaj = Chord (['C', 'E', 'G']) >>> cmaj.root() # returns C C
- 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(['c3']) >>> c1.orderedPitchClasses [0] >>> c1.seekChordTablesAddress() (1, 1, 0) >>> c1 = Chord(['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'b']) >>> c1.seekChordTablesAddress() (11, 1, 0) >>> c1 = Chord(['c', 'e', 'g']) >>> c1.seekChordTablesAddress() (3, 11, -1) >>> c1 = Chord(['c', 'e-', 'g']) >>> c1.seekChordTablesAddress() (3, 11, 1) >>> c1 = Chord(['c', 'c#', 'd#', 'e', 'f#', 'g#', 'a#']) >>> c1.seekChordTablesAddress() (7, 34, 0) >>> c1 = Chord(['c', 'c#', 'd']) >>> c1.seekChordTablesAddress() (3, 1, 0)
- semiClosedPosition()¶
- No documentation.
- sortAscending()¶
- No documentation.
- sortChromaticAscending()¶
- Same as sortAscending but notes are sorted by midi number, so F## sorts above G-.
- sortDiatonicAscending()¶
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 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
>>> cMajUnsorted = Chord(['E4', 'C4', 'G4']) >>> cMajSorted = cMajUnsorted.sortDiatonicAscending() >>> cMajSorted.pitches[0].name 'C'
- 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.
- 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. If the value is a string, any Interval string specification can be provided.
>>> a = Chord(['g4', 'a3', 'c#6']) >>> b = a.transpose('m3') >>> b <music21.chord.Chord B-4 C4 E6> >>> aInterval = interval.Interval(-6) >>> b = a.transpose(aInterval) >>> b <music21.chord.Chord C#4 D#3 F##5> >>> a.transpose(aInterval, inPlace=True) >>> a <music21.chord.Chord C#4 D#3 F##5>Methods inherited from NotRest: splitNoteAtPoint()
Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), compactNoteInfo(), splitAtDurations()
Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocation(), searchParentByAttr(), setContextAttr(), setOffsetBySite(), show(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()