Created
November 27, 2013 01:31
-
-
Save jsundram/7669296 to your computer and use it in GitHub Desktop.
Calculate the range between two musical notes
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
def location(pitch): | |
shift = {"C":0, "D":2, "E":4, "F":5, "G":7, "A":9, "B":11, "#":1, "-":-1} | |
location = 12 * int(pitch[-1]) | |
for c in pitch[:-1]: | |
location += shift[c] | |
return location | |
def count(low, hi): | |
return location(high) - location(low) | |
def main(): | |
# would be good to have some tests here | |
print "location of C4 is %d" % location('C4') | |
print "interval (C4, C5) is %d" % count('C4', 'C5') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment