Schedule [js] Task in absolute ticks?
I see that JS Tasks can be scheduled in millisecond delays, but can they be scheduled to fire when the transport reaches an absolute time in ticks?
Flipping through the SDK, I figure I can probably mash up the delay2
and simplejs
examples to do something like what I'd like—although I'm not completely certain how to call a JS callback from C.
This is for a Max For Live project. If there's any other way to have a JS callback fire when the Live transport reaches a specific time, that would work, too.
Quick follow-up question: If there's a way to schedule events to fire at an absolute tick value in Java with [mxj], that would also be of interest to me.
For what it's worth, I already have a system for this purpose working using [timepoint], but I'd love to push this scheduling functionality into procedural code—either Java or JavaScript—if possible.
You'll be lucky to get millisecond timing accuracy in Javascript because it only runs in the UI thread; Java is a better bet.
Thanks, Nick. I'm actually getting really good results from [js] right now—turnaround times in microseconds. Will persist and post here if I see any major performance problems.
FWIW, I also tried making a system to schedule arbitrary messages at specific times in the future with patcher scripting, by creating instances of a patcher that used [timepoint] and [pv], then removed itself with [thispatcher]. This system is way too slow for my purposes, though—several milliseconds in either [js] or [mxj jruby], mainly caused by presence of [thispatcher]. I'll revert to my original system, which involves a single event loop feeding upcoming events through a single [timepoint] + [pv] combo.