Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: cgdolan/21M359Fall2012
base: 996d7ae773
...
head fork: cgdolan/21M359Fall2012
compare: a5d6e9c54b
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 18 additions and 20 deletions.
  1. +18 −20 data/chord.py
View
38 data/chord.py
@@ -46,29 +46,27 @@ def interval_vector(self):
def zero_shifted(self):
sorted_pitch_classes = []
- sorted_pitch_classes = sorted(pitch_classes)
- if sorted_pitch_classes[0] == 0:
- return Chord(sorted_pitch_classes)
- else:
- shifting_factor = sorted_pitch_classes[0]
- for i in sorted_pitch_classes:
- sorted_pitch_classes[i] = sorted_pitch_classes[i]-shifting_factor
- return Chord(sorted_pitch_classes)
+ sorted_pitch_classes = sorted(self.pitch_classes)
+ new_pitch_classes = [sp - min(sorted_pitch_classes) for sp in sorted_pitch_classes]
+ return Chord(new_pitch_classes)
- def base_at_zero(self):
- #takes a chord and puts it in normal form
- output = []
- output.append(sorted(self.transpose(-min(chord))))
- return Chord(output)
def leftward_pack(self):
- output = []
- #generate the other possible forms of this chord, return
- #lexicographically smallest one
- otherForms = [self.invert(float(x)/2) for x in range(0,6)]
- otherForms.sort()
- output.append(otherForms[0])
- return Chord(output)
+ pc = self.pitch_classes
+ minSpan = None
+ for i in range(len(pc)):
+ newSpan = (pc[(len(pc)-1+i)%len(pc)] - pc[i%len(pc)]) % 12
+ if minSpan == None or newSpan < minSpan:
+ minSpan = newSpan
+ leftRotations = i
+ # this ought to be the correct rotation, now we only need
+ # to test each inversion
+ rot_classes = [pc[(i + leftRotations)%len(pc)] for i in range(len(pc))]
+ # we need to base this at zero still - can't use zero_shifted function, because
+ # that won't retain rotation information due to sorting
+ zeroed_rot = [(rc - rot_classes[0])%12 for rc in rot_classes]
+ inversions = [Chord(zeroed_rot).invert(x).pitch_classes for x in range(12)]
+ return sorted(inversions)[0]
def __repr__(self):

No commit comments for this range

Something went wrong with that request. Please try again.