Hello all,
I succeeded actually using a slightly different approach as you can see in the following source code: Instead of storing the number in a variable, I decided to put the time(NULL) function directly into the outgoing argument to the outlet.
In any case, I don't think this object will be of any use to anybody because PD returns the following number: 1.03777e+009 (or something like it) which can't be used very reliably. I mean it works, but I can't see the seconds pass -- i can only observe the passage of time every 64 seconds or so. (What I mean is that the object will output the same number for about 64 seconds, then it outputs another number which is slightly higher.)
Perhaps Miller has an answer to this? I know that the floating point values in PD are limited to a specific range -- is that the cause of this phenomenon.?
I attached the compiled external and a "epochtime_test.pd" if you want to witness this for yourself.
Regards, Dave S
p.s.: What I'm REALLY trying to do is put together a "difftime()" type of routine. But this "epochtime" seemed simpler and a logical place to begin.
#include "m_pd.h" #include "time.h"
static t_class *epochtime_class;
typedef struct _epochtime { t_object x_obj; } t_epochtime;
void *epochtime_new(void) { t_epochtime *x = (t_epochtime *)pd_new(epochtime_class);
outlet_new(&x->x_obj, &s_float);
return (x); }
void epochtime_bang(t_epochtime *x) { outlet_float(x->x_obj.ob_outlet, (t_float) (time( NULL ))); }
void epochtime_setup(void) { epochtime_class = class_new(gensym("epochtime"), (t_newmethod)epochtime_new, 0, sizeof(t_epochtime), CLASS_DEFAULT, 0);
class_addbang(epochtime_class, epochtime_bang); }