<div dir="ltr">Thanks Kjetil, I will take a look at the Radium sources.<div><br></div><div>Much appreciated,</div><div>iain</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 8, 2020 at 10:32 AM Kjetil Matheussen <<a href="mailto:k.s.matheussen@gmail.com">k.s.matheussen@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">For realtime or semi-realtime usage, you normally store the callbacks<br>
in a binary heap. (<a href="https://en.wikipedia.org/wiki/Binary_heap" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/Binary_heap</a>) A binary<br>
heap implemented in an array is both very efficient and quite simple:<br>
<a href="https://github.com/kmatheussen/radium/blob/master/common/PriorityQueue.hpp" rel="noreferrer" target="_blank">https://github.com/kmatheussen/radium/blob/master/common/PriorityQueue.hpp</a><br>
<br>
You can look at Radium's scheduler, which uses a binary heap, here:<br>
<a href="https://github.com/kmatheussen/radium/blob/master/api/api_various.cpp#L4175" rel="noreferrer" target="_blank">https://github.com/kmatheussen/radium/blob/master/api/api_various.cpp#L4175</a><br>
<br>
Example:<br>
<br>
(define (callback)<br>
(display "500ms later")<br>
500) ;; I.e. call me again in 500ms. Return #f instead to stop<br>
being called again.<br>
<br>
;; start it<br>
(ra:schedule 500 callback)<br>
<br>
;; stop it<br>
(ra:remove-schedule callback)<br>
<br>
On Mon, Jun 8, 2020 at 6:06 PM Iain Duncan <<a href="mailto:iainduncanlists@gmail.com" target="_blank">iainduncanlists@gmail.com</a>> wrote:<br>
><br>
> Hi list, I'm hoping someone can give me some brief guidance as I'm sure this is a solved problem in S7 and CM but is beyond my lisp knowledge for how to do it correctly.<br>
><br>
> Max/MSP has a scheduler that works with it's global clock. I want to enable something like the following:<br>
><br>
> (delay :4n '(my-funct a b c))<br>
><br>
> So the delaying side will be implemented in C, and that side will handle converting :4n to the right time according to the max clock and then call *something* in S7 from C at the right time. My question is what the right way to store and then call the delayed function is, given that it might also have anonymous elements<br>
><br>
> (delay :4n (list (lambda (x) (...)) :foo :bar))<br>
><br>
> Ideally, the way this is done would be compatible with future plans to allow a variant that we can cancel:<br>
><br>
> (define future (delay :4n '(my-fun a b c)))<br>
> ... now I can cancel it by doing something to future if need be<br>
><br>
> Do I need to do something like have my arg 3 to delay be converted to a function and environment captured and stored with gensym? Is there a known pattern for this that I can look at in the common music sources or other lisp literature? Any help preventing slow wheel re-invention much appreciated!<br>
><br>
> thanks<br>
> iain<br>
><br>
><br>
> _______________________________________________<br>
> Cmdist mailing list<br>
> <a href="mailto:Cmdist@ccrma.stanford.edu" target="_blank">Cmdist@ccrma.stanford.edu</a><br>
> <a href="https://cm-mail.stanford.edu/mailman/listinfo/cmdist" rel="noreferrer" target="_blank">https://cm-mail.stanford.edu/mailman/listinfo/cmdist</a><br>
</blockquote></div>