Re: MIDI Tracks and Sequences

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 UTC