Skip to content

Instantly share code, notes, and snippets.

@andrewdunndev
Created August 4, 2012 13:27
Show Gist options
  • Select an option

  • Save andrewdunndev/3257764 to your computer and use it in GitHub Desktop.

Select an option

Save andrewdunndev/3257764 to your computer and use it in GitHub Desktop.
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