Re: MIDI Delta-Time to milliseconds?

[email protected] ("James Bennett") Tue, 19 Oct 2004 14:46:05 -0700
Newsgroups perl.midi
Message-ID <[email protected]>
The following code works for my applications and has been quite robust over
a variety of MIDI scores.  If you are computing elapsed time don't forget to
update the variables for each 'time_signature' and 'set_tempo' event as you
go.

Compute the elapsed_seconds between two events times by dividing by the
number of $ticks_per_second, which is computed as

    $ticks_per_second =
($ticks_per_beat*1000000)/($prevailing_tempo/$beats_per_quarter_note);

(Note that msecs is obtained by scaling by 1000 rather than 1000000).

where
  $ticks = opus->ticks;

and
  $ts_r is a 'time_signature' event
  $beats_per_quarter_note = (2**(@$ts_r->[3] - 2));
  $ticks_per_beat = $ticks/$beats_per_quarter_note;

and
  $tempo_r is a 'set_tempo' event
  $prevailing_tempo = @$tempo_r->[2]; # microsecs/beat

jim