<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Here's how:<br>
</p>
<pre>struct t_myexternal {
t_object x_obj;
t_clock *x_clock;
int x_running;
};
</pre>
<pre>void tick(t_myexternal *x)
{
// do some work
// then reschedule (if not cancelled)
if (x->x_running)
clock_delay(x->x_clock, POLLINTERVAL);
}
</pre>
<pre>void start(t_myexternal *x)
{
clock_delay(x->x_clock, 0);
x->x_running = true;
}
void stop(t_myexternal *x)
{
x->x_running = false;
}
void* myexternal_new(void)
t_myexternal *x = pd_new(myexternal_class);
x->x_clock = clock_new(x, (t_method)tick);
x->x_running = false;
}
</pre>
Hope this helps!<br>
<br>
Christof<br>
<div class="moz-cite-prefix">On 29.04.2021 18:12, Kyriakos
Charalampides via Pd-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:3274865D-B660-461C-9866-CBE532FF1CCE@icloud.com">
<pre class="moz-quote-pre" wrap="">I recently started learning how to write some custom pd externals. It has been quite fun until now, but its been a few days I am stuck in a loop. I want to read a buffer coming from an external device every 1 ms. I could do that with a metro but this can cause several issues with this buffer.
My initial though was to use a for loop but this was obviously a horrible idea since pd will stuck in the for loop and hang. Then I though to use a clock to execute my reading function but all examples with clock and clock_delay seem to be based on for and while loops. What I would really like to achieve is to execute the reading function every 1ms and interrupt this process every time that a new message is coming from pd.
Any tips or ideas will be highly appreciated.
All best,
Kyr
_______________________________________________
Pd-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Pd-dev@lists.iem.at">Pd-dev@lists.iem.at</a>
<a class="moz-txt-link-freetext" href="https://lists.puredata.info/listinfo/pd-dev">https://lists.puredata.info/listinfo/pd-dev</a>
</pre>
</blockquote>
</body>
</html>