sebpiq / WAAClock

A comprehensive event scheduling tool for Web Audio API.
MIT License
244 stars 32 forks source link

how about ability to "delay" an event by t seconds? #5

Closed wolfbiter closed 10 years ago

wolfbiter commented 10 years ago

Hi,

First off, thanks so much for providing this library! I'm using it as a scheduler in a music playlisting app...

Something I find myself wanting is the ability to change an event's execution time after the event has already been created (rather than canceling the event, recalculating when that execution time would be, and recreating the event). I have in mind something like this:

// prints 'wow!' in 13 seconds
var event = clock.setTimeout(function() { console.log('wow!') }, 13)
// delays print by 5 seconds, such that print happens in 18 seconds
event.delay(5);
// 'un'delays print by 18 seconds, such that print happens now
event.delay(-18);

What do you think?

sebpiq commented 10 years ago

First off, thanks so much for providing this library! I'm using it as a scheduler in a music playlisting app...

Great!!! I'd love to see it in action :)

I think what you say makes sense. This is already what I am doing in the timeStretch function, i.e. rescheduling an event at a different time. I am just wondering, would it make more sense to expose this in the Event API :

event.reschedule(absoluteTime)

Or do you have a good use-case for a version using the relative time (as you suggested) :

event.delay(relativeTime)
wolfbiter commented 10 years ago

Well so I have a Player class which have an event list, Player.events. They share a communal position, and so I wanted something like

Player.on('seek', function (distSeeked) {
  Player.events.forEach(function (event) {
    event.delay(distSeeked);
  }
}

However, I think your idea is better in that it is more general. Don't the events even store their time in them, such that one could simply invoke the below to serve as event.delay?

event.reschedule(event.time + relativeTime);
sebpiq commented 10 years ago

What I did is that I just exposed the schedule function of the event (which was "private" before), and documented that you can use the .time attribute of the event to get its absolute time : 7e43f1732d2f6fc41aa086409bc8b2b27516e684

Is that good?

wolfbiter commented 10 years ago

Works great for me! Thanks for providing this!