aboutsummaryrefslogtreecommitdiff
path: root/desiredata/doc/6.externs
diff options
context:
space:
mode:
Diffstat (limited to 'desiredata/doc/6.externs')
-rw-r--r--desiredata/doc/6.externs/0.README.txt9
-rw-r--r--desiredata/doc/6.externs/dspobj~.c67
-rw-r--r--desiredata/doc/6.externs/makefile82
-rw-r--r--desiredata/doc/6.externs/obj1.c47
-rw-r--r--desiredata/doc/6.externs/obj2.c45
-rw-r--r--desiredata/doc/6.externs/obj3.c39
-rw-r--r--desiredata/doc/6.externs/obj4.c47
-rw-r--r--desiredata/doc/6.externs/obj5.c54
-rw-r--r--desiredata/doc/6.externs/test-dspobj~.pd11
-rw-r--r--desiredata/doc/6.externs/test-obj1.pd6
-rw-r--r--desiredata/doc/6.externs/test-obj2.pd8
-rw-r--r--desiredata/doc/6.externs/test-obj3.pd8
-rw-r--r--desiredata/doc/6.externs/test-obj4.pd6
-rw-r--r--desiredata/doc/6.externs/test-obj5.pd4
14 files changed, 433 insertions, 0 deletions
diff --git a/desiredata/doc/6.externs/0.README.txt b/desiredata/doc/6.externs/0.README.txt
new file mode 100644
index 00000000..3b130116
--- /dev/null
+++ b/desiredata/doc/6.externs/0.README.txt
@@ -0,0 +1,9 @@
+EXTERNAL OBJECTS in Pd.
+
+Here are the sources for three simple external objects in Pd.
+To compile, type "make pd_linux", "nmake pd_nt", "make pd_irix5" or "make
+pd_irix6".
+
+The objects "foo1" and "foo2" are intended as very simple control objects, and
+"dspobj" is a tilde object.
+
diff --git a/desiredata/doc/6.externs/dspobj~.c b/desiredata/doc/6.externs/dspobj~.c
new file mode 100644
index 00000000..5c3fa86b
--- /dev/null
+++ b/desiredata/doc/6.externs/dspobj~.c
@@ -0,0 +1,67 @@
+#include "m_pd.h"
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ dspobj~ ----------------------------- */
+
+/* tilde object to take absolute value. */
+
+static t_class *dspobj_class;
+
+typedef struct _dspobj
+{
+ t_object x_obj; /* obligatory header */
+ t_float x_f; /* place to hold inlet's value if it's set by message */
+} t_dspobj;
+
+ /* this is the actual performance routine which acts on the samples.
+ It's called with a single pointer "w" which is our location in the
+ DSP call list. We return a new "w" which will point to the next item
+ after us. Meanwhile, w[0] is just a pointer to dsp-perform itself
+ (no use to us), w[1] and w[2] are the input and output vector locations,
+ and w[3] is the number of points to calculate. */
+static t_int *dspobj_perform(t_int *w)
+{
+ t_float *in = (t_float *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ int n = (int)(w[3]);
+ while (n--)
+ {
+ float f = *(in++);
+ *out++ = (f > 0 ? f : -f);
+ }
+ return (w+4);
+}
+
+ /* called to start DSP. Here we call Pd back to add our perform
+ routine to a linear callback list which Pd in turn calls to grind
+ out the samples. */
+static void dspobj_dsp(t_dspobj *x, t_signal **sp)
+{
+ dsp_add(dspobj_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+static void *dspobj_new(void)
+{
+ t_dspobj *x = (t_dspobj *)pd_new(dspobj_class);
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_f = 0;
+ return (x);
+}
+
+ /* this routine, which must have exactly this name (with the "~" replaced
+ by "_tilde) is called when the code is first loaded, and tells Pd how
+ to build the "class". */
+void dspobj_tilde_setup(void)
+{
+ dspobj_class = class_new(gensym("dspobj~"), (t_newmethod)dspobj_new, 0,
+ sizeof(t_dspobj), 0, A_DEFFLOAT, 0);
+ /* this is magic to declare that the leftmost, "main" inlet
+ takes signals; other signal inlets are done differently... */
+ CLASS_MAINSIGNALIN(dspobj_class, t_dspobj, x_f);
+ /* here we tell Pd about the "dsp" method, which is called back
+ when DSP is turned on. */
+ class_addmethod(dspobj_class, (t_method)dspobj_dsp, gensym("dsp"), 0);
+}
diff --git a/desiredata/doc/6.externs/makefile b/desiredata/doc/6.externs/makefile
new file mode 100644
index 00000000..8a5657fe
--- /dev/null
+++ b/desiredata/doc/6.externs/makefile
@@ -0,0 +1,82 @@
+current:
+ echo make pd_linux, pd_nt, pd_irix5, or pd_irix6
+
+clean: ; rm -f *.pd_linux *.o
+
+# ----------------------- NT -----------------------
+
+pd_nt: obj1.dll obj2.dll obj3.dll obj4.dll obj5.dll dspobj~.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)
+
+# override explicitly for tilde objects like this:
+dspobj~.dll: dspobj~.c;
+ cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c
+ link /dll /export:dspobj_tilde_setup $*.obj $(PDNTLIB)
+
+# ----------------------- IRIX 5.x -----------------------
+
+pd_irix5: obj1.pd_irix5 obj2.pd_irix5 \
+ obj3.pd_irix5 obj4.pd_irix5 obj5.pd_irix5 dspobj~.pd_irix5
+
+.SUFFIXES: .pd_irix5
+
+SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2
+
+
+SGIINCLUDE = -I../../src/
+
+.c.pd_irix5:
+ cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c
+ ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o
+ rm $*.o
+
+# ----------------------- LINUX i386 -----------------------
+
+pd_linux: obj1.pd_linux obj2.pd_linux obj3.pd_linux obj4.pd_linux \
+ obj5.pd_linux dspobj~.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../../src
+
+.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: obj1.pd_darwin obj2.pd_darwin \
+ obj3.pd_darwin obj4.pd_darwin obj5.pd_darwin dspobj~.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
+
diff --git a/desiredata/doc/6.externs/obj1.c b/desiredata/doc/6.externs/obj1.c
new file mode 100644
index 00000000..0618d646
--- /dev/null
+++ b/desiredata/doc/6.externs/obj1.c
@@ -0,0 +1,47 @@
+/* code for "obj1" pd class. This takes two messages: floating-point
+numbers, and "rats", and just prints something out for each message. */
+
+#include "m_pd.h"
+
+ /* the data structure for each copy of "obj1". In this case we
+ on;y need pd's obligatory header (of type t_object). */
+typedef struct obj1
+{
+ t_object x_ob;
+} t_obj1;
+
+ /* this is called back when obj1 gets a "float" message (i.e., a
+ number.) */
+void obj1_float(t_obj1 *x, t_floatarg f)
+{
+ post("obj1: %f", f);
+}
+
+ /* this is called when obj1 gets the message, "rats". */
+void obj1_rats(t_obj1 *x)
+{
+ post("obj1: rats");
+}
+
+ /* this is a pointer to the class for "obj1", which is created in the
+ "setup" routine below and used to create new ones in the "new" routine. */
+t_class *obj1_class;
+
+ /* this is called when a new "obj1" object is created. */
+void *obj1_new(void)
+{
+ t_obj1 *x = (t_obj1 *)pd_new(obj1_class);
+ post("obj1_new");
+ return (void *)x;
+}
+
+ /* this is called once at setup time, when this code is loaded into Pd. */
+void obj1_setup(void)
+{
+ post("obj1_setup");
+ obj1_class = class_new(gensym("obj1"), (t_newmethod)obj1_new, 0,
+ sizeof(t_obj1), 0, 0);
+ class_addmethod(obj1_class, (t_method)obj1_rats, gensym("rats"), 0);
+ class_addfloat(obj1_class, obj1_float);
+}
+
diff --git a/desiredata/doc/6.externs/obj2.c b/desiredata/doc/6.externs/obj2.c
new file mode 100644
index 00000000..14cd134a
--- /dev/null
+++ b/desiredata/doc/6.externs/obj2.c
@@ -0,0 +1,45 @@
+/* code for the "obj2" pd class. This one, in addition to the "obj1"
+code, has an inlet taking numbers. */
+
+#include "m_pd.h"
+
+typedef struct obj2
+{
+ t_object x_ob;
+} t_obj2;
+
+void obj2_float(t_obj2 *x, t_floatarg f)
+{
+ post("obj2: %f", f);
+}
+
+void obj2_rats(t_obj2 *x)
+{
+ post("obj2: rats");
+}
+
+void obj2_ft1(t_obj2 *x, t_floatarg g)
+{
+ post("ft1: %f", g);
+}
+
+t_class *obj2_class;
+
+void *obj2_new(void)
+{
+ t_obj2 *x = (t_obj2 *)pd_new(obj2_class);
+ inlet_new(&x->x_ob, &x->x_ob.ob_pd, gensym("float"), gensym("ft1"));
+ post("obj2_new");
+ return (void *)x;
+}
+
+void obj2_setup(void)
+{
+ post("obj2_setup");
+ obj2_class = class_new(gensym("obj2"), (t_newmethod)obj2_new,
+ 0, sizeof(t_obj2), 0, 0);
+ class_addmethod(obj2_class, (t_method)obj2_rats, gensym("rats"), 0);
+ class_addmethod(obj2_class, (t_method)obj2_ft1, gensym("ft1"), A_FLOAT, 0);
+ class_addfloat(obj2_class, obj2_float);
+}
+
diff --git a/desiredata/doc/6.externs/obj3.c b/desiredata/doc/6.externs/obj3.c
new file mode 100644
index 00000000..434fbb95
--- /dev/null
+++ b/desiredata/doc/6.externs/obj3.c
@@ -0,0 +1,39 @@
+/* code for the "obj3" pd class. This adds an outlet and a state variable. */
+
+#include "m_pd.h"
+
+typedef struct obj3
+{
+ t_object x_ob;
+ t_outlet *x_outlet;
+ float x_value;
+} t_obj3;
+
+void obj3_float(t_obj3 *x, t_floatarg f)
+{
+ outlet_float(x->x_outlet, f + x->x_value);
+}
+
+void obj3_ft1(t_obj3 *x, t_floatarg g)
+{
+ x->x_value = g;
+}
+
+t_class *obj3_class;
+
+void *obj3_new(void)
+{
+ t_obj3 *x = (t_obj3 *)pd_new(obj3_class);
+ inlet_new(&x->x_ob, &x->x_ob.ob_pd, gensym("float"), gensym("ft1"));
+ x->x_outlet = outlet_new(&x->x_ob, gensym("float"));
+ return (void *)x;
+}
+
+void obj3_setup(void)
+{
+ obj3_class = class_new(gensym("obj3"), (t_newmethod)obj3_new,
+ 0, sizeof(t_obj3), 0, 0);
+ class_addmethod(obj3_class, (t_method)obj3_ft1, gensym("ft1"), A_FLOAT, 0);
+ class_addfloat(obj3_class, obj3_float);
+}
+
diff --git a/desiredata/doc/6.externs/obj4.c b/desiredata/doc/6.externs/obj4.c
new file mode 100644
index 00000000..3da2a84a
--- /dev/null
+++ b/desiredata/doc/6.externs/obj4.c
@@ -0,0 +1,47 @@
+/* code for the "obj4" pd class. This adds a creation argument, of
+type "float". */
+
+#include "m_pd.h"
+
+typedef struct obj4
+{
+ t_object x_ob;
+ t_outlet *x_outlet;
+ float x_value;
+} t_obj4;
+
+void obj4_float(t_obj4 *x, t_floatarg f)
+{
+ outlet_float(x->x_outlet, x->x_value + f);
+}
+
+void obj4_ft1(t_obj4 *x, t_floatarg g)
+{
+ x->x_value = g;
+}
+
+t_class *obj4_class;
+
+ /* as requested by the new invocation of "class_new" below, the new
+ routine will be called with a "float" argument. */
+void *obj4_new(t_floatarg f)
+{
+ t_obj4 *x = (t_obj4 *)pd_new(obj4_class);
+ inlet_new(&x->x_ob, &x->x_ob.ob_pd, gensym("float"), gensym("ft1"));
+ x->x_outlet = outlet_new(&x->x_ob, gensym("float"));
+ /* just stick the argument in the object structure for later. */
+ x->x_value = f;
+ return (void *)x;
+}
+
+void obj4_setup(void)
+{
+ /* here we add "A_DEFFLOAT" to the (zero-terminated) list of arg
+ types we declare for a new object. The value will be filled
+ in as 0 if not given in the object box. */
+ obj4_class = class_new(gensym("obj4"), (t_newmethod)obj4_new,
+ 0, sizeof(t_obj4), 0, A_DEFFLOAT, 0);
+ class_addmethod(obj4_class, (t_method)obj4_ft1, gensym("ft1"), A_FLOAT, 0);
+ class_addfloat(obj4_class, obj4_float);
+}
+
diff --git a/desiredata/doc/6.externs/obj5.c b/desiredata/doc/6.externs/obj5.c
new file mode 100644
index 00000000..687c8e0a
--- /dev/null
+++ b/desiredata/doc/6.externs/obj5.c
@@ -0,0 +1,54 @@
+/* code for the "obj5" pd class. This shows "gimme" arguments, which have
+variable arguments parsed by the routines (both "new" and "rats".) */
+
+#include "m_pd.h"
+
+typedef struct obj5
+{
+ t_object x_ob;
+} t_obj5;
+
+ /* the "rats" method is called with the selector (just "rats" again)
+ and an array of the typed areguments, which are each either a number
+ or a symbol. We just print them out. */
+void obj5_rats(t_obj5 *x, t_symbol *selector, int argcount, t_atom *argvec)
+{
+ int i;
+ post("rats: selector %s", selector->s_name);
+ for (i = 0; i < argcount; i++)
+ {
+ if (argvec[i].a_type == A_FLOAT)
+ post("float: %f", argvec[i].a_w.w_float);
+ else if (argvec[i].a_type == A_SYMBOL)
+ post("symbol: %s", argvec[i].a_w.w_symbol->s_name);
+ }
+}
+
+t_class *obj5_class;
+
+ /* same for the "new" (creation) routine, except that we don't have
+ "x" as an argument since we have to create "x" in this routine. */
+void *obj5_new(t_symbol *selector, int argcount, t_atom *argvec)
+{
+ t_obj5 *x = (t_obj5 *)pd_new(obj5_class);
+ int i;
+ post("new: selector %s", selector->s_name);
+ for (i = 0; i < argcount; i++)
+ {
+ if (argvec[i].a_type == A_FLOAT)
+ post("float: %f", argvec[i].a_w.w_float);
+ else if (argvec[i].a_type == A_SYMBOL)
+ post("symbol: %s", argvec[i].a_w.w_symbol->s_name);
+ }
+ return (void *)x;
+}
+
+void obj5_setup(void)
+{
+ /* We specify "A_GIMME" as creation argument for both the creation
+ routine and the method (callback) for the "rats" message. */
+ obj5_class = class_new(gensym("obj5"), (t_newmethod)obj5_new,
+ 0, sizeof(t_obj5), 0, A_GIMME, 0);
+ class_addmethod(obj5_class, (t_method)obj5_rats, gensym("rats"), A_GIMME, 0);
+}
+
diff --git a/desiredata/doc/6.externs/test-dspobj~.pd b/desiredata/doc/6.externs/test-dspobj~.pd
new file mode 100644
index 00000000..4d1030b3
--- /dev/null
+++ b/desiredata/doc/6.externs/test-dspobj~.pd
@@ -0,0 +1,11 @@
+#N canvas 0 0 335 239 10;
+#X obj 90 124 dspobj~;
+#X obj 90 96 sig~ 0;
+#X msg 106 149 bang;
+#X obj 90 177 print~;
+#X floatatom 89 71;
+#X msg 202 37 \; pd dsp 1;
+#X connect 0 0 3 0;
+#X connect 1 0 0 0;
+#X connect 2 0 3 0;
+#X connect 4 0 1 0;
diff --git a/desiredata/doc/6.externs/test-obj1.pd b/desiredata/doc/6.externs/test-obj1.pd
new file mode 100644
index 00000000..f50ce449
--- /dev/null
+++ b/desiredata/doc/6.externs/test-obj1.pd
@@ -0,0 +1,6 @@
+#N canvas 68 38 317 151 12;
+#X msg 68 52 5;
+#X msg 100 52 rats;
+#X obj 67 90 obj1;
+#X connect 0 0 2 0;
+#X connect 1 0 2 0;
diff --git a/desiredata/doc/6.externs/test-obj2.pd b/desiredata/doc/6.externs/test-obj2.pd
new file mode 100644
index 00000000..1d3fd191
--- /dev/null
+++ b/desiredata/doc/6.externs/test-obj2.pd
@@ -0,0 +1,8 @@
+#N canvas 62 333 310 157 12;
+#X msg 109 51 rats;
+#X msg 157 52 7;
+#X msg 68 52 4;
+#X obj 68 90 obj2;
+#X connect 0 0 3 0;
+#X connect 1 0 3 1;
+#X connect 2 0 3 0;
diff --git a/desiredata/doc/6.externs/test-obj3.pd b/desiredata/doc/6.externs/test-obj3.pd
new file mode 100644
index 00000000..1072a4af
--- /dev/null
+++ b/desiredata/doc/6.externs/test-obj3.pd
@@ -0,0 +1,8 @@
+#N canvas 128 288 310 157 12;
+#X obj 68 91 obj3;
+#X floatatom 67 61 3 0 0 0 - - -;
+#X floatatom 108 59 3 0 0 0 - - -;
+#X floatatom 70 118 3 0 0 0 - - -;
+#X connect 0 0 3 0;
+#X connect 1 0 0 0;
+#X connect 2 0 0 1;
diff --git a/desiredata/doc/6.externs/test-obj4.pd b/desiredata/doc/6.externs/test-obj4.pd
new file mode 100644
index 00000000..619012f5
--- /dev/null
+++ b/desiredata/doc/6.externs/test-obj4.pd
@@ -0,0 +1,6 @@
+#N canvas 128 288 310 157 12;
+#X floatatom 67 61 3 0 0 0 - - -;
+#X floatatom 70 118 3 0 0 0 - - -;
+#X obj 68 91 obj4 34;
+#X connect 0 0 2 0;
+#X connect 2 0 1 0;
diff --git a/desiredata/doc/6.externs/test-obj5.pd b/desiredata/doc/6.externs/test-obj5.pd
new file mode 100644
index 00000000..550f34a1
--- /dev/null
+++ b/desiredata/doc/6.externs/test-obj5.pd
@@ -0,0 +1,4 @@
+#N canvas 128 288 310 157 12;
+#X obj 15 74 obj5 1 2 3 cis boom bah;
+#X msg 15 30 rats 4 5 6 tara tara boum boum;
+#X connect 1 0 0 0;