Created
February 7, 2019 14:50
-
-
Save eruffaldi/b30650a7be5092fada384b3981af1aab to your computer and use it in GitHub Desktop.
MIDI to notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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