<div style="color:black;font: 10pt arial;">In my WIP pdlua scripting library https://github.com/sebshader/lscore
<div>I use 1 clock from pdlua for timing but then use my own heap/priority-queue-based scheduler as a wrapper for it.</div>

<div>So if I need a new delay/clock I add it to my own scheduling queue, and then the priority queue pops the (next time - current time) for the <span style="font-size: 10pt;">underlying t_clock that pdlua uses every time a delay occurs.</span></div>

<div>(and then the clocks are used for delays within coroutine yields so you can write music)</div>

<div>In my case I also need a lot more manipulations of the scheduling queues though (my next project is to have 1 scheduling queue per</div>

<div>accelerando/ritardando group so a tree of descendants of an ancestor coroutine that sprouted them can accelerando/ritardando together)</div>

<div><br>
</div>

<div>-Seb<br>
<br>

<div style="font-family:helvetica,arial;font-size:10pt;color:black"><font size="2">-----Original Message-----<br>

<div dir="ltr"><br>
</div>

<div dir="ltr">Date: Sun, 6 Jun 2021 18:52:17 -0700<br>
</div>

<div dir="ltr">From: Miller Puckette <<a ymailto="mailto:msp@ucsd.edu" href="mailto:msp@ucsd.edu">msp@ucsd.edu</a>><br>
</div>

<div dir="ltr">To: Iain Duncan <<a ymailto="mailto:iainduncanlists@gmail.com" href="mailto:iainduncanlists@gmail.com">iainduncanlists@gmail.com</a>><br>
</div>

<div dir="ltr">Cc: pd-dev <<a ymailto="mailto:pd-dev@lists.iem.at" href="mailto:pd-dev@lists.iem.at">pd-dev@lists.iem.at</a>><br>
</div>

<div dir="ltr">Subject: Re: [PD-dev] Creating delayed functions in Pd external?<br>
</div>

<div dir="ltr">Message-ID: <<a ymailto="mailto:20210607015217.4fb2ym5rl27d7olu@ucsd.edu" href="mailto:20210607015217.4fb2ym5rl27d7olu@ucsd.edu">20210607015217.4fb2ym5rl27d7olu@ucsd.edu</a>><br>
</div>

<div dir="ltr">Content-Type: text/plain; charset=us-ascii<br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">Well, Pd's own scheduler for clocks keeps them in a linked list and chases<br>
</div>

<div dir="ltr">down it to set and unset them.  So if you did anything smart for the<br>
</div>

<div dir="ltr">scheme callbacks Pd would see to it that it's still linear time in the<br>
</div>

<div dir="ltr">number of active callbacks.<br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">cheers<br>
</div>

<div dir="ltr">M<br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">On Sun, Jun 06, 2021 at 06:22:41PM -0700, Iain Duncan wrote:<br>
</div>

<div dir="ltr">> Thanks Miller. That brings up one more question.. ;-)<br>
</div>

<div dir="ltr">> <br>
</div>

<div dir="ltr">> In Scheme for Max, the way I do it is I keep a hash-table in C going<br>
</div>

<div dir="ltr">> with keys that are created on Scheme delay calls, so that one can cancel<br>
</div>

<div dir="ltr">> clocks by fetching them from the hashtable. In Max, there's a<br>
</div>

<div dir="ltr">> cross-platform hash-table implementation that I'm using. Is there something<br>
</div>

<div dir="ltr">> similar for Pd, or if not, is there an approach you would recommend for<br>
</div>

<div dir="ltr">> keeping a key-value store in C for the clocks by a symbolic key? I guess a<br>
</div>

<div dir="ltr">> good question might be if this is even necessary, given there can't be<br>
</div>

<div dir="ltr">> *that* many clocks scheduled for the future. And association list type<br>
</div>

<div dir="ltr">> thing might do just as well.<br>
</div>

<div dir="ltr">> <br>
</div>

<div dir="ltr">> thanks for the help, it's going well, now that I can finally work on it!<br>
</div>

<div dir="ltr">> ought to have a first alpha folks can play with in the next couple of weeks.<br>
</div>

<div dir="ltr">> iain<br>
</div>

<div dir="ltr">> <br>
</div>

<div dir="ltr">> <br>
</div>

<div dir="ltr">> <br>
</div>

<div dir="ltr">> On Sun, Jun 6, 2021 at 5:36 PM Miller Puckette <<a ymailto="mailto:msp@ucsd.edu" href="mailto:msp@ucsd.edu">msp@ucsd.edu</a>> wrote:<br>
</div>

<div dir="ltr">> <br>
</div>

<div dir="ltr">> > clock() is the only mechanism - for repeats, the easiest thing is often<br>
</div>

<div dir="ltr">> > to just re-use a clock() and re-set it each time it goes off (as in<br>
</div>

<div dir="ltr">> > the metro obejct).  You can indeed create clock obejcts on the fly -<br>
</div>

<div dir="ltr">> > that's what pipe does.  But you'll want to keep track of them so you can<br>
</div>

<div dir="ltr">> > cancel them if the owning object goes away.<br>
</div>

<div dir="ltr">> ><br>
</div>

<div dir="ltr">> > cheers<br>
</div>

<div dir="ltr">> > M<br>
</div>

<div dir="ltr">> ><br>
</div>

<div dir="ltr">> > On Sun, Jun 06, 2021 at 05:16:09PM -0700, Iain Duncan wrote:<br>
</div>

<div dir="ltr">> > > Ah fantastic, thanks. I was looking in pipe and not seeing it, but was<br>
</div>

<div dir="ltr">> > > probably just lost in other new details and not seeing the forest for the<br>
</div>

<div dir="ltr">> > > trees. :-)<br>
</div>

<div dir="ltr">> > ><br>
</div>

<div dir="ltr">> > > Couple of follow ups:<br>
</div>

<div dir="ltr">> > > - is there a separate facility for making a repeated callback (ie not<br>
</div>

<div dir="ltr">> > > one-shot), or does one just do both with clock?<br>
</div>

<div dir="ltr">> > > - is it safe to make clocks as we need them (ie during a method call, not<br>
</div>

<div dir="ltr">> > > necessarily at object instantiation time), or is this the kind of thing<br>
</div>

<div dir="ltr">> > > where for real time use one needs to make a clock pool and a pool manager<br>
</div>

<div dir="ltr">> > > and all that?<br>
</div>

<div dir="ltr">> > ><br>
</div>

<div dir="ltr">> > > thanks!<br>
</div>

<div dir="ltr">> > > iain<br>
</div>

<div dir="ltr">> > ><br>
</div>

<div dir="ltr">> > > On Sun, Jun 6, 2021 at 5:12 PM Miller Puckette <<a ymailto="mailto:msp@ucsd.edu" href="mailto:msp@ucsd.edu">msp@ucsd.edu</a>> wrote:<br>
</div>

<div dir="ltr">> > ><br>
</div>

<div dir="ltr">> > > > Yep, clock_delay() .  Simples example is in Pd's "delay" object,<br>
</div>

<div dir="ltr">> > x_time.c<br>
</div>

<div dir="ltr">> > > ><br>
</div>

<div dir="ltr">> > > > cheers<br>
</div>

<div dir="ltr">> > > > Miller<br>
</div>

<div dir="ltr">> > > ><br>
</div>

<div dir="ltr">> > > > On Sun, Jun 06, 2021 at 04:21:46PM -0700, Iain Duncan wrote:<br>
</div>

<div dir="ltr">> > > > > Hi folks, I'm hoping someone can point me in the right direction<br>
</div>

<div dir="ltr">> > here.<br>
</div>

<div dir="ltr">> > > > I'm<br>
</div>

<div dir="ltr">> > > > > porting Scheme for Max to pure data and I'm stuck figuring out how<br>
</div>

<div dir="ltr">> > to get<br>
</div>

<div dir="ltr">> > > > > delayed functions going. In Max, the SDK has a facility to make<br>
</div>

<div dir="ltr">> > register<br>
</div>

<div dir="ltr">> > > > a<br>
</div>

<div dir="ltr">> > > > > callback to executed at some point in the future, a few different<br>
</div>

<div dir="ltr">> > ways.<br>
</div>

<div dir="ltr">> > > > Is<br>
</div>

<div dir="ltr">> > > > > there a Pd equivalent, and if so, could anyone point me at resources<br>
</div>

<div dir="ltr">> > or<br>
</div>

<div dir="ltr">> > > > > code for it?  I basically just need to be able to have a callback<br>
</div>

<div dir="ltr">> > fire<br>
</div>

<div dir="ltr">> > > > off<br>
</div>

<div dir="ltr">> > > > > at the right time with one argument, which can be void pointer to the<br>
</div>

<div dir="ltr">> > > > rest<br>
</div>

<div dir="ltr">> > > > > of the stuff i want to get.<br>
</div>

<div dir="ltr">> > > > ><br>
</div>

<div dir="ltr">> > > > > thanks!<br>
</div>

<div dir="ltr">> > > > > iain<br>
</div>

<div dir="ltr">> > > ><br>
</div>

<div dir="ltr">> > > > > _______________________________________________<br>
</div>

<div dir="ltr">> > > > > Pd-dev mailing list<br>
</div>

<div dir="ltr">> > > > > <a ymailto="mailto:Pd-dev@lists.iem.at" href="mailto:Pd-dev@lists.iem.at">Pd-dev@lists.iem.at</a><br>
</div>

<div dir="ltr">> > > > ><br>
</div>

<div dir="ltr">> > > ><br>
</div>

<div dir="ltr">> > <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.puredata.info_listinfo_pd-2Ddev&d=DwICAg&c=-35OiAkTchMrZOngvJPOeA&r=XprZV3Fxus2L1LCw80hE4Q&m=uekrR-wLMB9CDNku0beRkRmoSJoExinRbBSlb0UQknQ&s=98jkGlO1FFE0Ea5fhSopCbZt6bmZH580Y0IUfgX4Rwk&e=" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.puredata.info_listinfo_pd-2Ddev&d=DwICAg&c=-35OiAkTchMrZOngvJPOeA&r=XprZV3Fxus2L1LCw80hE4Q&m=uekrR-wLMB9CDNku0beRkRmoSJoExinRbBSlb0UQknQ&s=98jkGlO1FFE0Ea5fhSopCbZt6bmZH580Y0IUfgX4Rwk&e=</a><br>
</div>

<div dir="ltr">> > > ><br>
</div>

<div dir="ltr">> > > ><br>
</div>

<div dir="ltr">> > > > --<br>
</div>

<div dir="ltr">> > > ><br>
</div>

<div dir="ltr">> ><br>
</div>

<div dir="ltr">> > --<br>
</div>

<div dir="ltr">> ><br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">-- <br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">------------------------------<br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">Subject: Digest Footer<br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">_______________________________________________<br>
</div>

<div dir="ltr">Pd-dev mailing list<br>
</div>

<div dir="ltr"><a ymailto="mailto:Pd-dev@lists.iem.at" href="mailto:Pd-dev@lists.iem.at">Pd-dev@lists.iem.at</a><br>
</div>

<div dir="ltr"><a href="https://lists.puredata.info/listinfo/pd-dev" target="_blank">https://lists.puredata.info/listinfo/pd-dev</a><br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">------------------------------<br>
</div>

<div dir="ltr"><br>
</div>

<div dir="ltr">End of Pd-dev Digest, Vol 194, Issue 4<br>
</div>

<div dir="ltr">**************************************<br>
</div>
</font></div>
</div>
</div>