Skip to content

Instantly share code, notes, and snippets.

@kistaaa
Last active November 12, 2022 17:56
Show Gist options
  • Save kistaaa/0c901048a363800a65b95a9bbfd0e4f0 to your computer and use it in GitHub Desktop.
Save kistaaa/0c901048a363800a65b95a9bbfd0e4f0 to your computer and use it in GitHub Desktop.
Convert midi events to a list for importing in Blender
from mido import MidiFile
tempo=0
noteons = []
notas = []
mid = MidiFile('C:/scripts-python/meow.mid')
for evt in mid:
if not evt.is_meta:
tempo += evt.time
if evt.type == 'note_on':
noteons.append(evt)
elif evt.type == 'note_off':
for nota in noteons:
if nota.note == evt.note:
com = tempo - evt.time
fim = tempo
dur = fim - com
notas.append([evt.note, com, fim, dur])
noteons.remove(nota)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment