From 71b83fc040b848c98c5065d95ecbc72b0b4f8943 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 17 Jan 2013 22:54:00 +0000 Subject: merging maxlib v1.5.5 from branches/pd-extended/0.43 svn path=/trunk/externals/maxlib/; revision=16897 --- edge.c | 164 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 82 insertions(+), 82 deletions(-) (limited to 'edge.c') diff --git a/edge.c b/edge.c index 4f32e8a..8d94c71 100644 --- a/edge.c +++ b/edge.c @@ -1,82 +1,82 @@ -/* --------------------------- edge ----------------------------------------- */ -/* */ -/* Detect rising or falling edge of float input. */ -/* Written by Olaf Matthes (olaf.matthes@gmx.de) */ -/* Get source at http://www.akustische-kunst.org/puredata/maxlib/ */ -/* */ -/* This program is free software; you can redistribute it and/or */ -/* modify it under the terms of the GNU General Public License */ -/* as published by the Free Software Foundation; either version 2 */ -/* of the License, or (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* */ -/* Based on PureData by Miller Puckette and others. */ -/* */ -/* ---------------------------------------------------------------------------- */ - -#include "m_pd.h" -#include - -static char *version = "edge v0.1, written by Olaf Matthes "; - -typedef struct edge -{ - t_object x_ob; - t_outlet *x_out1; /* bang on rising edge */ - t_outlet *x_out2; /* bang on falling edge */ - t_float x_lastval; /* last input value */ -} t_edge; - -static void edge_float(t_edge *x, t_floatarg f) -{ - if((x->x_lastval <= 0) && (f >= 1)) /* rising edge */ - outlet_bang(x->x_out1); - else if((x->x_lastval >= 1) && (f <= 0)) /* falling edge */ - outlet_bang(x->x_out2); - - x->x_lastval = f; /* save last value */ -} - -static t_class *edge_class; - -static void *edge_new(t_floatarg f) -{ - int i; - - t_edge *x = (t_edge *)pd_new(edge_class); - x->x_out1 = outlet_new(&x->x_ob, gensym("bang")); - x->x_out2 = outlet_new(&x->x_ob, gensym("bang")); - - x->x_lastval = f; - - return (void *)x; -} - -#ifndef MAXLIB -void edge_setup(void) -{ - edge_class = class_new(gensym("edge"), (t_newmethod)edge_new, - 0, sizeof(t_edge), 0, A_DEFFLOAT, 0); - class_addfloat(edge_class, edge_float); - - post(version); -} -#else -void maxlib_edge_setup(void) -{ - edge_class = class_new(gensym("maxlib_edge"), (t_newmethod)edge_new, - 0, sizeof(t_edge), 0, A_DEFFLOAT, 0); - class_addfloat(edge_class, edge_float); - class_addcreator((t_newmethod)edge_new, gensym("edge"), A_DEFFLOAT, 0); - class_sethelpsymbol(edge_class, gensym("maxlib/edge-help.pd")); -} -#endif - +/* --------------------------- edge ----------------------------------------- */ +/* */ +/* Detect rising or falling edge of float input. */ +/* Written by Olaf Matthes (olaf.matthes@gmx.de) */ +/* Get source at http://www.akustische-kunst.org/puredata/maxlib/ */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* ---------------------------------------------------------------------------- */ + +#include "m_pd.h" +#include + +static char *version = "edge v0.1, written by Olaf Matthes "; + +typedef struct edge +{ + t_object x_ob; + t_outlet *x_out1; /* bang on rising edge */ + t_outlet *x_out2; /* bang on falling edge */ + t_float x_lastval; /* last input value */ +} t_edge; + +static void edge_float(t_edge *x, t_floatarg f) +{ + if((x->x_lastval <= 0) && (f >= 1)) /* rising edge */ + outlet_bang(x->x_out1); + else if((x->x_lastval >= 1) && (f <= 0)) /* falling edge */ + outlet_bang(x->x_out2); + + x->x_lastval = f; /* save last value */ +} + +static t_class *edge_class; + +static void *edge_new(t_floatarg f) +{ + int i; + + t_edge *x = (t_edge *)pd_new(edge_class); + x->x_out1 = outlet_new(&x->x_ob, gensym("bang")); + x->x_out2 = outlet_new(&x->x_ob, gensym("bang")); + + x->x_lastval = f; + + return (void *)x; +} + +#ifndef MAXLIB +void edge_setup(void) +{ + edge_class = class_new(gensym("edge"), (t_newmethod)edge_new, + 0, sizeof(t_edge), 0, A_DEFFLOAT, 0); + class_addfloat(edge_class, edge_float); + + logpost(NULL, 4, version); +} +#else +void maxlib_edge_setup(void) +{ + edge_class = class_new(gensym("maxlib_edge"), (t_newmethod)edge_new, + 0, sizeof(t_edge), 0, A_DEFFLOAT, 0); + class_addfloat(edge_class, edge_float); + class_addcreator((t_newmethod)edge_new, gensym("edge"), A_DEFFLOAT, 0); + class_sethelpsymbol(edge_class, gensym("maxlib/edge-help.pd")); +} +#endif + -- cgit v1.2.1