aboutsummaryrefslogtreecommitdiff
path: root/src/iemlib2/modulo_counter.c
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2004-05-18 21:33:33 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2004-05-18 21:33:33 +0000
commit577ac6e80ff4f436fbd054291ed7dddbc31bd49a (patch)
tree6ec69b216dda68d7de38a5eba1851b9d4f1431e6 /src/iemlib2/modulo_counter.c
This commit was generated by cvs2svn to compensate for changes in r1738,svn2git-root
which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/iemlib/; revision=1739
Diffstat (limited to 'src/iemlib2/modulo_counter.c')
-rw-r--r--src/iemlib2/modulo_counter.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/iemlib2/modulo_counter.c b/src/iemlib2/modulo_counter.c
new file mode 100644
index 0000000..3c072e2
--- /dev/null
+++ b/src/iemlib2/modulo_counter.c
@@ -0,0 +1,90 @@
+/* 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 <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+
+/* ---------------- 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"));
+}