Skip to content

mxm, IT's mad science

Sections
Personal tools
You are here: Home » Products » Open Source » Python Midi Package » Another way to lookuo hex values for notes
Downloads
You can download mxm products here.

Due to it's technical and international nature, this section is in english.

Max M Has a blog too.

og er glad for mad

 

Comment

Above in this comment thread: Python Midi Package » Notes !

Another way to lookuo hex values for notes

Posted by Anonymous User at 2008-06-11 10:06 PM
def get(note, transpose=0):
"""
note is a string value (e.g. c#)
transpose is a signed integer that indicates
number of octaves to transpose up or down
"""
transpose = transpose * 0x0C
note = note.lower()
sharpMap = {
'db': 'c#',
'eb': 'd#',
'gb': 'f#',
'ab': 'g#',
'bb': 'g#'
}
noteMap = {
'c': 0x3C,
'c#': 0x3D,
'd': 0x3E,
'd#': 0x3F,
'e': 0x40,
'f': 0x41,
'f#': 0x42,
'g': 0x43,
'g#': 0x44,
'a': 0x45,
'a#': 0x46,
'b': 0x47
}

if note in noteMap.keys():
return noteMap[note] + transpose
elif note in sharpMap.keys():
return noteMap[sharpMap[note]] + transpose
else:
raise LookupError, "The note %s does not exist" % note