diff options
Diffstat (limited to 'maskxor')
-rwxr-xr-x | maskxor/help-maskxor.pd | 39 | ||||
-rwxr-xr-x | maskxor/makefile | 105 | ||||
-rwxr-xr-x | maskxor/maskxor.c | 118 |
3 files changed, 262 insertions, 0 deletions
diff --git a/maskxor/help-maskxor.pd b/maskxor/help-maskxor.pd new file mode 100755 index 0000000..23fd1b7 --- /dev/null +++ b/maskxor/help-maskxor.pd @@ -0,0 +1,39 @@ +#N canvas 0 0 665 304 10; +#X obj 368 207 maskxor; +#X obj 457 63 t b b; +#X msg 38 157 bang; +#X floatatom 390 247 5 0 0 0 - - -; +#X floatatom 368 264 5 0 0 0 - - -; +#X floatatom 254 122 5 0 0 0 - - -; +#X msg 457 46 bang; +#X msg 457 80 listl 1 1 0 0 0 1 1; +#X msg 500 97 listr 0 1 1 0 2 1 0; +#X text 39 56 Maskxor takes two lists - listr and listl \, to set up +a map where map = listl ^ listr.; +#X text 37 93 Floats will only pass through if map[(int)float] > 0 +\, so if the corresponding element is greater than zero in either listl +\, or listr \, but not both.; +#X text 76 148 outputs the map \, the xor-ed element and (if this is +greater than zero) the last float in.; +#X obj 412 227 print MASK; +#X text 41 22 Maskxor - exclusive-OR mask map by Edward Kelly. This +is GNU software.; +#X msg 39 193 clear; +#X text 79 192 resets the object; +#X text 29 283 Polyphony control objects by Ed Kelly November 2006 +; +#X text 397 282 See also; +#X obj 458 280 sieve; +#X obj 501 280 polymap; +#X obj 558 280 polystat; +#X connect 0 0 4 0; +#X connect 0 1 3 0; +#X connect 0 2 12 0; +#X connect 1 0 7 0; +#X connect 1 1 8 0; +#X connect 2 0 0 0; +#X connect 5 0 0 0; +#X connect 6 0 1 0; +#X connect 7 0 0 0; +#X connect 8 0 0 0; +#X connect 14 0 0 0; diff --git a/maskxor/makefile b/maskxor/makefile new file mode 100755 index 0000000..950cfa2 --- /dev/null +++ b/maskxor/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: maskxor.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: maskxor.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: maskxor.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: maskxor.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: maskxor.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 maskxor.$(EXT) $(INSTALL_PREFIX)/lib/pd/extra + install -m 644 *.pd $(INSTALL_PREFIX)/lib/pd/doc/5.reference diff --git a/maskxor/maskxor.c b/maskxor/maskxor.c new file mode 100755 index 0000000..b75379f --- /dev/null +++ b/maskxor/maskxor.c @@ -0,0 +1,118 @@ +#include "m_pd.h" +#include <math.h> +#define MAXENTRIES 512 + +static t_class *maskxor_class; + +typedef struct _mask +{ + t_atom maskxor[MAXENTRIES]; + t_atom maskl[MAXENTRIES]; + t_atom maskr[MAXENTRIES]; +} t_mask; + +typedef struct _maskxor +{ + t_object x_obj; + t_mask masking; + t_float total; + t_float f_in, yes; + t_outlet *thru, *bool, *mask; +} t_maskxor; + +void maskxor_float(t_maskxor *x, t_floatarg fin) +{ + int input = (int)fin; + if(input>=0 && input<MAXENTRIES) + { + x->f_in = fin; + x->yes = atom_getfloatarg(input, MAXENTRIES, x->masking.maskxor); + outlet_float(x->bool, x->yes); + if(x->yes) outlet_float(x->thru, x->f_in); + } +} + +void maskxor_bang(t_maskxor *x, t_symbol *s) +{ + outlet_list(x->mask, &s_list, x->total, x->masking.maskxor); + outlet_float(x->bool, x->yes); + if(x->yes)outlet_float(x->thru, x->f_in); +} + +void maskxor_listl(t_maskxor *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + float listr_element, listl_element, xor_element; + if(x->total < argc && argc < MAXENTRIES) x->total = argc; + for(i=0;i<x->total;i++) + { + listl_element = atom_getfloat(argv+i); + SETFLOAT(&x->masking.maskl[i], listl_element); + listr_element = atom_getfloatarg(i,MAXENTRIES,x->masking.maskr); + xor_element = (float)((int)listl_element ^ (int)listr_element); + SETFLOAT(&x->masking.maskxor[i], xor_element); + } + outlet_list(x->mask, &s_list, x->total, x->masking.maskxor); +} + +void maskxor_listr(t_maskxor *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + float listr_element; + if(x->total < argc && argc < MAXENTRIES) + { + x->total = argc; + } + for(i=0;i<x->total;i++) + { + listr_element = atom_getfloat(argv+i); + SETFLOAT(&x->masking.maskr[i], listr_element); + } +} + +void maskxor_clear(t_maskxor *x) +{ + int i; + for(i=0;i<=MAXENTRIES;i++) + { + SETFLOAT(&x->masking.maskl[i], 0); + SETFLOAT(&x->masking.maskr[i], 0); + SETFLOAT(&x->masking.maskxor[i], 0); + } + x->total=1; + x->yes = x->f_in = 0; +} + +void *maskxor_new(t_symbol *s) +{ + int i; + t_maskxor *x = (t_maskxor *)pd_new(maskxor_class); + x->total = 1; + for(i=0;i<MAXENTRIES;i++) + { + SETFLOAT(&x->masking.maskr[i], 0); + SETFLOAT(&x->masking.maskl[i], 0); + SETFLOAT(&x->masking.maskxor[i], 0); + } + x->thru = outlet_new(&x->x_obj, &s_float); + x->bool = outlet_new(&x->x_obj, &s_float); + x->mask = outlet_new(&x->x_obj, &s_list); + return (void *)x; +} + +void maskxor_setup(void) +{ + maskxor_class = class_new(gensym("maskxor"), + (t_newmethod)maskxor_new, + 0, sizeof(t_maskxor), + CLASS_DEFAULT, A_DEFFLOAT, 0); + post("|..-.--.-..-maskxor.-...--.-..|"); + post("| exclusive-or mask-map |"); + post("|.--.- Edward Kelly 2006 ---.-|"); + class_sethelpsymbol(maskxor_class, gensym("help-maskxor")); + class_addfloat(maskxor_class, maskxor_float); + class_addmethod(maskxor_class, (t_method)maskxor_listl, gensym("listl"), A_GIMME, 0, 0); + class_addmethod(maskxor_class, (t_method)maskxor_listr, gensym("listr"), A_GIMME, 0, 0); + class_addbang(maskxor_class, (t_method)maskxor_bang); + class_addmethod(maskxor_class, (t_method)maskxor_clear, gensym("clear"), A_DEFFLOAT, 0); +} |