<div dir="ltr">Thanks Seb, that's helpful and  gives me some stuff to chew on. Is the code in which you've done this public?<div><br></div><div>iain</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jun 13, 2021 at 9:40 PM Sebastian Shader via Pd-dev <<a href="mailto:pd-dev@lists.iem.at">pd-dev@lists.iem.at</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">
<div style="color:black;font:10pt arial">><span style="font-family:helvetica,arial;font-size:10pt">1) Is the Pd clock scheduler only accurate to the ms or does it operate at</span>
<div dir="ltr" style="font-family:helvetica,arial">>higher than ms accuracy? (As in, if I wanted to role my own mechanism<br>
</div>

<div dir="ltr" style="font-family:helvetica,arial">>closer to what Seb did, how frequently should my master time go off?)</div>

<div><br>
</div>
from what I can tell Pd seems to use its own unit of time in order to interface better with the audio side of things, (but it's stored in a double)
<div>lua uses double for it's numbers, and I just used milliseconds (partially because the pd clocks seem to work/have worked with milliseconds primarily/historically)</div>

<div><br>
</div>

<div>I'm not sure I understand "how frequently should my master time go off?"<br>
You have the clock callbacks stored in the priority queue, and use the scheduled time (in ms) for the keys the queue is sorted by.</div>

<div>So in order to "start a delay", you put a callback on the queue. Then to start your scheduler, call the underlying t_clock delay with the value of the difference between the time of the top value in the queue (which will be the earliest callback because you set up the priority queue to sort as a min-heap, so that the lowest times get popped out first) and the current time.</div>

<div>Every time you return from the underlying t_clock callback, increment your own time by the amount the underlying t_clock was called with/delayed for (in milliseconds stored in a double, in my case).</div>

<div><br>
</div>

<div>The nice thing about using t_clock is that you don't need to implement the delay part yourself, just the priority queue and figuring out when to start and stop it. (along with dispatching the callbacks associated with members in the queue, wherever those go.)</div>

<div><br>
</div>

<div>What I do is put my "main thread" on the queue to start. Every time another thread/coroutine is started/sprouted it gets added to the queue. Whenever a delay is encountered the current thread will be at the top of the queue, so you just have to change the delay time and call some downheap() function on the heap to restore the heap property after changing the delay time in the priority queue member. (then delay the t_clock by the new top member of the queue)</div>

<div>Every time a coroutine finishes I take it off of the top of the queue. (and call another t_clock delay for the new top member, or stop if there are none left)</div>

<div><br>
</div>

<div>-Seb<br>
<br>

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

<div dir="ltr">Date: Sat, 12 Jun 2021 11:11:12 -0700<br>
</div>

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

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

<div dir="ltr">Subject: [PD-dev] More clock questions<br>
</div>

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

<div dir="ltr">I have a couple more clock/schedule related questions after rereading the<br>
</div>

<div dir="ltr">comments from Miller and Seb.<br>
</div>

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

<div dir="ltr">1) Is the Pd clock scheduler only accurate to the ms or does it operate at<br>
</div>

<div dir="ltr">higher than ms accuracy? (As in, if I wanted to role my own mechanism<br>
</div>

<div dir="ltr">closer to what Seb did, how frequently should my master time go off?)<br>
</div>

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

<div dir="ltr">2) Miller made reference to the linked list of clocks that pd iterates<br>
</div>

<div dir="ltr">through. Is that something I could access directly? (and if so, where would<br>
</div>

<div dir="ltr">it live?<br>
</div>

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

<div dir="ltr">3) if anyone knows good books or online resources for learning more about<br>
</div>

<div dir="ltr">writing scheduler related code, I'm all ears! :-)<br>
</div>

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

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

<div dir="ltr">iain</div>
</font></div>
</div>
</div>
_______________________________________________<br>
Pd-dev mailing list<br>
<a href="mailto:Pd-dev@lists.iem.at" target="_blank">Pd-dev@lists.iem.at</a><br>
<a href="https://lists.puredata.info/listinfo/pd-dev" rel="noreferrer" target="_blank">https://lists.puredata.info/listinfo/pd-dev</a><br>
</blockquote></div>