From 35ef784adf86ce8f41411b540c5324a8e912fc7c Mon Sep 17 00:00:00 2001 From: "N.N." Date: Mon, 2 Jan 2006 07:20:49 +0000 Subject: new external [rtimer] svn path=/trunk/abstractions/pureunity/; revision=4352 --- Makefile | 3 ++- pureunity.c | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 76c27ba..7bd0263 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ PD = /home/matju/pd_0_38_4/bin/pd -noaudio #PD = pd PDFLAGS = -lib pureunity -noaudio -path generics -path specifics +CFLAGS = -Wall test:: built $(PD) $(PDFLAGS) main.pd @@ -12,5 +13,5 @@ built: Makefile pureunity.pd_linux generic/%~.pd: generic/%.pd pureunity.pd_linux: pureunity.c Makefile - $(CC) -shared -o pureunity.pd_linux pureunity.c + $(CC) $(CFLAGS) -shared -o pureunity.pd_linux pureunity.c diff --git a/pureunity.c b/pureunity.c index a68887b..c721be1 100644 --- a/pureunity.c +++ b/pureunity.c @@ -1,9 +1,40 @@ +#include /*#include */ #include "../../pd/src/m_pd.h" +#define ALIAS(y,x) class_addcreator((t_newmethod)getfn(m,gensym(x)),gensym(y),A_GIMME,0); + +typedef struct { + t_text o; + struct timeval t0; +} t_rtimer; + +t_class *rtimer_class; +void rtimer_reset(t_rtimer *self) {gettimeofday(&self->t0,0);} +void *rtimer_new(t_symbol *s) { + t_rtimer *self = (t_rtimer *)pd_new(rtimer_class); + inlet_new((t_text *)self, (t_pd *)self, gensym("bang"), gensym("1_bang")); + outlet_new((t_text *)self, gensym("float")); + rtimer_reset(self); + return self; +} + +void rtimer_1_bang(t_rtimer *self) { + struct timeval t1; + gettimeofday(&t1,0); + outlet_float(self->o.ob_outlet, + (t1.tv_sec -self->t0.tv_sec )*1000.0 + + (t1.tv_usec-self->t0.tv_usec)/1000.0); +} + void pureunity_setup() { - t_pd *m = &pd_objectmaker; - class_addcreator((t_newmethod)getfn(m,gensym( "inlet" )),gensym("f.inlet" ),A_GIMME,0); - class_addcreator((t_newmethod)getfn(m,gensym( "inlet~")),gensym("~.inlet" ),A_GIMME,0); - class_addcreator((t_newmethod)getfn(m,gensym("outlet" )),gensym("f.outlet"),A_GIMME,0); - class_addcreator((t_newmethod)getfn(m,gensym("outlet~")),gensym("~.outlet"),A_GIMME,0); + t_pd *m = &pd_objectmaker; + ALIAS( "f.inlet","inlet" ); + ALIAS( "~.inlet","inlet~" ); + ALIAS("f.outlet","outlet" ); + ALIAS("~.outlet","outlet~"); + ALIAS( "f.swap","swap" ); + rtimer_class = class_new(gensym("rtimer"),(t_newmethod)rtimer_new,0,sizeof(t_rtimer),0,0); + class_addbang(rtimer_class,rtimer_reset); + class_addmethod(rtimer_class, (t_method)rtimer_1_bang, gensym("1_bang"), 0); } + -- cgit v1.2.1