diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2010-12-13 01:08:45 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2010-12-13 01:08:45 +0000 |
commit | a7af081228de119a07bc18bcb35f0bbf567f9dd8 (patch) | |
tree | d08f91f26307df1ae40a45633ab0094c391c1371 /externals/vanilla/timer.c | |
parent | 8cd5a0079b644c5b9bc95072e269be8457d56a97 (diff) |
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
Diffstat (limited to 'externals/vanilla/timer.c')
-rw-r--r-- | externals/vanilla/timer.c | 43 |
1 files changed, 43 insertions, 0 deletions
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 <stdio.h> + +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); +} |