aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--valve/help-valve.pd34
-rw-r--r--valve/makefile105
-rw-r--r--valve/sieve.c285
-rw-r--r--valve/valve.c123
4 files changed, 547 insertions, 0 deletions
diff --git a/valve/help-valve.pd b/valve/help-valve.pd
new file mode 100644
index 0000000..d5c7cef
--- /dev/null
+++ b/valve/help-valve.pd
@@ -0,0 +1,34 @@
+#N canvas 0 0 450 300 10;
+#X obj 126 189 valve;
+#X msg 60 46 map 0 0 1 1 1 1 0 0;
+#X obj 21 82 loadbang;
+#X text 116 66 ^;
+#X text 116 68 |;
+#X text 116 78 |;
+#X text 116 88 |;
+#X text 116 98 |;
+#X msg 115 114 2;
+#X floatatom 103 233 5 0 0 0 - - -;
+#X floatatom 166 233 5 0 0 0 - - -;
+#X msg 194 104 4;
+#X text 145 66 ^;
+#X text 145 68 |;
+#X text 145 78 |;
+#X text 145 88 |;
+#X text 145 98 |;
+#X text 171 66 ^;
+#X text 171 68 |;
+#X text 171 68 |;
+#X text 171 78 |;
+#X text 171 78 |;
+#X text 175 78 _________;
+#X msg 240 82 6;
+#X text 149 98 ______;
+#X connect 0 0 9 0;
+#X connect 0 1 10 0;
+#X connect 1 0 0 0;
+#X connect 2 0 1 0;
+#X connect 2 0 8 0;
+#X connect 8 0 0 1;
+#X connect 11 0 0 0;
+#X connect 23 0 0 0;
diff --git a/valve/makefile b/valve/makefile
new file mode 100644
index 0000000..f6733a2
--- /dev/null
+++ b/valve/makefile
@@ -0,0 +1,105 @@
+current:
+ echo make pd_linux, pd_nt, pd_irix5, pd_irix6 or pd_darwin, then make install
+
+clean: ; rm -f *.pd_* *.o
+
+# ----------------------- NT -----------------------
+
+pd_nt: valve.dll
+
+INSTALL_PREFIX="C:\pd\extra"
+EXT=dll
+.SUFFIXES: .obj .dll
+
+PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo
+VC="D:\Program Files\Microsoft Visual Studio\Vc98"
+
+PDNTINCLUDE = /I. /I\tcl\include /I..\..\src /I$(VC)\include
+
+PDNTLDIR = $(VC)\lib
+PDNTLIB = $(PDNTLDIR)\libc.lib \
+ $(PDNTLDIR)\oldnames.lib \
+ $(PDNTLDIR)\kernel32.lib \
+ ..\..\bin\pd.lib
+
+.c.dll:
+ cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c
+ link /dll /export:$*_setup $*.obj $(PDNTLIB)
+
+# ----------------------- IRIX 5.x -----------------------
+
+pd_irix5: valve.pd_irix5
+
+INSTALL_PREFIX=/usr/local
+EXT=pd_irix5
+.SUFFIXES: .pd_irix5
+
+SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2
+
+SGIINCLUDE = -I/usr/local/include
+
+.c.pd_irix5:
+ cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c
+ ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o
+ rm $*.o
+
+# ----------------------- IRIX 5.x -----------------------
+
+pd_irix6: valve.pd_irix6
+
+INSTALL_PREFIX=/usr/local
+EXT=pd_irix6
+.SUFFIXES: .pd_irix6
+
+SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2
+
+SGIINCLUDE = -I/usr/local/include
+
+.c.pd_irix6:
+ cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c
+ ld -elf -shared -rdata_shared -o $*.pd_irix6 $*.o
+ rm $*.o
+
+# ----------------------- LINUX i386 -----------------------
+
+pd_linux: valve.pd_linux
+
+INSTALL_PREFIX=/usr/local
+EXT=pd_linux
+.SUFFIXES: .pd_linux
+
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
+ -Wall -W -Wshadow -Wstrict-prototypes -Werror \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+LINUXINCLUDE = -I/usr/local/include
+
+.c.pd_linux:
+ cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm
+ strip --strip-unneeded $*.pd_linux
+ rm $*.o
+
+# ----------------------- Mac OSX -----------------------
+
+pd_darwin: valve.pd_darwin
+
+INSTALL_PREFIX=/usr/local
+EXT=pd_darwin
+.SUFFIXES: .pd_darwin
+
+DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+.c.pd_darwin:
+ cc $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ cc -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o
+ rm -f $*.o
+
+# ----------------------------------------------
+
+install::
+ install -d $(INSTALL_PREFIX)/lib/pd/extra
+# install -m 644 *.$(EXT) $(INSTALL_PREFIX)/lib/pd/externs
+ -install -m 644 valve.$(EXT) $(INSTALL_PREFIX)/lib/pd/extra
+ install -m 644 *.pd $(INSTALL_PREFIX)/lib/pd/doc/5.reference
diff --git a/valve/sieve.c b/valve/sieve.c
new file mode 100644
index 0000000..cd6c7d5
--- /dev/null
+++ b/valve/sieve.c
@@ -0,0 +1,285 @@
+/* takes a map like 0 1 3 4 7 and only returns the number if it is present */
+/* in the map, or returns the closest, or the next up or down (wrapped)*/
+#include "m_pd.h"
+#include <math.h>
+#include <string.h>
+#define MAXENTRIES 512
+#define LASTENTRY 511
+
+static t_class *sieve_class;
+
+/* mode = 0 : block when absent, 1: nearest when absent, 2: shunt when absent */
+typedef struct _map
+{
+ t_atom map[MAXENTRIES];
+ t_atom nomap[MAXENTRIES];
+} t_map;
+
+typedef struct _sieve
+{
+ t_object x_obj;
+ t_map x_map;
+ t_float input, mode, max, outmap;
+ t_outlet *mapped, *value, *mapout, *inst;
+} t_sieve;
+
+void sieve_float(t_sieve *x, t_floatarg fin)
+{
+ int i, ip, in, arg, arga, argb, argaout, argbout, argxa, argxb, itest, itesta, itestb, iresult;
+ itest = itesta = itestb = iresult = arga = argb = arg = 0;
+ float test, testa, testb, fresult;
+ test = testa = testb = fresult = 0;
+ x->input = arg = fin;// < 0 ? 0 : fin > LASTENTRY ? LASTENTRY : (int)fin;
+ if (x->mode == 0)
+ {
+ test = fin < 0 ? 0 : atom_getfloatarg(arg, MAXENTRIES, x->x_map.map);
+ if(test!=0)
+ {
+ outlet_bang(x->inst);
+ outlet_float(x->value, test);
+ outlet_float(x->mapped, arg);
+ }
+ }
+ else if (x->mode == 1)
+ {
+ test = fin < 0 ? 0 : atom_getfloatarg(arg, MAXENTRIES, x->x_map.map);
+ if(test!=0)
+ {
+ outlet_bang(x->inst);
+ outlet_float(x->value, test);
+ outlet_float(x->mapped, arg);
+ }
+ else
+ {
+ arga = argb = arg;
+ while(itest == 0 && (arga > -1 || argb < MAXENTRIES))
+ {
+ arga--;
+ argb++;
+ argxa = arga >= 0 ? arga : 0;
+ argxb = argb <= LASTENTRY ? argb : LASTENTRY;
+ testa = atom_getfloatarg(argxa, MAXENTRIES, x->x_map.map);
+ testb = atom_getfloatarg(argxb, MAXENTRIES, x->x_map.map);
+ itesta = testa != 0 ? 1 : 0;
+ itestb = testb != 0 ? 1 : 0;
+ itest = fin < 0 ? 0 : itesta + itestb;
+ }
+ switch(itest)
+ {
+ case 2:
+ if (x->mode == 1)
+ {
+ outlet_float(x->value, testb);
+ outlet_float(x->mapped, argb);
+ }
+ else
+ {
+ outlet_float(x->value, testa);
+ outlet_float(x->mapped, arga);
+ }
+ case 1:
+ iresult = itesta == 1 ? arga : argb;
+ fresult = itesta == 1 ? testa : testb;
+ outlet_float(x->value, fresult);
+ outlet_float(x->mapped, iresult);
+ case 0:
+ break;
+ }
+ }
+ }
+ else if (x->mode==2)
+ {
+ itest = 0;
+ test = fin < 0 ? 0 : atom_getfloatarg(arg, MAXENTRIES, x->x_map.map);
+ if(test!=0)
+ {
+ outlet_bang(x->inst);
+ outlet_float(x->value, test);
+ outlet_float(x->mapped, arg);
+ }
+ else
+ {
+ arga = arg;
+ while(itest == 0 && (x->max > 0))
+ {
+ arga = (arga + 1) <= LASTENTRY ? (arga + 1) : 0;
+ testa = atom_getfloatarg(arga, MAXENTRIES, x->x_map.map);
+ itest = testa != 0 ? 1 : 0;
+ }
+ if(x->max > 0 && fin >= 0)
+ {
+ outlet_float(x->value, testa);
+ outlet_float(x->mapped, arga);
+ }
+ }
+ }
+ else if (x->mode == 3)
+ {
+ itest = 0;
+ test = fin < 0 ? 0 : atom_getfloatarg(arg, MAXENTRIES, x->x_map.map);
+ if(test!=0)
+ {
+ outlet_bang(x->inst);
+ outlet_float(x->value, test);
+ outlet_float(x->mapped, arg);
+ }
+ else
+ {
+ arga = arg;
+ while(itest == 0 && (x->max > 0))
+ {
+ argb = arga - 1;
+ arga = argb >= 0 ? argb : LASTENTRY;
+ testa = atom_getfloatarg(arga, MAXENTRIES, x->x_map.map);
+ itest = testa != 0 ? 1 : 0;
+ }
+ }
+ outlet_float(x->value, testa);
+ outlet_float(x->mapped, arga);
+ }
+}
+
+void sieve_set(t_sieve *x, t_floatarg fmap, t_floatarg fval)
+{
+ float fvaller;
+ if(fmap < MAXENTRIES && fmap >= 0)
+ {
+ int imap = (int)fmap;
+ fvaller = fval != 0 ? 0 : 1;
+ SETFLOAT(&x->x_map.map[imap], fval);
+ SETFLOAT(&x->x_map.nomap[imap], fvaller);
+ x->max = fmap > x->max ? fmap : x->max;
+ }
+}
+
+void sieve_get(t_sieve *x, t_floatarg inv)
+{
+ if(inv!=0)
+ {
+ outlet_list(x->mapout, gensym("list"), x->max+1, x->x_map.nomap);
+ }
+ else outlet_list(x->mapout, gensym("list"), x->max+1, x->x_map.map);
+ x->outmap = inv;
+}
+
+void sieve_clear(t_sieve *x)
+{
+ //memset(x->x_map.map, 0, MAXENTRIES);
+ int i;
+ for(i=0;i<MAXENTRIES;i++)
+ {
+ SETFLOAT(&x->x_map.map[i], 0);
+ SETFLOAT(&x->x_map.nomap[i], 1);
+ }
+ //memset(x->x_map.nomap, 1, MAXENTRIES);
+ x->max = 0;
+}
+
+void sieve_map(t_sieve *x, t_symbol *s, int argc, t_atom *argv)
+{
+ //memset(x->x_map.map, 0, MAXENTRIES);
+ //memset(x->x_map.nomap, 1, MAXENTRIES);
+ int i;
+ for(i=0;i<MAXENTRIES;i++)
+ {
+ SETFLOAT(x->x_map.map+i, 0);
+ SETFLOAT(x->x_map.nomap+i, 1);
+ }
+ x->max = 0;
+ float arg;
+ for(i=0;i<argc;i++)
+ {
+ arg = atom_getfloat(argv+i);
+ if(arg != 0)
+ {
+ SETFLOAT(&x->x_map.map[i], arg);
+ SETFLOAT(&x->x_map.nomap[i], 0);
+ x->max = i;
+ }
+ }
+ if (x->max > 0 && x->outmap == 0)
+ {
+ outlet_list(x->mapout, gensym("list"), x->max+1, x->x_map.map);
+ }
+ else if (x->max > 0 && x->outmap == 1)
+ {
+ outlet_list(x->mapout, gensym("list"), x->max+1, x->x_map.nomap);
+ }
+}
+
+void sieve_mode(t_sieve *x, t_floatarg fmode)
+{
+ x->mode = fmode < 0 ? 0 : fmode > 3 ? 3 : fmode;
+}
+
+void sieve_debug(t_sieve *x)
+{
+ float ele0, ele1, ele2, ele3, ele4, ele5, ele6, ele7, ele8, ele9;
+ float nle0, nle1, nle2, nle3, nle4, nle5, nle6, nle7, nle8, nle9;
+ ele0 = atom_getfloatarg(0, MAXENTRIES, x->x_map.map);
+ ele1 = atom_getfloatarg(1, MAXENTRIES, x->x_map.map);
+ ele2 = atom_getfloatarg(2, MAXENTRIES, x->x_map.map);
+ ele3 = atom_getfloatarg(3, MAXENTRIES, x->x_map.map);
+ ele4 = atom_getfloatarg(4, MAXENTRIES, x->x_map.map);
+ ele5 = atom_getfloatarg(5, MAXENTRIES, x->x_map.map);
+ ele6 = atom_getfloatarg(6, MAXENTRIES, x->x_map.map);
+ ele7 = atom_getfloatarg(7, MAXENTRIES, x->x_map.map);
+ ele8 = atom_getfloatarg(8, MAXENTRIES, x->x_map.map);
+ ele9 = atom_getfloatarg(9, MAXENTRIES, x->x_map.map);
+ nle0 = atom_getfloatarg(0, MAXENTRIES, x->x_map.nomap);
+ nle1 = atom_getfloatarg(1, MAXENTRIES, x->x_map.nomap);
+ nle2 = atom_getfloatarg(2, MAXENTRIES, x->x_map.nomap);
+ nle3 = atom_getfloatarg(3, MAXENTRIES, x->x_map.nomap);
+ nle4 = atom_getfloatarg(4, MAXENTRIES, x->x_map.nomap);
+ nle5 = atom_getfloatarg(5, MAXENTRIES, x->x_map.nomap);
+ nle6 = atom_getfloatarg(6, MAXENTRIES, x->x_map.nomap);
+ nle7 = atom_getfloatarg(7, MAXENTRIES, x->x_map.nomap);
+ nle8 = atom_getfloatarg(8, MAXENTRIES, x->x_map.nomap);
+ nle9 = atom_getfloatarg(9, MAXENTRIES, x->x_map.nomap);
+ /* post("blocksize = %d, scales = %d, vectorsize = %d, offset = %d",
+ x->N, x->scales, x->vecsize, x->offset); */
+ post("mode = %d, max = %d", x->mode, x->max);
+ post("first 10 elements = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d", ele0, ele1, ele2, ele3, ele4, ele5, ele6, ele7, ele8, ele9);
+ post("first 10 elements = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d", nle0, nle1, nle2, nle3, nle4, nle5, nle6, nle7, nle8, nle9);
+}
+
+void *sieve_new(t_floatarg f)
+{
+ t_sieve *x = (t_sieve *)pd_new(sieve_class);
+ x->mode = f;
+ x->max = 0;
+ x->outmap = 0;
+ //memset(x->x_map.map, 0, MAXENTRIES);
+ //memset(x->x_map.nomap, 1, MAXENTRIES);
+ int i;
+ for(i=0;i<MAXENTRIES;i++)
+ {
+ SETFLOAT(x->x_map.map+i, 0);
+ SETFLOAT(x->x_map.nomap+i, 1);
+ }
+ x->mapped = outlet_new(&x->x_obj, &s_float);
+ x->value = outlet_new(&x->x_obj, &s_float);
+ x->mapout = outlet_new(&x->x_obj, &s_list);
+ x->inst = outlet_new(&x->x_obj, &s_bang);
+ return (void *)x;
+}
+
+void sieve_setup(void)
+{
+
+ sieve_class = class_new(gensym("sieve"),
+ (t_newmethod)sieve_new,
+ 0, sizeof(t_sieve),
+ 0, A_DEFFLOAT, 0);
+ post("|^^^^^^^^^^^^^sieve^^^^^^^^^^^^^|");
+ post("|->^^^integer map to floats^^^<-|");
+ post("|^^^^^^^Edward Kelly 2006^^^^^^^|");
+ class_sethelpsymbol(sieve_class, gensym("help-sieve"));
+ class_addfloat(sieve_class, sieve_float);
+ class_addmethod(sieve_class, (t_method)sieve_set, gensym("set"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(sieve_class, (t_method)sieve_map, gensym("map"), A_GIMME, 0);
+ class_addmethod(sieve_class, (t_method)sieve_clear, gensym("clear"), A_DEFFLOAT, 0);
+ class_addmethod(sieve_class, (t_method)sieve_get, gensym("get"), A_DEFFLOAT, 0);
+ class_addmethod(sieve_class, (t_method)sieve_mode, gensym("mode"), A_DEFFLOAT, 0);
+ class_addmethod(sieve_class, (t_method)sieve_debug, gensym("debug"), A_DEFFLOAT, 0);
+}
diff --git a/valve/valve.c b/valve/valve.c
new file mode 100644
index 0000000..5762201
--- /dev/null
+++ b/valve/valve.c
@@ -0,0 +1,123 @@
+/* takes a map like 0 1 3 4 7 and a route. if the route and the input are */
+/* non-zero in the map, then the route is output from the object */
+#include "m_pd.h"
+#include <math.h>
+#include <string.h>
+#define MAXENTRIES 512
+#define LASTENTRY 511
+
+static t_class *valve_class;
+
+typedef struct _valve
+{
+ t_object x_obj;
+
+ t_atom *map;
+ int bufsize;
+
+ t_float input, router, max;
+ t_outlet *routed, *notrouted;
+
+ int flush;
+} t_valve;
+
+static void valve_map(t_valve *x, t_symbol *s, int n, t_atom *map)
+{
+ if (x->map) {
+ freebytes(x->map, x->bufsize * sizeof(t_atom));
+ x->map = 0;
+ x->bufsize = 0;
+ }
+
+ x->map = copybytes(map, n * sizeof(t_atom));
+ x->bufsize = n;
+}
+
+void valve_float(t_valve *x, t_floatarg fin)
+{
+ if (x->map) {
+ int arg, arga, argb;
+ arga = argb = 0;
+ float testa, testb;
+ testa = testb = 0;
+ x->input = fin;
+ arg = (int)x->input;
+ testa = fin < 0 ? 0 : atom_getfloatarg(arg, x->bufsize, x->map);
+ testb = x->router < 0 ? 0 : atom_getfloatarg(x->router, x->bufsize, x->map);
+ arga = (int)testa;
+ argb = (int)testb;
+ if(arga && argb)
+ {
+ outlet_float(x->routed, x->router);
+ }
+ else if (!argb)
+ {
+ outlet_float(x->notrouted, argb);
+ }
+ else if (!arga && argb)
+ {
+ outlet_float(x->notrouted, arga);
+ }
+ }
+}
+
+void valve_set(t_valve *x, t_floatarg fmap, t_floatarg fval)
+{
+ if(fmap < x->bufsize && fmap >= 0)
+ {
+ int imap = (int)fmap;
+ SETFLOAT(&x->map[imap], fval);
+ x->max = fmap > x->max ? fmap : x->max;
+ }
+}
+
+void valve_clear(t_valve *x)
+{
+ if (x->map) {
+ freebytes(x->map, x->bufsize * sizeof(t_atom));
+ x->map = 0;
+ x->bufsize = 0;
+ }
+}
+
+void valve_debug(t_valve *x)
+{
+ int i;
+ for(i=0;i<x->bufsize;i++) {
+ float element = atom_getfloatarg(i, x->bufsize, x->map);
+ post("element %d = %d", i, element);
+ }
+ post("max = %d", x->max);
+}
+
+void *valve_new(t_floatarg f)
+{
+ t_valve *x = (t_valve *)pd_new(valve_class);
+ x->max = 0;
+ int i;
+ x->map = 0;
+ x->bufsize = 0;
+
+ floatinlet_new(&x->x_obj, &x->router);
+
+ x->routed = outlet_new(&x->x_obj, &s_float);
+ x->notrouted = outlet_new(&x->x_obj, &s_float);
+ return (void *)x;
+}
+
+void valve_setup(void)
+{
+ valve_class = class_new(gensym("valve"),
+ (t_newmethod)valve_new,
+ 0, sizeof(t_valve),
+ 0, A_DEFFLOAT, 0);
+ post("|¬~¬~¬~¬~¬~¬valve~¬~¬~¬~¬~¬~¬|");
+ post("|~>^^^integer map router^^^<¬|");
+ post("|¬~¬~¬Edward Kelly 2007~¬~¬~¬|");
+ class_sethelpsymbol(valve_class, gensym("help-valve"));
+ class_addfloat(valve_class, valve_float);
+ class_addmethod(valve_class, (t_method)valve_set, gensym("set"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(valve_class, (t_method)valve_map, gensym("map"), A_GIMME, 0);
+ class_addmethod(valve_class, (t_method)valve_clear, gensym("clear"), A_DEFFLOAT, 0);
+ class_addmethod(valve_class, (t_method)valve_debug, gensym("debug"), A_DEFFLOAT, 0);
+}