From fc3d3c0a4f110a23335398c327ac0a4fc949d5cb Mon Sep 17 00:00:00 2001 From: Guenter Geiger Date: Mon, 17 Jun 2002 10:13:57 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r12, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/ggee/; revision=13 --- signal/rtin~.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 signal/rtin~.c (limited to 'signal/rtin~.c') diff --git a/signal/rtin~.c b/signal/rtin~.c new file mode 100755 index 0000000..d086003 --- /dev/null +++ b/signal/rtin~.c @@ -0,0 +1,76 @@ +/* (C) Guenter Geiger */ + + + #include + #include + #include + #include + #include + +// int gettimeofday(struct timeval *tv, struct timezone *tz); + + + +#include "math.h" +#include + + +/* ----------------------------- rtin ----------------------------- */ +static t_class *rtin_class; + + +#define INVTWOPI 0.15915494f + +typedef struct _rtin +{ + t_object x_obj; + t_int fd; + t_int usec; +} t_rtin; + +static void *rtin_new(t_symbol *s, int argc, t_atom *argv) +{ + t_rtin *x = (t_rtin *)pd_new(rtin_class); + /* inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);*/ + outlet_new(&x->x_obj, &s_float); + + x->usec=0; + x->fd = open("/dev/midi00",O_RDWR|O_NDELAY); + + return (x); + +} + +t_int *rtin_perform(t_int *w) +{ + struct timeval tv; + long diff; + t_rtin* x = (t_rtin *)(w[1]); +// int n = (int)(w[2]); + char c; + + + if (read(x->fd,&c,1) == 1) { + gettimeofday(&tv, NULL); + diff = tv.tv_usec - x->usec; + if (diff < 0) diff+=1000000; + if (diff > 10000) outlet_float(x->x_obj.ob_outlet,diff*0.001); + x->usec=tv.tv_usec; + } + + + return (w+2); +} + +static void rtin_dsp(t_rtin *x, t_signal **sp) +{ + dsp_add(rtin_perform, 1, x); +} + +void rtin_tilde_setup(void) +{ + rtin_class = class_new(gensym("rtin~"), (t_newmethod)rtin_new, 0, + sizeof(t_rtin), 0, A_GIMME, 0); + class_addmethod(rtin_class, nullfn, gensym("signal"), 0); + class_addmethod(rtin_class, (t_method)rtin_dsp, gensym("dsp"), 0); +} -- cgit v1.2.1