W3C home > Mailing lists > Public > public-audio@w3.org > July to September 2012

Re: MIDI Tracks and Sequences

From: Chris Wilson <cwilso@google.com>
Date: Fri, 14 Sep 2012 09:22:09 -0700
Message-ID: <CAJK2wqWJx9s7N+4gfWBUhJESrAVLmUCFowog6Snr8PdBj4L_7w@mail.gmail.com>
To: James Ingram <j.ingram@netcologne.de>
Cc: public-audio@w3.org, Jussi Kalliokoski <jussi.kalliokoski@gmail.com>
On Fri, Sep 14, 2012 at 2:07 AM, James Ingram <j.ingram@netcologne.de>wrote:

> The problem is that the sendMIDISequence() function is recursive. And it
> has to be that way because of the way setInterval() works.


It really, really doesn't need to be recursive.  That's what's giving you
scope trouble, I believe.  This is also causing you to have to pervert how
you use setInterval - if you're going to have to cancel the interval every
tick, you should just use setTimeout.

Additionally, you are only sending one message per tick; that's not really
the point.  You should be sending any messages that are between this
interval call and the next, to get them queued up;  and really, you need
some lookahead past that, in case the timers are skewed a bit (aka the
setInterval callback is late).

Your loop should really loop more like this: https://gist.github.com/3722988
.

-Chris

The stack is growing during the performance, and the likelihood of garbage
> collections (or even a crash) is increasing all the time. What happens if I
> want to play a 5 hour piece at a conservative 20 recursions per second?
>
> My instinct says that the player should really be executing on a
> background worker thread, and using an ordinary sleep() function instead of
> setInterval().
>

setInterval or setTimeout will give you the effect that you need from
sleep().
Received on Friday, 14 September 2012 16:22:41 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 14 September 2012 16:22:42 GMT