I have this two codes to extract information from a simple MIDI file, in the first the 'time' is so little: 0.3, 2.1, 0.9, etc. but in the second the 'time' is more big: 60, 420, 180, etc.
Can someone explain why there is this difference? What does it mean each 'time' in each code? I believe the second will be more sure to other processing, cause they are integers. Thanks in advance for your interesting comments.
import midofrom mido import MidiFileimport numpy as np# Cargar el archivo MIDImid = MidiFile('clusters.mid')mididict = []#crea una lista mididict para guardar los eventos midi del diccionario lista_notas = []#crea una lista output para guardar la salida final.# Recorre los mensajes midi hasta encontrar 'set_tempo'for msg in mid: if msg.type=='set_tempo': bpm=mido.tempo2bpm(msg.tempo)#guarda el tempo en bpm break #se sale si no lo encuentra# Recorre el midi buscando los eventos 'note_on', 'note_off' y 'time_signature'for i in mid: if i.type == 'note_on' or i.type == 'note_off' or i.type == 'time_signature': mididict.append(i.dict())#agrega los eventos encontrados a mididict # Recorre el midi para convertir los eventos 'note_on' en 'note_off' si 'velocity'=0for i in mididict: if i['type'] == 'note_on' and i['velocity'] == 0: i['type'] = 'note_off'print("Datos extraídos del MIDI:")# Imprime el tempo y el número de pulsos por tiempo (ticks por beat)print(f"tempo: {bpm}, ticks_per_beat: {mid.ticks_per_beat}")#clocks_per_click: {clocks_per_click},h=0 #inicia un contador de elementos print("Lista Mididict:")for i in mididict: print(f"Evento: {h}, {i}") #, número de evento y atributos del evento h=h+1 # incrementa el contadorDatos extraídos del MIDI:tempo: 100.0, ticks_per_beat: 120Lista Mididict:Evento: 0, {'type': 'time_signature', 'numerator': 4, 'denominator': 4, 'clocks_per_click': 24, 'notated_32nd_notes_per_beat': 8, 'time': 0}Evento: 1, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 60, 'velocity': 100}Evento: 2, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 60, 'velocity': 0}Evento: 3, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 62, 'velocity': 100}Evento: 4, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 62, 'velocity': 0}Evento: 5, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 60, 'velocity': 100}Evento: 6, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 60, 'velocity': 0}Evento: 7, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 64, 'velocity': 100}Evento: 8, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 64, 'velocity': 0}Evento: 9, {'type': 'note_on', 'time': 0.3, 'channel': 0, 'note': 60, 'velocity': 100}Evento: 10, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 60, 'velocity': 0} Evento: 11, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 64, 'velocity': 100} Evento: 12, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 64, 'velocity': 0} Evento: 13, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 67, 'velocity': 100} Evento: 14, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 67, 'velocity': 0} Evento: 15, {'type': 'note_on', 'time': 2.1, 'channel': 0, 'note': 70, 'velocity': 100} Evento: 16, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 70, 'velocity': 0} Evento: 17, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 72, 'velocity': 100} Evento: 18, {'type': 'note_off', 'time': 0.9, 'channel': 0, 'note': 72, 'velocity': 0} Evento: 19, {'type': 'note_on', 'time': 0.3, 'channel': 0, 'note': 74, 'velocity': 100} Evento: 20, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 74, 'velocity': 0} Evento: 21, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 76, 'velocity': 100}Evento: 22, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 76, 'velocity': 0}Evento: 23, {'type': 'note_on', 'time': 0, 'channel': 0, 'note': 72, 'velocity': 100}Evento: 24, {'type': 'note_off', 'time': 0.3, 'channel': 0, 'note': 72, 'velocity': 0}
from mido import MidiFilemid = MidiFile('Clusters.mid')print("Informacion de los tracks")for i, track in enumerate(mid.tracks): print('Track {}: {}'.format(i, track.name))i=0 print("\nInformacion de los eventos")for msg in track: print(i, msg) i=i+1Informacion de los eventos0 MetaMessage('midi_port', port=0, time=0)1 MetaMessage('track_name', name='', time=0)2 note_on channel=0 note=60 velocity=100 time=03 note_on channel=0 note=60 velocity=0 time=604 note_on channel=0 note=62 velocity=100 time=05 note_on channel=0 note=62 velocity=0 time=606 note_on channel=0 note=60 velocity=100 time=07 note_on channel=0 note=60 velocity=0 time=608 note_on channel=0 note=64 velocity=100 time=09 note_on channel=0 note=64 velocity=0 time=6010 note_on channel=0 note=60 velocity=100 time=6011 note_on channel=0 note=60 velocity=0 time=6012 note_on channel=0 note=64 velocity=100 time=013 note_on channel=0 note=64 velocity=0 time=6014 note_on channel=0 note=67 velocity=100 time=015 note_on channel=0 note=67 velocity=0 time=6016 note_on channel=0 note=70 velocity=100 time=42017 note_on channel=0 note=70 velocity=0 time=6018 note_on channel=0 note=72 velocity=100 time=019 note_on channel=0 note=72 velocity=0 time=18020 note_on channel=0 note=74 velocity=100 time=6021 note_on channel=0 note=74 velocity=0 time=6022 note_on channel=0 note=76 velocity=100 time=023 note_on channel=0 note=76 velocity=0 time=6024 note_on channel=0 note=72 velocity=100 time=025 note_on channel=0 note=72 velocity=0 time=6026 MetaMessage('end_of_track', time=0)[Program finished]