aboutsummaryrefslogtreecommitdiff
path: root/src/minmax.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
commit2b60d55c919e7588f5aff15936e83c300b3660bb (patch)
tree14d860de7f28083d3756ad91b627de70f26788f6 /src/minmax.c
parentc500bc542cb7cc78d6dac3f7da3bff626056b1aa (diff)
zexy-2.0:
- use of abstractions for objects that allow it - some objects are build both as externals and abstractions (as slower fallbacks) - code-layout is now 1:1 c-file<->object (this should allow for building of zexy as a collection of externals instead as a big library) - matrix-objects have moved to iemmatrix !! svn path=/trunk/externals/zexy/; revision=2641
Diffstat (limited to 'src/minmax.c')
-rw-r--r--src/minmax.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/minmax.c b/src/minmax.c
new file mode 100644
index 0000000..f96b025
--- /dev/null
+++ b/src/minmax.c
@@ -0,0 +1,84 @@
+/******************************************************
+ *
+ * zexy - implementation file
+ *
+ * copyleft (c) IOhannes m zmölnig
+ *
+ * 1999:forum::für::umläute:2004
+ *
+ * institute of electronic music and acoustics (iem)
+ *
+ ******************************************************
+ *
+ * license: GNU General Public License v.2
+ *
+ ******************************************************/
+
+#include "zexy.h"
+
+/* minmax :: get minimum and maximum of a list */
+
+static t_class *minmax_class;
+
+typedef struct _minmax
+{
+ t_object x_obj;
+ t_float min;
+ t_float max;
+
+ t_outlet *mino, *maxo;
+} t_minmax;
+
+static void minmax_bang(t_minmax *x)
+{
+ outlet_float(x->maxo,x->max);
+ outlet_float(x->mino,x->min);
+}
+
+static void minmax_list(t_minmax *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float min = atom_getfloat(argv++);
+ t_float max=min;
+ argc--;
+
+ while(argc--){
+ t_float f = atom_getfloat(argv++);
+ if (f<min)min=f;
+ else if (f>max)max=f;
+ }
+
+ x->min=min;
+ x->max=max;
+
+ minmax_bang(x);
+}
+
+static void *minmax_new(void)
+{
+ t_minmax *x = (t_minmax *)pd_new(minmax_class);
+
+ x->mino=outlet_new(&x->x_obj, gensym("float"));
+ x->maxo=outlet_new(&x->x_obj, gensym("float"));
+
+ x->min = x->max = 0;
+
+ return (x);
+}
+
+static void minmax_help(void)
+{
+ post("minmax\t:: get minimum and maximum of a list of floats");
+}
+
+void minmax_setup(void)
+{
+ minmax_class = class_new(gensym("minmax"), (t_newmethod)minmax_new, 0,
+ sizeof(t_minmax), 0, A_DEFFLOAT, 0);
+
+ class_addlist(minmax_class, (t_method)minmax_list);
+ class_addbang(minmax_class, (t_method)minmax_bang);
+ class_addmethod(minmax_class, (t_method)minmax_help, gensym("help"), 0);
+
+ class_sethelpsymbol(minmax_class, gensym("zexy/minmax"));
+ zexy_register("minmax");
+}