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
how do i know wich note is note=0x41 ....
which note represents ,,,, there is any manual ou something so see all notes in Hex
thnx
I've defined some helper functions for managing midi notes and hex numbers.
Try this:
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) == types.StringType:
_note = (note, 0)
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
Replies to this comment
"""
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
code:
# Some notes
c0 = 52
cis0= 53
d0 = 54
dis0= 55
e0 = 56
f0 = 57
fis0= 58
g0 = 59
gis0= 60
a0 = 61
ais0= 62
h0 = 63
c1 = 64
cis1= 65
d1 = 66
dis1= 67
e1 = 68
f1 = 69
fis1= 70
g1 = 71
gis1= 72
a1 = 73
ais1= 74
h1 = 75
c2 = 76
cis2= 77
d2 = 78
dis2= 79
e2 = 80
f2 = 81
fis2= 82
g2 = 83
gis2= 84
a2 = 85
ais2= 86
h2 = 87
c3 = 88
cis3= 89
d3 = 90
dis3= 91
e3 = 92
f3 = 93
fis3= 94
g3 = 95
gis3= 96
a3 = 97
ais3= 98
h3 = 99
c4 = 100
cis4= 101
d4 = 102
dis4= 103
e4 = 104
f4 = 105
fis4= 106
g4 = 107
gis4= 108
a4 = 109
ais4= 110
h4 = 111
{EOF}
And using this will look just like this:
midi.note_on(note=c1)
midi.note_on(note=e1)
midi.note_on(note=g1)
cheers