Created
August 4, 2012 13:27
-
-
Save andrewdunndev/3257764 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def name_to_number(note_string): | |
| notes = "C . D . E F . G . A . B".split() | |
| name = note_string[0:1].upper() | |
| number = notes.index(name) | |
| acc = accidentals(note_string) | |
| return mod12(number + acc) | |
| def accidentals(note_string): | |
| print note_string | |
| acc = len(note_string[1:]) | |
| if "#" in note_string: | |
| return acc | |
| elif "b" in note_string: | |
| return -acc | |
| else: | |
| return 0 | |
| def accidentals_list(note_string): | |
| accidentals = list(note_string) | |
| acc = 0 | |
| for element in accidentals: | |
| if '#' in element: | |
| acc = acc + 1 | |
| if 'b' in element: | |
| acc = acc - 1 | |
| return acc | |
| def accidentals_collection(note_string): | |
| import collections | |
| collection_counter = collections.Counter(note_name) | |
| sharps = collection_counter['#'] | |
| flats = collection_counter['b'] | |
| return sharps - flats |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment