Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MIDI to notes
from mido import MidiFile
import mido
import sys
def ntof(n):
return 440*(2**((n-69)/12))
def main():
mid = MidiFile(sys.argv[1])
print("ticks per beat:",mid.ticks_per_beat)
#print("us per beat:",)
tempo = 120
for x in mid:
d = x.dict()
if type(x) is mido.midifiles.meta.MetaMessage:
if d.get("type") == "set_tempo":
print("tempo",d["tempo"],d)
tempo = d["tempo"]
else:
print("other",d)
else:
n = d.get("note")
if n is not None:
print(d["type"],ntof(n),mido.tick2second(d["time"],mid.ticks_per_beat,tempo))
else:
print(x)
if __name__ == '__main__':
print(ntof(127))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.