From f6833c650cd755a7c9a142bf667baff8add0ea31 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Wed, 9 Aug 2006 01:14:06 +0000 Subject: added help file that shows how to use with [hid] (almost complete), and parseeventnodenum.c svn path=/trunk/externals/input_noticer/; revision=5527 --- parseeventnodenum.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 parseeventnodenum.c (limited to 'parseeventnodenum.c') diff --git a/parseeventnodenum.c b/parseeventnodenum.c new file mode 100644 index 0000000..e8ddae1 --- /dev/null +++ b/parseeventnodenum.c @@ -0,0 +1,65 @@ +/* + * author: David Merrill + * based on code from Tom Schouten, found online at: + * http://lists.puredata.info/pipermail/pd-list/2002-02/004871.html + */ + +#include "m_pd.h" +#include + +#define MAXHEAD 1024 + +typedef struct{ + char buffer[MAXHEAD]; +} t_parseeventnodenum_data; + +typedef struct parseeventnodenum +{ + t_object t_ob; + t_outlet *x_out; + t_outlet *x_out_error; +} t_parseeventnodenum; + +void penn_any_method(t_parseeventnodenum *x, t_symbol *s, int argc, t_atom *argv) +{ + char* p = s->s_name; + int eventnodenum = -1, rv = 0; + + if (sscanf(p,"/dev/input/event%i",&eventnodenum)) { + + // success, send the float to the left outlet + outlet_float(x->x_out, eventnodenum); + } else { + + // failure, send the input symbol to the right outlet + outlet_symbol(x->x_out_error, gensym(p)); + } +} + +void parseeventnodenum_free(void) +{ +} + +t_class *parseeventnodenum_class; + +void *parseeventnodenum_new(void) +{ + t_parseeventnodenum *x = (t_parseeventnodenum *)pd_new(parseeventnodenum_class); + + // left outlet is where the parsed number will come out + x->x_out = outlet_new(&x->t_ob, gensym("float")); + + // right outlet is where the original string will come out if an error occured + x->x_out_error = outlet_new(&x->t_ob, gensym("symbol")); + + + return (void *)x; +} + +void parseeventnodenum_setup(void) +{ + parseeventnodenum_class = class_new(gensym("parseeventnodenum"), (t_newmethod)parseeventnodenum_new, + (t_method)parseeventnodenum_free, sizeof(t_parseeventnodenum), 0, 0); + class_addanything(parseeventnodenum_class, penn_any_method); +} + -- cgit v1.2.1