Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few ChordSymbol fixes #1702

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions music21/harmony.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
('suspended-second', ['1,2,5', ['sus2']]), # Y
('suspended-fourth', ['1,4,5', ['sus', 'sus4']]), # Y
('suspended-fourth-seventh', ['1,4,5,-7', ['7sus', '7sus4']]), # Y
('Neapolitan', ['1,2-,3,5-', ['N6']]), # Y
('Neapolitan', ['1,-2,3,-5', ['N6']]), # Y
('Italian', ['1,#4,-6', ['It+6', 'It']]), # Y
('French', ['1,2,#4,-6', ['Fr+6', 'Fr']]), # Y
('German', ['1,-3,#4,-6', ['Gr+6', 'Ger']]), # Y
Expand Down Expand Up @@ -1104,9 +1104,9 @@ def chordSymbolFigureFromChord(inChord: chord.Chord, includeChordType=False):
>>> harmony.chordSymbolFigureFromChord(c, True)
('CGr+6', 'German')

>>> c = chord.Chord(['C3'])
>>> harmony.chordSymbolFigureFromChord(c, True)
('Cpedal', 'pedal')
>>> eflat = chord.Chord(['E-3'])
>>> harmony.chordSymbolFigureFromChord(eflat, True)
('E-pedal', 'pedal')

>>> c = chord.Chord(['C3', 'G3'])
>>> harmony.chordSymbolFigureFromChord(c, True)
Expand Down Expand Up @@ -1134,7 +1134,7 @@ def chordSymbolFigureFromChord(inChord: chord.Chord, includeChordType=False):
still be identified correctly even if it is missing the 5th
5. the type with the most identical matches is used, and if no type matches,
"Chord Type Cannot Be Identified" is returned
6. the output format for the chord symbol figure is the chord's root (with 'b' instead of '-'),
6. the output format for the chord symbol figure is the chord's root,
the chord type's Abbreviation (saved in CHORD_TYPES dictionary),
a '/' if the chord is in an inversion, and the chord's bass

Expand All @@ -1145,7 +1145,7 @@ def chordSymbolFigureFromChord(inChord: chord.Chord, includeChordType=False):
Thus, by default the returned symbol is the first (element 0) in the CHORD_TYPES list.
For example (Eb minor eleventh chord, second inversion):

root + chord-type-str + '/' + bass = 'Ebmin11/Bb'
root + chord-type-str + '/' + bass = 'E-min11/B-'

Users who wish to change these defaults can simply change that
entry in the CHORD_TYPES dictionary.
Expand All @@ -1172,9 +1172,9 @@ def chordSymbolFigureFromChord(inChord: chord.Chord, includeChordType=False):

if len(inChord.pitches) == 1:
if includeChordType:
return (inChord.root().name.replace('-', 'b') + 'pedal', 'pedal')
return (inChord.root().name + 'pedal', 'pedal')
else:
return inChord.root().name.replace('-', 'b') + 'pedal'
return inChord.root().name + 'pedal'

d3 = inChord.semitonesFromChordStep(3) # 4 triad
d5 = inChord.semitonesFromChordStep(5) # 7 triad
Expand Down Expand Up @@ -1516,6 +1516,7 @@ class ChordSymbol(Harmony):

You can also create a Chord Symbol by writing out each degree,
and any alterations to that degree:

You must explicitly indicate EACH degree (a triad is NOT necessarily implied)

>>> [str(p) for p in harmony.ChordSymbol('C35b7b9#11b13').pitches]
Expand All @@ -1537,6 +1538,8 @@ class ChordSymbol(Harmony):
>>> [str(p) for p in harmony.ChordSymbol('Db35').pitches]
['D3', 'F3', 'A3']

(Note that this would be much better expressed just as 'Dm'.)

>>> [str(p) for p in harmony.ChordSymbol('D,35b7b9#11b13').pitches]
['D2', 'F#2', 'A2', 'E-3', 'G#3', 'B-3', 'C4']

Expand Down Expand Up @@ -1824,7 +1827,12 @@ def typeAlter(hD):
elif chordStepModification.modType == 'subtract':
typeSubtract(chordStepModification)
elif chordStepModification.modType == 'alter':
typeAlter(chordStepModification)
try:
typeAlter(chordStepModification)
except ChordStepModificationException:
# fix it in place
chordStepModification.modType = 'add'
typeAdd(chordStepModification)

return pitches

Expand Down
Loading