1

i am playing with python mido library an I am trying to get notes data but I don't understand it.

my code:

    # open midi file
    midi = str(MidiFile('./midi/piano/WA_Mozart_Marche_Turque_Turkish_March_fingered.mid', clip=True))
    
    # copy content of midi file to text file for easier work
    midiTextFile = open("midi.txt", "w")
    midiTextFile.write(midi)

Some example part of output

 Message('note_on', channel=0, note=80, velocity=96, time=1),
    Message('note_on', channel=0, note=80, velocity=0, time=119),
    Message('note_on', channel=0, note=64, velocity=96, time=1),
    Message('note_on', channel=0, note=64, velocity=0, time=119),
    Message('note_on', channel=0, note=76, velocity=96, time=1),
    Message('note_on', channel=0, note=76, velocity=0, time=119),
    MetaMessage('time_signature', numerator=1, denominator=4, clocks_per_click=24, notated_32nd_notes_per_beat=8, time=1),
    Message('note_on', channel=0, note=69, velocity=96, time=0),
    Message('note_on', channel=0, note=81, velocity=96, time=0),
    MetaMessage('set_tempo', tempo=500000, time=479),
    Message('note_on', channel=0, note=69, velocity=0, time=0),
    Message('note_on', channel=0, note=81, velocity=0, time=0),
    MetaMessage('key_signature', key='A', time=1),
    Message('note_on', channel=0, note=69, velocity=96, time=0),
    Message('note_on', channel=0, note=69, velocity=0, time=119),
    Message('note_on', channel=0, note=81, velocity=96, time=1),
    Message('note_on', channel=0, note=81, velocity=0, time=119),
    Message('note_on', channel=0, note=71, velocity=96, time=1),
    Message('note_on', channel=0, note=71, velocity=0, time=119),
    Message('note_on', channel=0, note=83, velocity=96, time=1),
    Message('note_on', channel=0, note=83, velocity=0, time=119),
    MetaMessage('time_signature', numerator=2, denominator=4, clocks_per_click=24, notated_32nd_notes_per_beat=8, time=1),
    Message('note_on', channel=0, note=73, velocity=96, time=0),
    Message('note_on', channel=0, note=73, velocity=0, time=119),
    Message('note_on', channel=0, note=85, velocity=96, time=1),
    Message('note_on', channel=0, note=85, velocity=0, time=119),
    Message('note_on', channel=0, note=69, velocity=96, time=241),
    Message('note_on', channel=0, note=69, velocity=0, time=119),
    Message('note_on', channel=0, note=81, velocity=96, time=1),
    Message('note_on', channel=0, note=81, velocity=0, time=119),
    Message('note_on', channel=0, note=71, velocity=96, time=1),

Now I am not sure about few things. This part means that note 64 starts on 1milisecond and ends on 119 milisecond? And if yes is there any better way how to get start and end of note than this?

Message('note_on', channel=0, note=64, velocity=96, time=1),
Message('note_on', channel=0, note=64, velocity=0, time=119),

And other thing i don't understand is that song in midi editor have 3 minutes while in this midi text file there is no time value bigger then time=500

Thanks for any help.

Michaelo
  • 579
  • 1
  • 5
  • 13
  • 3
    Maybe a look at the documentation would help. "Timing in MIDI files is centered around ticks and beats. A beat is the same as a quarter note. Beats are divided into ticks, the smallest unit of time in MIDI. Each message in a MIDI file has a delta time, which tells how many ticks have passed since the last message. The length of a tick is defined in ticks per beat. This value is stored as `ticks_per_beat` in MidiFile objects and remains fixed throughout the song." https://mido.readthedocs.io/en/latest/midi_files.html#iterating-over-messages – BoarGules Sep 11 '21 at 07:16
  • @BoarGules yeah now i understand that there is delta time and absolute time thank you. Question solved. – Michaelo Sep 11 '21 at 07:19

0 Answers0