Skip to content

Instantly share code, notes, and snippets.

@eamonnbell
Last active December 17, 2015 18:59
Show Gist options
  • Save eamonnbell/5657410 to your computer and use it in GitHub Desktop.
Save eamonnbell/5657410 to your computer and use it in GitHub Desktop.
Tries to account for chord changes in a Bach Chorale by brute-forcing the 24 unique LPR operations
import music21
# From Hook/Andrew Chung
LRPgroup = ['', 'P', 'LPRP', 'LPR', 'LRL', 'PRPL', 'LRLR', 'RLR', 'LPRPR', 'LRPR', 'PR', 'PRP',
'R', 'RP', 'LP', 'L', 'LPL', 'PL', 'RL', 'PLR', 'LPR', 'LR', 'PRPR', 'RPR']
LRPCombinations = music21.analysis.neoRiemannian.LRP_combinations
def getCanonicalTransform(source, target):
for operation in LRPgroup:
if sorted(target.pitchClasses) == sorted(LRPCombinations(source, operation).pitchClasses):
return operation
def doAnalysisToChordList(chords):
analysis = []
for index in range(len(chords)-1):
print (("".join(chords[index].pitchNames), "".join(chords[index+1].pitchNames), getCanonicalTransform(chords[index], chords[index+1])))
jsb = music21.corpus.parse('bwv7.7')
reduction = jsb.chordify()
chords = []
for chord in reduction.flat.getElementsByClass('Chord'):
chords.append(chord.closedPosition(forceOctave=4, inPlace=False))
doAnalysisToChordList(chords)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment