From 0c9b89b1018eb7760708ee5b080cd96846861328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 2 Jun 2005 18:25:00 +0000 Subject: updated to release-1.16 svn path=/trunk/externals/iemlib/; revision=3102 --- src/iemlib2/modulo_counter.c | 181 ++++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 90 deletions(-) (limited to 'src/iemlib2/modulo_counter.c') diff --git a/src/iemlib2/modulo_counter.c b/src/iemlib2/modulo_counter.c index 3c072e2..309b5a0 100644 --- a/src/iemlib2/modulo_counter.c +++ b/src/iemlib2/modulo_counter.c @@ -1,90 +1,91 @@ -/* Copyright (c) 1997-2003 Miller Puckette. -* For information on usage and redistribution, and for a DISCLAIMER OF ALL -* WARRANTIES, see the file, "LICENSE.txt," in this distribution. - -iemlib2 written by Thomas Musil (c) IEM KUG Graz Austria 2000 - 2003 */ - -#ifdef NT -#pragma warning( disable : 4244 ) -#pragma warning( disable : 4305 ) -#endif - -#include "m_pd.h" -#include "iemlib.h" -#include -#include -#include -#include - -/* ---------------- modulo-counter. ----------------- */ - -static t_class *modulo_counter_class; - -typedef struct _modulo_counter -{ - t_object x_obj; - int x_max; - int x_cur; -} t_modulo_counter; - -static void modulo_counter_bang(t_modulo_counter *x) -{ - outlet_float(x->x_obj.ob_outlet, x->x_cur++); - x->x_cur = x->x_cur % x->x_max; -} - -static void modulo_counter_float(t_modulo_counter *x, t_float max) -{ - int i = (int)max; - - if(i < 1) - i = 1; - if(x->x_cur >= i) - x->x_cur = i - 1; - x->x_max = i; -} - -static void modulo_counter_ft1(t_modulo_counter *x, t_float set_init) -{ - int i = (int)set_init; - - if(i < 0) - i = 0; - if(i >= x->x_max) - i = x->x_max - 1; - x->x_cur = i; -} - -static void *modulo_counter_new(t_symbol *s, int ac, t_atom *av) -{ - t_modulo_counter *x = (t_modulo_counter *)pd_new(modulo_counter_class); - int max = 1, cur = 0; - - if((ac > 0) && IS_A_FLOAT(av, 0)) - max = atom_getintarg(0, ac, av); - if((ac > 1) && IS_A_FLOAT(av, 1)) - cur = atom_getintarg(1, ac, av); - if(max < 1) - x->x_max = 1; - else - x->x_max = max; - if(cur < 0) - cur = 0; - if(cur >= x->x_max) - cur = x->x_max - 1; - x->x_cur = cur; - outlet_new(&x->x_obj, &s_float); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); - return (x); -} - -void modulo_counter_setup(void) -{ - modulo_counter_class = class_new(gensym("modulo_counter"), - (t_newmethod)modulo_counter_new, 0, - sizeof(t_modulo_counter), 0, A_GIMME, 0); - class_addbang(modulo_counter_class, (t_method)modulo_counter_bang); - class_addfloat(modulo_counter_class, (t_method)modulo_counter_float); - class_addmethod(modulo_counter_class, (t_method)modulo_counter_ft1, gensym("ft1"), A_FLOAT, 0); - class_sethelpsymbol(modulo_counter_class, gensym("iemhelp/help-modulo_counter")); -} +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include +#include +#include +#include + +/* ---------------- modulo-counter. ----------------- */ +/* -------- counter increments if input a bang ------ */ +/* -------- output is a modulo function. ------------ */ + +static t_class *modulo_counter_class; + +typedef struct _modulo_counter +{ + t_object x_obj; + int x_max; + int x_cur; +} t_modulo_counter; + +static void modulo_counter_bang(t_modulo_counter *x) +{ + outlet_float(x->x_obj.ob_outlet, x->x_cur++); + x->x_cur = x->x_cur % x->x_max; +} + +static void modulo_counter_float(t_modulo_counter *x, t_float max) +{ + int i = (int)max; + + if(i < 1) + i = 1; + if(x->x_cur >= i) + x->x_cur = i - 1; + x->x_max = i; +} + +static void modulo_counter_ft1(t_modulo_counter *x, t_float set_init) +{ + int i = (int)set_init; + + if(i < 0) + i = 0; + if(i >= x->x_max) + i = x->x_max - 1; + x->x_cur = i; +} + +static void *modulo_counter_new(t_symbol *s, int ac, t_atom *av) +{ + t_modulo_counter *x = (t_modulo_counter *)pd_new(modulo_counter_class); + int max = 1, cur = 0; + + if((ac > 0) && IS_A_FLOAT(av, 0)) + max = atom_getintarg(0, ac, av); + if((ac > 1) && IS_A_FLOAT(av, 1)) + cur = atom_getintarg(1, ac, av); + if(max < 1) + x->x_max = 1; + else + x->x_max = max; + if(cur < 0) + cur = 0; + if(cur >= x->x_max) + cur = x->x_max - 1; + x->x_cur = cur; + outlet_new(&x->x_obj, &s_float); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); + return (x); +} + +void modulo_counter_setup(void) +{ + modulo_counter_class = class_new(gensym("modulo_counter"), + (t_newmethod)modulo_counter_new, 0, + sizeof(t_modulo_counter), 0, A_GIMME, 0); + class_addbang(modulo_counter_class, (t_method)modulo_counter_bang); + class_addfloat(modulo_counter_class, (t_method)modulo_counter_float); + class_addmethod(modulo_counter_class, (t_method)modulo_counter_ft1, gensym("ft1"), A_FLOAT, 0); + class_sethelpsymbol(modulo_counter_class, gensym("iemhelp/help-modulo_counter")); +} -- cgit v1.2.1