Skip to content

mxm, IT's mad science

Sections
Personal tools
You are here: Home » Products » Open Source » Python Midi Package » right code
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 ! » Maybe this help you ... » How do I get the hex conversion code to work?

right code

Posted by Anonymous User at 2006-06-01 05:05 AM
def note2hex(note):
"""'note': is a string: 'f#' or a tuple or list: ('f#', -1),
the number indicates the octave (0 -> middle 'C')
If there is not number ('note' is a string), we assume
middle C"""
_note = ()
if type(note) == 'str':
_note = (note, 0)
n = _note[0].lower()
else:
_note = note
n = _note[0].lower()

if n == 'c':
nh = 0x3C
elif n == 'c#':
nh = 0x3D
elif n == 'db':
nh = 0x3D
elif n == 'd':
nh = 0x3E
elif n == 'd#':
nh = 0x3F
elif n == 'eb':
nh = 0x3F
elif n == 'e':
nh = 0x40
elif n == 'f':
nh = 0x41
elif n == 'f#':
nh = 0x42
elif n == 'gb':
nh = 0x42
elif n == 'g':
nh = 0x43
elif n == 'g#':
nh = 0x44
elif n == 'ab':
nh = 0x44
elif n == 'a':
nh = 0x45
elif n == 'a#':
nh = 0x46
elif n == 'bb':
nh = 0x46
elif n == 'b':
nh = 0x47

return nh + _note[1]*0x0C # 0x0C -> 12 Semitones