Permalink
Browse files

fixed problem in normalOrder - thx luiselroquero

  • Loading branch information...
mscuthbert committed Sep 18, 2017
1 parent 5585ef9 commit 2f0645fa390b2b5e5f3cef23342afe066790bce1
Showing with 26 additions and 7 deletions.
  1. +21 −2 music21/chord/__init__.py
  2. +5 −5 music21/chord/tables.py
View
@@ -3677,6 +3677,9 @@ def chordTablesAddress(self):
>>> c.chordTablesAddress
ChordTableAddress(cardinality=3, forteClass=12, inversion=0, pcOriginal=2)
>>> c = chord.Chord('G#2 A2 D3 G3')
>>> c.chordTablesAddress
ChordTableAddress(cardinality=4, forteClass=6, inversion=0, pcOriginal=2)
'''
if self._chordTablesAddressNeedsUpdating:
self._chordTablesAddress = chordTables.seekChordTablesAddress(self)
@@ -3984,11 +3987,27 @@ def normalOrder(self):
>>> c3.formatVectorString(c3.normalOrder)
'<A25>'
OMIT_FROM_DOCS
These were giving problems before:
>>> chord.Chord('G#2 A2 D3 G3').normalOrder
[7, 8, 9, 2]
>>> chord.Chord('G3 D4 A-4 A4 C5 E5').normalOrder
[7, 8, 9, 0, 2, 4]
'''
cta = self.chordTablesAddress
pcOriginal = cta.pcOriginal
transposedNormalForm = chordTables.addressToTransposedNormalForm(cta)
return [(pc + pcOriginal) % 12 for pc in transposedNormalForm]
orderedPCs = self.orderedPitchClasses
mustBePresentPCs = set(orderedPCs)
for transposeAmount in orderedPCs:
possibleNormalOrder = [(pc + transposeAmount) % 12 for pc in transposedNormalForm]
if set(possibleNormalOrder) == mustBePresentPCs:
return possibleNormalOrder
raise ChordException('Could not find a normalOrder for chord: '
+ str(self.orderedPitchClassesString))
@property
def normalOrderString(self):
View
@@ -2618,15 +2618,15 @@ def _validateAddress(address):
def addressToTransposedNormalForm(address):
'''Given a TN address, return the normal form transposed to start on 0.
>>> chord.tables.addressToTransposedNormalForm((3,1,0))
>>> chord.tables.addressToTransposedNormalForm((3, 1, 0))
(0, 1, 2)
>>> chord.tables.addressToTransposedNormalForm((3,11,-1))
>>> chord.tables.addressToTransposedNormalForm((3, 11, -1))
(0, 4, 7)
>>> chord.tables.addressToTransposedNormalForm((3,11,1))
>>> chord.tables.addressToTransposedNormalForm((3, 11, 1))
(0, 3, 7)
>>> chord.tables.addressToTransposedNormalForm((3,11))
>>> chord.tables.addressToTransposedNormalForm((3, 11))
(0, 3, 7)
>>> chord.tables.addressToTransposedNormalForm((3,11,None))
>>> chord.tables.addressToTransposedNormalForm((3, 11, None))
(0, 3, 7)
'''
card, index, inversion = _validateAddress(address)

0 comments on commit 2f0645f

Please sign in to comment.