Re: [Web MIDI API] send() timestamp

On Saturday, 15 December 2012 at 15:04, Marcos Caceres wrote:

> Ok, I think I'm getting it now :) I'll try to set up a little experiment and see if I can replicate the above (though it won't really work in the reference implementation as we are still relying on setTimeout for scheduling... which only has a precision of 4ms)

Ok, got it all going :)   
http://marcoscaceres.github.com/WebMIDIAPIShim/

So, to replay a recording made locally, it's basically:
//pre-recorded data
var record=[{data:[...], stamp: 123113}, … ];  

//time playback relative to "now"
var start = window.performance.now() - record[0].stamp;  
record.forEach(function(packet){
output.send(packet.data, packet.stamp + start);
})



I also polyfilled performance.now() for various browsers. See bottom of:
http://marcoscaceres.github.com/WebMIDIAPIShim/WebMIDIAPI.js

Hopefully that all looks about right now (bar the changes I made to API to make it easier to use… which I hope you will consider).  

--  
Marcos Caceres
http://datadriven.com.au

Received on Sunday, 16 December 2012 09:06:00 UTC