From a7af081228de119a07bc18bcb35f0bbf567f9dd8 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 13 Dec 2010 01:08:45 +0000 Subject: refactored x_time.c into delay.c pipe.c metro.c delay.c timer.c line.c and an alias, del.c svn path=/trunk/; revision=14599 --- externals/vanilla/timer.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 externals/vanilla/timer.c (limited to 'externals/vanilla/timer.c') diff --git a/externals/vanilla/timer.c b/externals/vanilla/timer.c new file mode 100644 index 00000000..675dafe6 --- /dev/null +++ b/externals/vanilla/timer.c @@ -0,0 +1,43 @@ +/* Copyright (c) 1997-1999 Miller Puckette. +* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +/* clock objects */ + +#include "m_pd.h" +#include + +static t_class *timer_class; + +typedef struct _timer +{ + t_object x_obj; + double x_settime; +} t_timer; + +static void timer_bang(t_timer *x) +{ + x->x_settime = clock_getsystime(); +} + +static void timer_bang2(t_timer *x) +{ + outlet_float(x->x_obj.ob_outlet, clock_gettimesince(x->x_settime)); +} + +static void *timer_new(t_floatarg f) +{ + t_timer *x = (t_timer *)pd_new(timer_class); + timer_bang(x); + outlet_new(&x->x_obj, gensym("float")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("bang"), gensym("bang2")); + return (x); +} + +static void timer_setup(void) +{ + timer_class = class_new(gensym("timer"), (t_newmethod)timer_new, 0, + sizeof(t_timer), 0, A_DEFFLOAT, 0); + class_addbang(timer_class, timer_bang); + class_addmethod(timer_class, (t_method)timer_bang2, gensym("bang2"), 0); +} -- cgit v1.2.1