1

I want to create an LSTM model(using Keras) that will be trained in music, but I am having a difficult time in vectorizing the midi input. I tried using the 'Mido' library in python from where I was able to extract the data in the following format:

note_on channel=0 note=72 velocity=50 time=0
note_on channel=0 note=38 velocity=50 time=0.1171875
note_off channel=0 note=80 velocity=0 time=0.1171875
note_off channel=0 note=41 velocity=0 time=0

I am converting it into an array

[note_number, velocity, time]

where velocity denotes velocity and whether it's note_on\note_off. Now the problem is how do I feed the time here, I mean the time is in ticks(i guess). How do I convert these ticks to seconds, and as I will feed this array to a Sequential model how will I again convert the time to ticks from the output??

Ayush
  • 23
  • 2
  • Why is it float if it measures ticks? It would be discrete then. I think time is in seconds or milliseconds. – LtWorf Dec 22 '18 at 15:06
  • @LtWorf then how is it 0 in the first case, 0.117 in the second and third case and again 0 in the fourth case(The sample that I've posted above is in sequence). Pls explain I've no idea about Midi files – Ayush Dec 22 '18 at 18:38

1 Answers1

1

Times in MIDI files are delta times, the amount of time to wait after the previous event before performing this event. In your example, the two Note Off events happen simultaneously. You can easily convert from delta time to absolute time by keeping a running sum of the delta time values.

The time values you show can’t be ticks. Ticks have to be integer values. Without seeing your code, I don’t know what those values are, but I’m guessing Mido has converted to seconds.

Ticks are normally based on quarter notes, not time. The length in time of a quarter note (and thus ticks) depends on the current tempo, which is set by the Set Tempo meta event.

I think you will benefit from some time spent better understanding MIDI files. The Mido documentation on MIDI files is a good place to start. There are a number of explanations of MIDI files out there (such as this one.)

Hopefully this will get you on the right track. If you’re still having trouble, post a new question with a Minimal, Complete, and Verifiable example of code that illustrates your problem.

SSteve
  • 10,550
  • 5
  • 46
  • 72