Hello all,
I'm exploring my very first external! But I've run into a snag.
I'd like to build an external object which outputs the number of seconds since "epoch" when banged. Epoch is the beginning of time as the digital world understands it: jan 1 1970.
Could somebody look over the following code and tell me why it works only after the FIRST BANG?
Many thanks Regards, Dave S
#include "m_pd.h" #include "time.h"
static t_class *epochtime_class;
typedef struct _epochtime { t_object x_obj; time_t t; } t_epochtime;
void epochtime_bang(t_epochtime *x) { t_float f=x->t; x->t=time( NULL );
outlet_float(x->x_obj.ob_outlet, f); }
void *epochtime_new(t_floatarg f) { t_epochtime *x = (t_epochtime *)pd_new(epochtime_class);
x->t=f; outlet_new(&x->x_obj, &s_float);
return (void *)x; }
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); }