Browse Source

add another pitch translator: midinames to midipitches

master
Nils 2 years ago
parent
commit
537d55c2cb
  1. 27
      template/engine/pitch.py

27
template/engine/pitch.py

@ -1094,6 +1094,30 @@ for _midipitch in range(128):
_octave, _pitch = divmod(_midipitch, 12)
midi_notenames_german.append("{}{}".format("C Des D Es E F Fis G As A B H".split()[_pitch] ,_octave-1))
#midi and sfz note names are normal midi notes again, but this time we need a dict because both Eb and D# are in there. c4 is middle.
_alt = {
"db" : "c#",
"eb" : "d#",
"f#" : "gb",
"ab" : "g#",
"bb" : "a#",
}
midiName2midiPitch = {}
for _midipitch in range(128): #0-127 incl.
_octave, _pitch = divmod(_midipitch, 12)
_octave -= 1
notename = "c db d eb e f f# g ab a bb b".split()[_pitch]
sfz_name1 = "{}{}".format(notename ,_octave)
midiName2midiPitch[sfz_name1] = _midipitch
if notename in ("db", "eb", "f#", "ab", "bb"): #Add the other variant
sfz_name2 = "{}{}".format(_alt[notename] ,_octave)
midiName2midiPitch[sfz_name2] = _midipitch
assert midiName2midiPitch["db4"] == 61, midiName2midiPitch["db4"]
assert midiName2midiPitch["db4"] == midiName2midiPitch["c#4"], midiName2midiPitch["c#4"]
"""midi_notenames_lilypond = []
for _midipitch in range(128):
_octave, _pitch = divmod(_midipitch, 12)
@ -1176,6 +1200,3 @@ simpleNoteNames["German"] = midi_notenames_german
simpleNoteNames["English"] = midi_notenames_english
simpleNoteNames["Lilypond"] = midi_notenames_lilypond
simpleNoteNames["Drums GM"] = midi_notenames_gm_drums

Loading…
Cancel
Save