Hi all,
Is there any way to have an external call a method periodically, without being triggered? I'm thinking of a histogram with a decay function, where the values are decremented every second (or other time value).
Thanks!
-Greg
Hallo!
Greg Surges schrieb:
Hi all,
Is there any way to have an external call a method periodically, without being triggered? I'm thinking of a histogram with a decay function, where the values are decremented every second (or other time value).
Clocks can be used to do that. Look e.g. at the code of the metro object in pd core. You could also look at externals/grh/threadlib/callbacks.c, but I guess it's easier to understand it in the metro object code.
LG Georg
Greg Surges wrote:
Hi all,
Is there any way to have an external call a method periodically, without being triggered?
Clocks. Check the C API in "m_pd.h"..
I'm thinking of a histogram with a decay function, where the values are decremented every second (or other time value).
I've done something like this with Lua, although I had the decrementing done by a [gemhead] not an internal clock, for tighter syncing with visuals. That's what made the keys fade from orange->grey->blue, if you happened to be at LAC Club Night during my set.
Thanks!
-Greg
Claude
Thanks Claude and Georg,
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"?
Thanks
On Mon, Mar 17, 2008 at 3:13 PM, Claude Heiland-Allen < claudiusmaximus@goto10.org> wrote:
Greg Surges wrote:
Hi all,
Is there any way to have an external call a method periodically, without being triggered?
Clocks. Check the C API in "m_pd.h"..
I'm thinking of a histogram with a decay function, where the values are decremented every second (or other time value).
I've done something like this with Lua, although I had the decrementing done by a [gemhead] not an internal clock, for tighter syncing with visuals. That's what made the keys fade from orange->grey->blue, if you happened to be at LAC Club Night during my set.
Thanks!
-Greg
Claude
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
First, you register a function with clock_set(). Usually that function is called myobjectname_tick(). Then when it runs, you call clock_delay() to schedule when myobjectname_tick() will get called again.
.hc
On Mar 17, 2008, at 4:49 PM, Greg Surges wrote:
Thanks Claude and Georg,
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"?
Thanks
On Mon, Mar 17, 2008 at 3:13 PM, Claude Heiland-Allen claudiusmaximus@goto10.org wrote: Greg Surges wrote:
Hi all,
Is there any way to have an external call a method periodically,
without
being triggered?
Clocks. Check the C API in "m_pd.h"..
I'm thinking of a histogram with a decay function, where the
values are
decremented every second (or other time value).
I've done something like this with Lua, although I had the decrementing done by a [gemhead] not an internal clock, for tighter syncing with visuals. That's what made the keys fade from orange->grey->blue, if you happened to be at LAC Club Night during my set.
Thanks!
-Greg
Claude
http://claudiusmaximus.goto10.org
-- http://www.uwm.edu/~gssurges/ _______________________________________________ PD-dev mailing list PD-dev@iem.at http://lists.puredata.info/listinfo/pd-dev
------------------------------------------------------------------------ ----
Using ReBirth is like trying to play an 808 with a long stick. - David Zicarelli
Thanks all,
I'm still stuck. Is there a way to interleave calls to clock_delay()?
I'll explain what I mean:
I'm coding (trying to, anyway) a histogram object. I'm using integers from input to increment the values stored in an array. For example, if 76 is received as input, the value in the array at index 76 is incremented. This way, there's a running total of the frequency with which a number occurs.
The problem is, I want the histogram to have a time window. So, a specified amount of time after an index is incremented, it should decrement automatically. I'm calling clock_delay() in the array incrementing function, which calls the decrementing function after the specified "decay" time. However, if you have two or more inputs before the decay time is up, only the most recent call from clock_delay() completes.
What's happening is: (Decay time of 2 seconds) 76 is input at 0:00 32 is input at 0:015
32 decrements at 0:035
What I want to happen is: (Decay time is 2 seconds) 76 is input at 0:00 32 is input at 0:015
76 decrements at 0:02 32 decrements at 0:035
Can anyone help me with a way around this?
Thanks again, this community has been really friendly and helpful as I start out learning.
-Greg Surges
If you post the code, it would be much easier to tell what's happening. My guess is that you can only have one delay set for a given clock, so like this:
- 76 sets the timer - 32 resets the timer with new info
Therefore the timer callback set by 76 never gets called. (Something like that, it's still morning here ;)
.hc
On Mar 21, 2008, at 11:24 PM, Greg Surges wrote:
Thanks all,
I'm still stuck. Is there a way to interleave calls to clock_delay()?
I'll explain what I mean:
I'm coding (trying to, anyway) a histogram object. I'm using integers from input to increment the values stored in an array. For example, if 76 is received as input, the value in the array at index 76 is incremented. This way, there's a running total of the frequency with which a number occurs.
The problem is, I want the histogram to have a time window. So, a specified amount of time after an index is incremented, it should decrement automatically. I'm calling clock_delay() in the array incrementing function, which calls the decrementing function after the specified "decay" time. However, if you have two or more inputs before the decay time is up, only the most recent call from clock_delay() completes.
What's happening is: (Decay time of 2 seconds) 76 is input at 0:00 32 is input at 0:015
32 decrements at 0:035
What I want to happen is: (Decay time is 2 seconds) 76 is input at 0:00 32 is input at 0:015
76 decrements at 0:02 32 decrements at 0:035
Can anyone help me with a way around this?
Thanks again, this community has been really friendly and helpful as I start out learning.
-Greg Surges
------------------------------------------------------------------------ ----
You can't steal a gift. Bird gave the world his music, and if you can hear it, you can have it. - Dizzy Gillespie
Thanks,
I've posted the code at http://www.uwm.edu/~gssurges/histogram.chttp://www.uwm.edu/%7Egssurges/histogram.c
Hope it makes sense...
-Greg
On Sat, Mar 22, 2008 at 11:06 AM, Hans-Christoph Steiner hans@eds.org wrote:
If you post the code, it would be much easier to tell what's happening. My guess is that you can only have one delay set for a given clock, so like this:
- 76 sets the timer
- 32 resets the timer with new info
Therefore the timer callback set by 76 never gets called. (Something like that, it's still morning here ;)
.hc
On Mar 21, 2008, at 11:24 PM, Greg Surges wrote:
Thanks all,
I'm still stuck. Is there a way to interleave calls to clock_delay()?
I'll explain what I mean:
I'm coding (trying to, anyway) a histogram object. I'm using integers from input to increment the values stored in an array. For example, if 76 is received as input, the value in the array at index 76 is incremented. This way, there's a running total of the frequency with which a number occurs.
The problem is, I want the histogram to have a time window. So, a specified amount of time after an index is incremented, it should decrement automatically. I'm calling clock_delay() in the array incrementing function, which calls the decrementing function after the specified "decay" time. However, if you have two or more inputs before the decay time is up, only the most recent call from clock_delay() completes.
What's happening is: (Decay time of 2 seconds) 76 is input at 0:00 32 is input at 0:015
32 decrements at 0:035
What I want to happen is: (Decay time is 2 seconds) 76 is input at 0:00 32 is input at 0:015
76 decrements at 0:02 32 decrements at 0:035
Can anyone help me with a way around this?
Thanks again, this community has been really friendly and helpful as I start out learning.
-Greg Surges
http://www.uwm.edu/~gssurges/ http://www.uwm.edu/%7Egssurges/
You can't steal a gift. Bird gave the world his music, and if you can hear it, you can have it. - Dizzy Gillespie