Re: MIDI Tracks and Sequences

On Wed, Sep 12, 2012 at 2:58 PM, James Ingram <j.ingram@netcologne.de>wrote:

> By the way, DOMHRT time is AudioContext.currentTime, right?
>

Heheh.  No.  :)  In fact, it's not even in the same units.

DOMHRT time is defined by the Navigation Timing spec (
http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html)
- its initial use was for high-precision performance timing, but it's
taking over as the general-purpose clock for high-precision Javascript
timing.

DOMHRT is in units of milliseconds, expressed as a floating point number;
the number represents the number of milliseconds since the navigation to
the page started.

AudioContext.currentTime is in units of seconds, expressed as a floating
point number; the number represents the number of seconds since the
AudioContext was created.  Most importantly, however, the clock may run at
a different rate, as it is the audio hardware system's clock, not the
computer's system clock; it may well have a different timing crystal.  In
short, you can't just convert by calculating the offset and
multiplying/dividing by 1000.

For this purpose, though, the AudioContext clock isn't relevant; you should
use the DOMHRT, and get the current time via

var currentTime = window.performance.now();

(actually, right now you have to use window.performance.webkitNow() in
Chrome.)

Just set timestamps on the MIDI messages based on offsets from a "start
sequence" time that you choose; you can write all the MIDI message
timestamps out at first if you like, but you probably want to just keep
writing ahead on a setInterval loop.  (I don't know if what I mean there
makes sense.)

Received on Wednesday, 12 September 2012 23:22:53 UTC