I have researched the subject for some time now and still haven't figure it out. I use midas3 library (Midi-actionscript3) to import midi to flash. I get each note-item on a timeline. I get the divisions value (192) and all of the "GET-TEMPO" elements are equal to 81.
I tried a lot of combinations to get the actual time of the midi but still no good (timeline*192/60 for example).
The reason I know it is not synchronized to the actual time is that when I visualize the notes as simple rectangles in flash - I check if they appear exactly to what the mp3 file plays (I have converted the midi file to this mp3 using simple conversion program)
I have read a lot about how all is calculated but still haven't figure out the number I need to use to get it right (timeline * MysteriusConstant = ReaTIME, what is the value of MysteriusConstant? is it really constant? and if not how do I calculate how it is changed?)
thanks Alon
If I understand your question correctly, you basically want to convert the ticks for each MIDI note into a millisecond value so you can display the notes visually along a timeline.
So first, you need to use the division and the tempo to determine the value of an individual tick. That conversion basically looks like:
[ 1 min 60 sec 1 beat Z clocks ]
| ------- * ------ * -------- * -------- | = seconds
[ X beats 1 min Y clocks 1 ]
So, in the above conversion, X
is the tempo, Y
is the division, and Z
is the number of clocks from the incoming event. You can see how all of the units cancel out, giving you a value in seconds. The condensed version of that conversion is therefore:
(60 * clocks) / (tempo * division) = seconds
Keep in mind that the value given here in seconds
is the number of seconds since the previous MIDI event, not from the sequence start. You will need to keep a running total of this value to construct a coherent sequence.
来源:https://stackoverflow.com/questions/5288593/how-to-convert-midi-timeline-into-the-actual-timeline-that-should-be-played