Hallo, Greg Surges hat gesagt: // Greg Surges wrote:
It looks like this is the right track...
Looking at the metro code, I'm a little confused as to how the object continues to output bangs after the first. What does it mean that clock_delay "calls back"?
When you create a new clock with clock_new, you pass it a method "fn":
EXTERN t_clock *clock_new(void *owner, t_method fn);
"fn" is the callback method, that gets called, if you later run "clock_delay" with your clock and the delaytime. It gets "owner" passed as argument, so it's called as: "fn(owner)"
In the metro-code, the clock is created in metro_new:
x->x_clock = clock_new(x, (t_method)metro_tick);
Here "metro_tick" get registered as the callback method of clock "x->c_clock". Then "metro_float" is responsible to start the metro, which is made by calling "metro_tick(x)" directly once, if the incoming float is not 0.
After that, "metro_tick" kind of calls itself over and over again using "clock_delay(x->x_clock, x->x_deltime);": Each time, "clock_delay" is called, it waits for x->x_deltime to then call the registered method, "metro_tick(x)", again.
You use clock_unset to stop the clock, and clock_free to destroy and free it completely.
It may be easier to first understand how [delay] works, as it's a bit simpler. And for a more complicated object, try to figure out how [pipe] works. ;)
Ciao