Created
April 30, 2012 05:25
-
-
Save jchia/2555741 to your computer and use it in GitHub Desktop.
Music scale manipulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Transpose the deltas so that the first one is 0 and everything is in [0, 12). | |
def normalize(deltas): | |
root = deltas[0] % 12 | |
return [(delta + 12 - root) % 12 for delta in deltas] | |
def transpose(deltas, base): | |
return [(delta + base) % 12 for delta in deltas] | |
# Gives the list of notes for the deltas using base as the base note | |
# (0=C, 1=Db, 2=D, ...) | |
# Two variants are available, one where only flats (and naturals) are used and | |
# another where only sharps are used. | |
def notes(deltas, base, sharp): | |
table = deltaToNoteSharp if sharp else deltaToNoteFlat | |
return [table[(delta + base) % 12] for delta in deltas] | |
deltaToNoteFlat = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'] | |
deltaToNoteSharp = ['B#', 'C#','D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'] | |
# major pentatonic | |
keysMaj = normalize([1, 3, 5, 8, 10]) | |
# minor pentatonic | |
keysMin = normalize([1, 4, 6, 8, 11]) | |
print keysMaj | |
# C maj pentatonic | |
print notes(keysMaj, 0, False) | |
# A min pentatonic | |
print notes(keysMin, 9, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment