<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 &lt;<a href="mailto:k.s.matheussen@gmail.com">k.s.matheussen@gmail.com</a>&gt; 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&#39;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 &quot;500ms later&quot;)<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 &lt;<a href="mailto:iainduncanlists@gmail.com" target="_blank">iainduncanlists@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi list, I&#39;m hoping someone can give me some brief guidance as I&#39;m sure this is a solved problem in S7 and CM but is beyond my lisp knowledge for how to do it correctly.<br>
&gt;<br>
&gt; Max/MSP has a scheduler that works with it&#39;s global clock. I want to enable something like the following:<br>
&gt;<br>
&gt; (delay :4n &#39;(my-funct a b c))<br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; (delay :4n (list (lambda (x) (...)) :foo :bar))<br>
&gt;<br>
&gt; Ideally, the way this is done would be compatible with future plans to allow a variant that we can cancel:<br>
&gt;<br>
&gt; (define future (delay :4n &#39;(my-fun a b c)))<br>
&gt; ... now I can cancel it by doing something to future if need be<br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; thanks<br>
&gt; iain<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Cmdist mailing list<br>
&gt; <a href="mailto:Cmdist@ccrma.stanford.edu" target="_blank">Cmdist@ccrma.stanford.edu</a><br>
&gt; <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>