aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/accum~-help.pd42
-rw-r--r--test/accum~.c239
-rw-r--r--test/count.c145
-rw-r--r--test/dial.c792
-rw-r--r--test/frameaccum.c71
-rw-r--r--test/from_ascii_code-help.pd19
-rw-r--r--test/from_ascii_code.c111
-rw-r--r--test/imagebutton.c415
-rw-r--r--test/pak.c379
-rw-r--r--test/test.c97
-rw-r--r--test/to_ascii_code-help.pd13
-rw-r--r--test/to_ascii_code.c97
-rw-r--r--test/tokenArgs.c80
13 files changed, 1152 insertions, 1348 deletions
diff --git a/test/accum~-help.pd b/test/accum~-help.pd
new file mode 100644
index 0000000..a6706d3
--- /dev/null
+++ b/test/accum~-help.pd
@@ -0,0 +1,42 @@
+#N canvas 1084 142 863 682 10;
+#X obj 14 14 cnv 15 400 40 empty empty empty 20 12 0 14 -260097 -66577
+0;
+#X msg 68 105 stop;
+#X msg 40 78 bang;
+#X floatatom 38 494 15 0 0 0 - - -;
+#X text 152 492 samples counted;
+#X floatatom 121 353 5 0 0 0 - - -;
+#X floatatom 80 332 5 0 0 0 - - -;
+#X obj 106 217 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X msg 106 242 autoreset \$1;
+#X text 30 22 description: sample accumulator;
+#X text 79 79 start accumulating;
+#X text 131 218 reset accumulation to min if dsp is turned off and
+on again;
+#X obj 92 160 sig~ 1;
+#X obj 38 464 cyclone/Snapshot~ 100;
+#X obj 162 377 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X text 183 373 wrap to min/max;
+#X floatatom 92 138 5 0 0 0 - - -;
+#X text 107 106 stop \, and reset to min;
+#X text 126 331 set a min value;
+#X text 164 353 set a max value;
+#X text 135 158 Accumulation amount;
+#X text 173 401 arguments: min max wrap autoreset;
+#X obj 435 15 loadbang;
+#X msg 435 40 \; pd dsp 1;
+#X obj 39 402 tof/accum~ 0 441000 1;
+#X connect 1 0 24 0;
+#X connect 2 0 24 0;
+#X connect 5 0 24 2;
+#X connect 6 0 24 1;
+#X connect 7 0 8 0;
+#X connect 8 0 24 0;
+#X connect 12 0 24 0;
+#X connect 13 0 3 0;
+#X connect 14 0 24 3;
+#X connect 16 0 12 0;
+#X connect 22 0 23 0;
+#X connect 24 0 13 0;
diff --git a/test/accum~.c b/test/accum~.c
new file mode 100644
index 0000000..487a54a
--- /dev/null
+++ b/test/accum~.c
@@ -0,0 +1,239 @@
+
+
+
+/* [accum~] by Thomas Ouellet Fredericks
+ * License: If you use and die, it's not my fault
+ * Based on [count~] (sickle/count.c)
+ * Copyright (c) 2002-2003 krzYszcz and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+*/
+
+#include "m_pd.h"
+#include <math.h>
+
+/* TODO
+- Maybe add a pause?
+*/
+
+typedef struct _accum_tilde
+{
+ t_object x_obj;
+ t_float f;
+ t_float min;
+ t_float max;
+ int wrap;
+ //int limit;
+ int on;
+ int autoreset;
+ double count;
+} t_accum_tilde;
+
+static t_class *accum_tilde_class;
+
+static void accum_tilde_wrap(t_accum_tilde *x, t_floatarg f) {
+ x->wrap = (f != 0);
+}
+/*
+static void accum_tilde_set(t_accum_tilde *x, t_floatarg f1, t_floatarg f2) {
+ x->min=(f1<f2)?f1:f2;
+ x->max=(f1>f2)?f1:f2;
+ post(" min: %f \n max: %f",x->min,x->max);
+}
+*/
+
+static void accum_tilde_min(t_accum_tilde *x, t_floatarg f) {
+
+ x->min = f;
+ //accum_tilde_set(x,f,x->max);
+
+}
+
+
+static void accum_tilde_max(t_accum_tilde *x, t_floatarg f) {
+ x->max = f;
+ //accum_tilde_set(x,x->min,f);
+
+}
+
+static void accum_tilde_autoreset(t_accum_tilde *x, t_floatarg f)
+{
+ x->autoreset = (f != 0);
+}
+
+static void accum_tilde_bang(t_accum_tilde *x)
+{
+ x->count = x->min;
+ x->on = 1;
+}
+
+/*
+static void accum_tilde_float(t_accum_tilde *x, t_floatarg f)
+{
+ x->x_accum_tilde = x->x_min = (int)f;
+ x->x_on = 1;
+}
+*/
+
+/*
+static void accum_tilde_list(t_accum_tilde *x, t_symbol *s, int ac, t_atom *av)
+{
+ int i;
+ if (ac > 4) ac = 4;
+ for (i = 0; i < ac; i++)
+ if (av[i].a_type != A_FLOAT) break;
+ switch (i)
+ {
+ case 4:
+ count_autoreset(x, av[3].a_w.w_float);
+ case 3:
+ x->x_on = (av[2].a_w.w_float != 0);
+ case 2:
+ count_max(x, av[1].a_w.w_float);
+ case 1:
+ count_min(x, av[0].a_w.w_float);
+ default:
+ x->x_accum_tilde = x->x_min;
+ }
+}
+*/
+/*
+static void accum_tilde_set(t_accum_tilde *x, t_symbol s, int ac, t_atom *av)
+{
+ if (av[0].a_type == A_FLOAT) count_min(x, av[0].a_w.w_float);
+ if (av[1].a_type == A_FLOAT) count_max(x, av[1].a_w.w_float);
+}
+*/
+static void accum_tilde_stop(t_accum_tilde *x)
+{
+ x->count = x->min;
+ x->on = 0;
+}
+
+static t_int *accum_tilde_perform(t_int *w) {
+ // point to x
+ // point to number of samples
+ // point to inlet~
+ // point to outlet~
+
+ t_accum_tilde *x = (t_accum_tilde *)(w[1]);
+ int nblock = (int)(w[2]);
+ t_float* in = (t_float *)(w[3]);
+ t_float* out = (t_float *)(w[4]);
+ double count = x->count;
+
+ t_float min = (x->min < x->max)?x->min:x->max;
+ t_float max = (x->max > x->min)?x->max:x->min;
+ //post(" min: %f \n max: %f",min,max);
+
+
+ // Do not count if min == max
+ if ( min == max) {
+ count = min;
+ while (nblock--) *out++ = count;
+ } else {
+ if (x->on) {
+ if ( x->wrap ) {
+ // Possible wrapping
+ while (nblock--) {
+ count = count + *in;
+ in++;
+ if (count < min || count >= max) {
+ count = fmod((count - min),(max - min));
+ if (count < 0) {
+ count = count + max ;
+ } else {
+ count = count + min;
+ }
+ }
+ *out++ = count;
+ }
+ } else {
+ // No wrapping
+ while (nblock--) {
+ count = count + *in;
+ in++;
+ *out++ = count;
+ }
+ }
+ } else {
+ /* WRAP EVEN IF NOT ACCUMULATING ?
+ if ( x->wrap && (count < min || count >= max)) {
+ count = fmod((count - min),(max - min));
+ if (count < 0) {
+ count = count + max ;
+ } else {
+ count = count + min;
+ }
+ }
+ */
+ while (nblock--) *out++ = count;
+ }
+ }
+ x->count = count;
+
+ return (w + 5);
+}
+
+static void accum_tilde_dsp(t_accum_tilde *x, t_signal **sp) {
+ if (x->autoreset) accum_tilde_bang(x);
+ // point to x
+ // point to number of samples
+ // point to inlet~
+ // point to outlet~
+ dsp_add(accum_tilde_perform, 4, x, sp[0]->s_n, sp[0]->s_vec,sp[1]->s_vec);
+}
+
+static void *accum_tilde_new(t_floatarg minval, t_floatarg maxval,
+ t_floatarg wrapflag, t_floatarg autoflag)
+{
+ t_accum_tilde *x = (t_accum_tilde *)pd_new(accum_tilde_class);
+
+ x->wrap = 0;
+ x->on = 0;
+
+ accum_tilde_min(x, minval);
+ accum_tilde_max(x, maxval);
+ x->wrap = (wrapflag != 0);
+ accum_tilde_autoreset(x, autoflag);
+ x->count = x->min;
+
+
+
+ //inlet_new((t_object *)x, &s_signal);
+
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("min"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("max"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("wrap"));
+ outlet_new((t_object *)x, &s_signal);
+
+ return (x);
+}
+
+void accum_tilde_setup(void)
+{
+ accum_tilde_class = class_new(gensym("accum~"),
+ (t_newmethod)accum_tilde_new, 0,
+ sizeof(t_accum_tilde), 0,
+ A_DEFFLOAT, A_DEFFLOAT,
+ A_DEFFLOAT, A_DEFFLOAT, 0);
+
+ CLASS_MAINSIGNALIN(accum_tilde_class, t_accum_tilde, f);
+ class_addmethod(accum_tilde_class, (t_method)accum_tilde_dsp, gensym("dsp"), 0);
+ //sic_setup(count_class, count_dsp, SIC_NOMAINSIGNALIN);
+ class_addbang(accum_tilde_class, accum_tilde_bang);
+ //class_addfloat(accum_tilde_class, count_float);
+ //class_addlist(accum_tilde_class, count_list);
+ /*class_addmethod(count_class, (t_method)count_max,
+ gensym("ft1"), A_FLOAT, 0);*/
+
+ class_addmethod(accum_tilde_class, (t_method)accum_tilde_autoreset,
+ gensym("autoreset"), A_FLOAT, 0);
+ class_addmethod(accum_tilde_class, (t_method)accum_tilde_min,
+ gensym("min"), A_FLOAT, 0);
+ class_addmethod(accum_tilde_class, (t_method)accum_tilde_max,
+ gensym("max"), A_FLOAT, 0);
+ class_addmethod(accum_tilde_class, (t_method)accum_tilde_wrap,
+ gensym("wrap"), A_FLOAT, 0);
+ //class_addmethod(count_class, (t_method)count_set, gensym("set"), A_GIMME, 0);
+ class_addmethod(accum_tilde_class, (t_method)accum_tilde_stop, gensym("stop"), 0);
+}
diff --git a/test/count.c b/test/count.c
new file mode 100644
index 0000000..b2ed2cd
--- /dev/null
+++ b/test/count.c
@@ -0,0 +1,145 @@
+/* Copyright (c) 2002-2003 krzYszcz and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#include "m_pd.h"
+#include "sickle/sic.h"
+
+typedef struct _count
+{
+ t_sic x_sic;
+ int x_min;
+ int x_max;
+ int x_limit;
+ int x_on;
+ int x_autoreset;
+ int x_count; /* MAYBE use 64 bits (if 13.5 hours is not enough...) */
+} t_count;
+
+static t_class *count_class;
+
+static void count_min(t_count *x, t_floatarg f)
+{
+ x->x_min = (int)f;
+}
+
+static void count_max(t_count *x, t_floatarg f)
+{
+ x->x_max = (int)f;
+ /* MAYBE use 64 bits */
+ x->x_limit = (x->x_max == 0 ? 0x7fffffff
+ : x->x_max - 1); /* CHECKED */
+}
+
+static void count_autoreset(t_count *x, t_floatarg f)
+{
+ x->x_autoreset = (f != 0);
+}
+
+static void count_bang(t_count *x)
+{
+ x->x_count = x->x_min;
+ x->x_on = 1;
+}
+
+static void count_float(t_count *x, t_floatarg f)
+{
+ x->x_count = x->x_min = (int)f;
+ x->x_on = 1;
+}
+
+static void count_list(t_count *x, t_symbol *s, int ac, t_atom *av)
+{
+ int i;
+ if (ac > 4) ac = 4;
+ for (i = 0; i < ac; i++)
+ if (av[i].a_type != A_FLOAT) break;
+ switch (i)
+ {
+ case 4:
+ count_autoreset(x, av[3].a_w.w_float);
+ case 3:
+ x->x_on = (av[2].a_w.w_float != 0);
+ case 2:
+ count_max(x, av[1].a_w.w_float);
+ case 1:
+ count_min(x, av[0].a_w.w_float);
+ default:
+ x->x_count = x->x_min;
+ }
+}
+
+static void count_set(t_count *x, t_symbol s, int ac, t_atom *av)
+{
+ if (av[0].a_type == A_FLOAT) count_min(x, av[0].a_w.w_float);
+ if (av[1].a_type == A_FLOAT) count_max(x, av[1].a_w.w_float);
+}
+
+static void count_stop(t_count *x)
+{
+ x->x_count = x->x_min;
+ x->x_on = 0;
+}
+
+static t_int *count_perform(t_int *w)
+{
+ t_count *x = (t_count *)(w[1]);
+ int nblock = (int)(w[2]);
+ t_float *out = (t_float *)(w[3]);
+ int count = x->x_count;
+ int limit = x->x_limit;
+ if (x->x_on)
+ {
+ while (nblock--)
+ {
+ if (count > limit) count = x->x_min;
+ *out++ = (t_float)count++;
+ }
+ }
+ else
+ while (nblock--) *out++ = count;
+ x->x_count = count;
+ return (w + 4);
+}
+
+static void count_dsp(t_count *x, t_signal **sp)
+{
+ if (x->x_autoreset) count_bang(x);
+ dsp_add(count_perform, 3, x, sp[0]->s_n, sp[0]->s_vec);
+}
+
+static void *count_new(t_floatarg minval, t_floatarg maxval,
+ t_floatarg onflag, t_floatarg autoflag)
+{
+ t_count *x = (t_count *)pd_new(count_class);
+ count_min(x, minval);
+ count_max(x, maxval);
+ x->x_on = (onflag != 0);
+ count_autoreset(x, autoflag);
+ x->x_count = x->x_min;
+ inlet_new((t_object *)x, (t_pd *)x, &s_float, gensym("ft1"));
+ outlet_new((t_object *)x, &s_signal);
+ return (x);
+}
+
+void count_tilde_setup(void)
+{
+ count_class = class_new(gensym("count~"),
+ (t_newmethod)count_new, 0,
+ sizeof(t_count), 0,
+ A_DEFFLOAT, A_DEFFLOAT,
+ A_DEFFLOAT, A_DEFFLOAT, 0);
+ sic_setup(count_class, count_dsp, SIC_NOMAINSIGNALIN);
+ class_addbang(count_class, count_bang);
+ class_addfloat(count_class, count_float);
+ class_addlist(count_class, count_list);
+ class_addmethod(count_class, (t_method)count_max,
+ gensym("ft1"), A_FLOAT, 0);
+ class_addmethod(count_class, (t_method)count_autoreset,
+ gensym("autoreset"), A_FLOAT, 0);
+ class_addmethod(count_class, (t_method)count_min,
+ gensym("min"), A_FLOAT, 0);
+ class_addmethod(count_class, (t_method)count_set,
+ gensym("set"), A_GIMME, 0);
+ class_addmethod(count_class, (t_method)count_stop, gensym("stop"), 0);
+}
diff --git a/test/dial.c b/test/dial.c
deleted file mode 100644
index ff5045f..0000000
--- a/test/dial.c
+++ /dev/null
@@ -1,792 +0,0 @@
-/* Copyright (c) 1997-1999 Miller Puckette.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
-/* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */
-
-/* 'dial' gui object by Frank Barknecht, 'externalised' by Olaf Matthes */
-/* changed for devel_0.37 by Christoph Kummerer - hardly tested */
-
-/* I had to out-comment the loadbang stuff because I couldn't find the code
- in Pd where it is declared */
-
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-#include "m_pd.h"
-
-#ifndef PD_MAJOR_VERSION
-#include "s_stuff.h"
-#else
-#include "m_imp.h"
-#endif
-
-#include "g_canvas.h"
-
-#include "g_all_guis.h"
-#include <math.h>
-
-#ifdef WIN32
-#include <io.h>
-#else
-#include <unistd.h>
-#endif
-
-#ifndef M_PI
-#define M_PI 3.141592654
-#endif
-
-#define IEM_dial_DEFAULTSIZE 32
-
-/* ------------ dial gui-vertical slider ----------------------- */
-
-t_widgetbehavior dial_widgetbehavior;
-static t_class *dial_class;
-t_symbol *iemgui_key_sym=0; /* taken from g_all_guis.c */
-
-typedef struct _dial /* taken from Frank's modyfied g_all_guis.h */
-{
- t_iemgui x_gui;
- int x_pos;
- int x_val;
- int x_lin0_log1;
- int x_steady;
- double x_min;
- double x_max;
- double x_k;
-} t_dial;
-
-/* widget helper functions */
-
-static void dial_draw_update(t_dial *x, t_glist *glist)
-{
- if (glist_isvisible(glist))
- {
- /* compute dial:*/
- float radius = 0.5*(float)x->x_gui.x_h;
- double angle = 7.0/36.0 + 34.0/36.0*2.0*M_PI*( (double)x->x_val*0.01/(double)x->x_gui.x_h );
- int start = -80;
- int extent = 350 - (int)(360.0*angle/(2.0*M_PI));
- /* center point: */
- int x1 = text_xpix(&x->x_gui.x_obj, glist) + radius;
- int y1 = text_ypix(&x->x_gui.x_obj, glist) + radius;
- int x2 = text_xpix(&x->x_gui.x_obj, glist) + radius + radius * sin( -angle);
- int y2 = text_ypix(&x->x_gui.x_obj, glist) + radius + radius * cos( angle);
-
- sys_vgui(".x%x.c coords %xdial %d %d %d %d\n",
- glist_getcanvas(glist), x,
- x1, /* x1 */
- y1, /* y1 */
- x2, /* x2 */
- y2 /* y2 */
- );
-
- /* post("dial: (%d, %d) (%d, %d)", x1,y1,x2,y2); */
-
- sys_vgui(".x%x.c itemconfigure %xBASE -start %d -extent %d \n", glist_getcanvas(glist), x,
- start, extent);
- }
-}
-
-static void dial_draw_new(t_dial *x, t_glist *glist)
-{
- int xpos=text_xpix(&x->x_gui.x_obj, glist);
- int ypos=text_ypix(&x->x_gui.x_obj, glist);
- /* int r = ypos + x->x_gui.x_h - (x->x_val + 50)/100; */
- t_canvas *canvas=glist_getcanvas(glist);
-
- /* compute dial:*/
- float radius = 0.5*(float)x->x_gui.x_h;
- /* center point: */
- int x1 = xpos + radius;
- int y1 = ypos + radius;
- /* dial */
- double angle = 7.0/36.0 + 34.0/36.0*2.0*M_PI*((float)x->x_val*0.01/(float)(x->x_gui.x_h));
- int x2 = x1 + radius * sin(-angle);
- int y2 = y1 + radius * cos(angle);
-
-
- /* BASE2 */
- sys_vgui(".x%x.c create arc %d %d %d %d -outline #%6.6x -style arc -width 3 -start -80 -extent 340 -tags %xBASE2\n",
- canvas,
- xpos, ypos, /* upper left */
- xpos + x->x_gui.x_h, ypos + x->x_gui.x_h, /* lower right */
- x->x_gui.x_fcol, x);
-
- /* BASE */
- sys_vgui(".x%x.c create arc %d %d %d %d -fill #%6.6x -style arc -width 3 -start -80 -extent 340 -tags %xBASE\n",
- canvas,
- xpos, ypos, /* upper left */
- xpos + x->x_gui.x_h, ypos + x->x_gui.x_h, /* lower right */
- x->x_gui.x_bcol, x);
- /* LINE */
- sys_vgui(".x%x.c create line %d %d %d %d -width 3 -fill #%6.6x -capstyle round -tags %xdial\n",
- canvas,
- x1, /* x1 */
- y1, /* y1 */
- x2, /* x2 */
- y2, /* y2 */
- x->x_gui.x_fcol, /* color */
- x);
-
- sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
- -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
- canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
- x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
- if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos, ypos + x->x_gui.x_h+2,
- xpos+7, ypos + x->x_gui.x_h+3,
- x, 0);
- if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos, ypos-2,
- xpos+7, ypos-1,
- x, 0);
-}
-
-static void dial_draw_move(t_dial *x, t_glist *glist)
-{
- int xpos=text_xpix(&x->x_gui.x_obj, glist);
- int ypos=text_ypix(&x->x_gui.x_obj, glist);
- /* int r = ypos + x->x_gui.x_h - (x->x_val + 50)/100; */
- t_canvas *canvas=glist_getcanvas(glist);
- /* compute dial:*/
- float radius = 0.5*(float)x->x_gui.x_h;
- /* float angle = 7.0/36.0 + 34.0/36.0*2.0*M_PI*((float)x->x_val*0.01/(float)(x->x_gui.x_h)); */
- double angle = 7.0/36.0 + 34.0/36.0*2.0*M_PI*( (double)x->x_val*0.01/(double)x->x_gui.x_h );
- /* center point: */
- int x1 = text_xpix(&x->x_gui.x_obj, glist) + radius;
- int y1 = text_ypix(&x->x_gui.x_obj, glist) + radius;
- int x2 = text_xpix(&x->x_gui.x_obj, glist) + radius + radius * sin( -angle);
- int y2 = text_ypix(&x->x_gui.x_obj, glist) + radius + radius * cos( angle);
-
-
-
- sys_vgui(".x%x.c coords %xdial %d %d %d %d\n",
- canvas, x,
- x1, /* x1 */
- y1, /* y1 */
- x2, /* x2 */
- y2 /* y2 */
- );
- /* post("dial: (%d, %d) (%d, %d)", x1,y1,x2,y2); */
-
- sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
- canvas, x,
- xpos, ypos,
- xpos + x->x_gui.x_h, ypos + x->x_gui.x_h);
-
- sys_vgui(".x%x.c coords %xBASE2 %d %d %d %d\n",
- canvas, x,
- xpos, ypos,
- xpos + x->x_gui.x_h, ypos + x->x_gui.x_h);
-
- sys_vgui(".x%x.c coords %xLABEL %d %d\n",
- canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
- if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0,
- xpos, ypos + x->x_gui.x_h+2,
- xpos+7, ypos + x->x_gui.x_h+3);
- if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
- canvas, x, 0,
- xpos, ypos-2,
- xpos+7, ypos-1);
-}
-
-static void dial_draw_erase(t_dial* x,t_glist* glist)
-{
- t_canvas *canvas=glist_getcanvas(glist);
-
- sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
- sys_vgui(".x%x.c delete %xBASE2\n", canvas, x);
- sys_vgui(".x%x.c delete %xdial\n", canvas, x);
- sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
- if(!x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
- if(!x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
-}
-
-static void dial_draw_config(t_dial* x,t_glist* glist)
-{
- t_canvas *canvas=glist_getcanvas(glist);
-
- sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
- canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
- x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
- strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
- sys_vgui(".x%x.c itemconfigure %xdial -fill #%6.6x\n", canvas,
- x, x->x_gui.x_fcol);
- sys_vgui(".x%x.c itemconfigure %xBASE2 -outline #%6.6x\n", canvas,
- x, x->x_gui.x_fcol);
- sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas,
- x, x->x_gui.x_bcol);
-}
-
-static void dial_draw_io(t_dial* x,t_glist* glist, int old_snd_rcv_flags)
-{
- int xpos=text_xpix(&x->x_gui.x_obj, glist);
- int ypos=text_ypix(&x->x_gui.x_obj, glist);
- t_canvas *canvas=glist_getcanvas(glist);
-
- if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
- canvas,
- xpos, ypos + x->x_gui.x_h+2,
- xpos+7, ypos + x->x_gui.x_h+3,
- x, 0);
- if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
- sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
- if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
- canvas,
- xpos, ypos-2,
- xpos+7, ypos-1,
- x, 0);
- if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
- sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
-}
-
-static void dial_draw_select(t_dial *x, t_glist *glist)
-{
- t_canvas *canvas=glist_getcanvas(glist);
-
- if(x->x_gui.x_fsf.x_selected)
- {
- pd_bind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym);
- sys_vgui(".x%x.c itemconfigure %xBASE2 -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
- }
- else
- {
- pd_unbind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym);
- sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
- sys_vgui(".x%x.c itemconfigure %xBASE2 -outline #%6.6x\n", canvas, x, x->x_gui.x_fcol);
- sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
- }
-}
-
-void dial_draw(t_dial *x, t_glist *glist, int mode)
-{
- if(mode == IEM_GUI_DRAW_MODE_UPDATE)
- dial_draw_update(x, glist);
- else if(mode == IEM_GUI_DRAW_MODE_MOVE)
- dial_draw_move(x, glist);
- else if(mode == IEM_GUI_DRAW_MODE_NEW)
- dial_draw_new(x, glist);
- else if(mode == IEM_GUI_DRAW_MODE_SELECT)
- dial_draw_select(x, glist);
- else if(mode == IEM_GUI_DRAW_MODE_ERASE)
- dial_draw_erase(x, glist);
- else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
- dial_draw_config(x, glist);
- else if(mode >= IEM_GUI_DRAW_MODE_IO)
- dial_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
-}
-
-/* ------------------------ dial widgetbehaviour----------------------------- */
-
-
-static void dial_getrect(t_gobj *z, t_glist *glist,
- int *xp1, int *yp1, int *xp2, int *yp2)
-{
- t_dial* x = (t_dial*)z;
-
- *xp1 = text_xpix(&x->x_gui.x_obj, glist);
- *yp1 = text_ypix(&x->x_gui.x_obj, glist) - 2;
- *xp2 = *xp1 + x->x_gui.x_h;
- *yp2 = *yp1 + x->x_gui.x_h + 5;
-}
-
-static void dial_save(t_gobj *z, t_binbuf *b)
-{
- t_dial *x = (t_dial *)z;
- int bflcol[3], *ip1, *ip2;
- t_symbol *srl[3];
-
- iemgui_save(&x->x_gui, srl, bflcol);
- ip1 = (int *)(&x->x_gui.x_isa);
- ip2 = (int *)(&x->x_gui.x_fsf);
- binbuf_addv(b, "ssiisiiffiisssiiiiiiiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_gui.x_obj.te_binbuf)),
- x->x_gui.x_h, x->x_gui.x_h,
- (float)x->x_min, (float)x->x_max,
- x->x_lin0_log1, (*ip1)&IEM_INIT_ARGS_ALL,
- srl[0], srl[1], srl[2],
- x->x_gui.x_ldx, x->x_gui.x_ldy,
- (*ip2)&IEM_FSTYLE_FLAGS_ALL, x->x_gui.x_fontsize,
- bflcol[0], bflcol[1], bflcol[2],
- x->x_val, x->x_steady);
- binbuf_addv(b, ";");
-}
-
-void dial_check_height(t_dial *x, int h)
-{
- if(h < IEM_SL_MINSIZE)
- h = IEM_SL_MINSIZE;
- x->x_gui.x_h = h;
- if(x->x_val > (x->x_gui.x_h*100 - 100))
- {
- x->x_pos = x->x_gui.x_h*100 - 100;
- x->x_val = x->x_pos;
- }
- if(x->x_lin0_log1)
- x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
- else
- x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
-}
-
-void dial_check_minmax(t_dial *x, double min, double max)
-{
- if(x->x_lin0_log1)
- {
- if((min == 0.0)&&(max == 0.0))
- max = 1.0;
- if(max > 0.0)
- {
- if(min <= 0.0)
- min = 0.01*max;
- }
- else
- {
- if(min > 0.0)
- max = 0.01*min;
- }
- }
- x->x_min = min;
- x->x_max = max;
- if(x->x_min > x->x_max) /* bugfix */
- x->x_gui.x_isa.x_reverse = 1;
- else
- x->x_gui.x_isa.x_reverse = 0;
- if(x->x_lin0_log1)
- x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_h - 1);
- else
- x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
-}
-
-static void dial_properties(t_gobj *z, t_glist *owner)
-{
- t_dial *x = (t_dial *)z;
- char buf[800];
- t_symbol *srl[3];
-
- iemgui_properties(&x->x_gui, srl);
-
- sprintf(buf, "pdtk_iemgui_dialog %%s dial \
- --------dimensions(pix)(pix):-------- %d %d NONE: %d %d height: \
- -----------output-range:----------- %g left: %g right: %g \
- %d lin log %d %d empty %d \
- %s %s \
- %s %d %d \
- %d %d \
- %d %d %d\n",
- x->x_gui.x_w, IEM_SL_MINSIZE, x->x_gui.x_h, IEM_GUI_MINSIZE,
- x->x_min, x->x_max, 0.0,/*no_schedule*/
- x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/
- srl[0]->s_name, srl[1]->s_name,
- srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
- x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
- 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
- gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
-}
-
-static void dial_bang(t_dial *x)
-{
- double out;
-
- if(x->x_lin0_log1)
- out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
- else
- out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
- if((out < 1.0e-10)&&(out > -1.0e-10))
- out = 0.0;
- //post("dial_bang -- x_k: %f", x->x_k);
-
- outlet_float(x->x_gui.x_obj.ob_outlet, out);
- if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
- pd_float(x->x_gui.x_snd->s_thing, out);
-}
-
-static void dial_dialog(t_dial *x, t_symbol *s, int argc, t_atom *argv)
-{
- t_symbol *srl[3];
- int w = (int)atom_getintarg(0, argc, argv);
- int h = (int)atom_getintarg(1, argc, argv);
- double min = (double)atom_getfloatarg(2, argc, argv);
- double max = (double)atom_getfloatarg(3, argc, argv);
- int lilo = (int)atom_getintarg(4, argc, argv);
- int steady = (int)atom_getintarg(17, argc, argv);
- int sr_flags;
-
- if(lilo != 0) lilo = 1;
- x->x_lin0_log1 = lilo;
- if(steady)
- x->x_steady = 1;
- else
- x->x_steady = 0;
- sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
- x->x_gui.x_h = iemgui_clip_size(w);
- dial_check_height(x, h);
- dial_check_minmax(x, min, max);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
- canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
-}
-
-static void dial_motion(t_dial *x, t_floatarg dx, t_floatarg dy)
-{
- int old = x->x_val;
-
- if(x->x_gui.x_fsf.x_finemoved)
- x->x_pos -= (int)dy;
- else
- x->x_pos -= 100*(int)dy;
- x->x_val = x->x_pos;
- if(x->x_val > (100*x->x_gui.x_h - 100))
- {
- x->x_val = 100*x->x_gui.x_h - 100;
- x->x_pos += 50;
- x->x_pos -= x->x_pos%100;
- }
- if(x->x_val < 0)
- {
- x->x_val = 0;
- x->x_pos -= 50;
- x->x_pos -= x->x_pos%100;
- }
- if(old != x->x_val)
- {
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- dial_bang(x);
- }
-}
-
-static void dial_click(t_dial *x, t_floatarg xpos, t_floatarg ypos,
- t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
-{
- if(!x->x_steady)
- x->x_val = (int)(100.0 * (x->x_gui.x_h + text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist) - ypos));
- if(x->x_val > (100*x->x_gui.x_h - 100))
- x->x_val = 100*x->x_gui.x_h - 100;
- if(x->x_val < 0)
- x->x_val = 0;
- x->x_pos = x->x_val;
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- dial_bang(x);
- glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, (t_glistmotionfn)dial_motion,
- 0, xpos, ypos);
-}
-
-static int dial_newclick(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
-{
- t_dial* x = (t_dial *)z;
-
- if(doit)
- {
- dial_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift,
- 0, (t_floatarg)alt);
- if(shift)
- x->x_gui.x_fsf.x_finemoved = 1;
- else
- x->x_gui.x_fsf.x_finemoved = 0;
- }
- return (1);
-}
-
-static void dial_set(t_dial *x, t_floatarg f)
-{
- double g;
-
- if(x->x_gui.x_isa.x_reverse) /* bugfix */
- {
- if(f > x->x_min)
- f = x->x_min;
- if(f < x->x_max)
- f = x->x_max;
- }
- else
- {
- if(f > x->x_max)
- f = x->x_max;
- if(f < x->x_min)
- f = x->x_min;
- }
- if(x->x_lin0_log1)
- g = log(f/x->x_min)/x->x_k;
- else
- g = (f - x->x_min) / x->x_k;
- //post("dial_set f: %f", f );
- //post("dial_set g: %f", g );
- x->x_val = (int)(100.0*g + 0.49999);
- // x->x_val = (int)(100.0*g);
- x->x_pos = x->x_val;
- //post("dial_set x_val: %f", x->x_val );
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
-}
-
-static void dial_float(t_dial *x, t_floatarg f)
-{
- /* post("dial_set infloat f: %f", f ); */
- dial_set(x, f);
- if(x->x_gui.x_fsf.x_put_in2out)
- dial_bang(x);
-}
-
-static void dial_size(t_dial *x, t_symbol *s, int ac, t_atom *av)
-{
- x->x_gui.x_h = iemgui_clip_size((int)atom_getintarg(0, ac, av));
- if(ac > 1)
- dial_check_height(x, (int)atom_getintarg(1, ac, av));
- iemgui_size((void *)x, &x->x_gui);
-}
-
-static void dial_delta(t_dial *x, t_symbol *s, int ac, t_atom *av)
-{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
-
-static void dial_pos(t_dial *x, t_symbol *s, int ac, t_atom *av)
-{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
-
-static void dial_range(t_dial *x, t_symbol *s, int ac, t_atom *av)
-{
- dial_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
- (double)atom_getfloatarg(1, ac, av));
-}
-
-static void dial_color(t_dial *x, t_symbol *s, int ac, t_atom *av)
-{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
-
-static void dial_send(t_dial *x, t_symbol *s)
-{iemgui_send(x, &x->x_gui, s);}
-
-static void dial_receive(t_dial *x, t_symbol *s)
-{iemgui_receive(x, &x->x_gui, s);}
-
-static void dial_label(t_dial *x, t_symbol *s)
-{iemgui_label((void *)x, &x->x_gui, s);}
-
-static void dial_label_pos(t_dial *x, t_symbol *s, int ac, t_atom *av)
-{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
-
-static void dial_label_font(t_dial *x, t_symbol *s, int ac, t_atom *av)
-{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
-
-static void dial_log(t_dial *x)
-{
- x->x_lin0_log1 = 1;
- dial_check_minmax(x, x->x_min, x->x_max);
-}
-
-static void dial_lin(t_dial *x)
-{
- x->x_lin0_log1 = 0;
- x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_h - 1);
-}
-
-static void dial_init(t_dial *x, t_floatarg f)
-{
- x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
-}
-
-static void dial_steady(t_dial *x, t_floatarg f)
-{
- x->x_steady = (f==0.0)?0:1;
-}
-
-static void dial_loadbang(t_dial *x)
-{
- /* WARNING: this is a kludge to get this object building on
- Windows. Currently, the linker fails on the symbol
- "sys_noloadbang". <hans@at.or.at>
- */
-#ifdef _WIN32
- if(x->x_gui.x_isa.x_loadinit)
-#else
- if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
-#endif
- {
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
- dial_bang(x);
- }
-}
-
-/*
-static void dial_list(t_dial *x, t_symbol *s, int ac, t_atom *av)
-{
- int l=iemgui_list((void *)x, &x->x_gui, s, ac, av);
-
- if(l < 0)
- {
- if(IS_A_FLOAT(av,0))
- dial_float(x, atom_getfloatarg(0, ac, av));
- }
- else if(l > 0)
- {
- (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
- canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
- }
-}
-*/
-
-static void *dial_new(t_symbol *s, int argc, t_atom *argv)
-{
- t_dial *x = (t_dial *)pd_new(dial_class);
- int bflcol[]={-262144, -1, -1};
- t_symbol *srl[3];
- int w=IEM_dial_DEFAULTSIZE, h=IEM_dial_DEFAULTSIZE;
- int lilo=0, ldx=0, ldy=-8;
- int fs=8, v=0, steady=1;
- double min=0.0, max=(double)(IEM_SL_DEFAULTSIZE-1);
- char str[144];
-
- //srl[0] = gensym("empty");
- //srl[1] = gensym("empty");
- //srl[2] = gensym("empty");
-
- iem_inttosymargs(&x->x_gui.x_isa, 0);
- iem_inttofstyle(&x->x_gui.x_fsf, 0);
-
-
- if(((argc == 17)||(argc == 18))&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
- &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
- &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
- &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
- &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7))
- &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8))
- &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
- &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
- &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
- {
- w = (int)atom_getintarg(0, argc, argv);
- h = (int)atom_getintarg(1, argc, argv);
- min = (double)atom_getfloatarg(2, argc, argv);
- max = (double)atom_getfloatarg(3, argc, argv);
- lilo = (int)atom_getintarg(4, argc, argv);
- iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
- iemgui_new_getnames(&x->x_gui, 6, argv);
- ldx = (int)atom_getintarg(9, argc, argv);
- ldy = (int)atom_getintarg(10, argc, argv);
- iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
- fs = (int)atom_getintarg(12, argc, argv);
- bflcol[0] = (int)atom_getintarg(13, argc, argv);
- bflcol[1] = (int)atom_getintarg(14, argc, argv);
- bflcol[2] = (int)atom_getintarg(15, argc, argv);
- v = (int)atom_getintarg(16, argc, argv);
- }
- else iemgui_new_getnames(&x->x_gui, 6, 0);
- if((argc == 18)&&IS_A_FLOAT(argv,17))
- steady = (int)atom_getintarg(17, argc, argv);
-
- x->x_gui.x_draw = (t_iemfunptr)dial_draw;
-
- x->x_gui.x_fsf.x_snd_able = 1;
- x->x_gui.x_fsf.x_rcv_able = 1;
-
- x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
- if(x->x_gui.x_isa.x_loadinit)
- x->x_val = v;
- else
- x->x_val = 0;
- x->x_pos = x->x_val;
- if(lilo != 0) lilo = 1;
- x->x_lin0_log1 = lilo;
- if(steady != 0) steady = 1;
- x->x_steady = steady;
- if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
- x->x_gui.x_fsf.x_snd_able = 0;
- if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
- x->x_gui.x_fsf.x_rcv_able = 0;
- if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
- else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
- else { x->x_gui.x_fsf.x_font_style = 0;
- strcpy(x->x_gui.x_font, "courier"); }
- if(x->x_gui.x_fsf.x_rcv_able)
- pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
- x->x_gui.x_ldx = ldx;
- x->x_gui.x_ldy = ldy;
- if(fs < 4)
- fs = 4;
- x->x_gui.x_fontsize = fs;
- x->x_gui.x_h = iemgui_clip_size(h);
- dial_check_height(x, w);
- dial_check_minmax(x, min, max);
- iemgui_all_colfromload(&x->x_gui, bflcol);
- //x->x_thick = 0;
- iemgui_verify_snd_ne_rcv(&x->x_gui);
- outlet_new(&x->x_gui.x_obj, &s_float);
- return (x);
-}
-
-
-
-static void dial_free(t_dial *x)
-{
- if(x->x_gui.x_fsf.x_selected)
- pd_unbind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym);
- if(x->x_gui.x_fsf.x_rcv_able)
- pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
- gfxstub_deleteforkey(x);
-}
-
-void dial_setup(void)
-{
- dial_class = class_new(gensym("dial"), (t_newmethod)dial_new,
- (t_method)dial_free, sizeof(t_dial), 0, A_GIMME, 0);
- class_addcreator((t_newmethod)dial_new, gensym("dial"), A_GIMME, 0);
- class_addbang(dial_class,dial_bang);
- class_addfloat(dial_class,dial_float);
-
- /* class_addlist(dial_class, dial_list); */
- class_addmethod(dial_class, (t_method)dial_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
- class_addmethod(dial_class, (t_method)dial_motion, gensym("motion"),
- A_FLOAT, A_FLOAT, 0);
- class_addmethod(dial_class, (t_method)dial_dialog, gensym("dialog"),
- A_GIMME, 0);
- class_addmethod(dial_class, (t_method)dial_loadbang, gensym("loadbang"), 0);
- class_addmethod(dial_class, (t_method)dial_set, gensym("set"), A_FLOAT, 0);
- class_addmethod(dial_class, (t_method)dial_size, gensym("size"), A_GIMME, 0);
- class_addmethod(dial_class, (t_method)dial_delta, gensym("delta"), A_GIMME, 0);
- class_addmethod(dial_class, (t_method)dial_pos, gensym("pos"), A_GIMME, 0);
- class_addmethod(dial_class, (t_method)dial_range, gensym("range"), A_GIMME, 0);
- class_addmethod(dial_class, (t_method)dial_color, gensym("color"), A_GIMME, 0);
- class_addmethod(dial_class, (t_method)dial_send, gensym("send"), A_DEFSYM, 0);
- class_addmethod(dial_class, (t_method)dial_receive, gensym("receive"), A_DEFSYM, 0);
- class_addmethod(dial_class, (t_method)dial_label, gensym("label"), A_DEFSYM, 0);
- class_addmethod(dial_class, (t_method)dial_label_pos, gensym("label_pos"), A_GIMME, 0);
- class_addmethod(dial_class, (t_method)dial_label_font, gensym("label_font"), A_GIMME, 0);
- class_addmethod(dial_class, (t_method)dial_log, gensym("log"), 0);
- class_addmethod(dial_class, (t_method)dial_lin, gensym("lin"), 0);
- class_addmethod(dial_class, (t_method)dial_init, gensym("init"), A_FLOAT, 0);
- class_addmethod(dial_class, (t_method)dial_steady, gensym("steady"), A_FLOAT, 0);
- if(!iemgui_key_sym) iemgui_key_sym = gensym("#keyname");
- dial_widgetbehavior.w_getrectfn = dial_getrect;
- dial_widgetbehavior.w_displacefn = iemgui_displace;
- dial_widgetbehavior.w_selectfn = iemgui_select;
- dial_widgetbehavior.w_activatefn = NULL;
- dial_widgetbehavior.w_deletefn = iemgui_delete;
- dial_widgetbehavior.w_visfn = iemgui_vis;
- dial_widgetbehavior.w_clickfn = dial_newclick;
-#if PD_MINOR_VERSION < 37 /* TODO: remove old behaviour in exactly 2 months from now */
- dial_widgetbehavior.w_propertiesfn = dial_properties;;
- dial_widgetbehavior.w_savefn = dial_save;
-#else
- class_setpropertiesfn(dial_class, &dial_properties);
- class_setsavefn(dial_class, &dial_save);
-#endif
- class_setwidget(dial_class, &dial_widgetbehavior);
- //class_sethelpsymbol(dial_class, gensym("dial"));
-}
diff --git a/test/frameaccum.c b/test/frameaccum.c
new file mode 100644
index 0000000..6038ae5
--- /dev/null
+++ b/test/frameaccum.c
@@ -0,0 +1,71 @@
+/* Copyright (c) 2002-2003 krzYszcz and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#include <string.h>
+#include "m_pd.h"
+#include "common/grow.h"
+#include "sickle/sic.h"
+
+#define FRAMEACCUM_INISIZE 512
+
+typedef struct _frameaccum
+{
+ t_sic x_sic;
+ int x_size;
+ t_float *x_frame;
+ t_float x_frameini[FRAMEACCUM_INISIZE];
+} t_frameaccum;
+
+static t_class *frameaccum_class;
+
+static t_int *frameaccum_perform(t_int *w)
+{
+ int nblock = (int)(w[1]);
+ t_float *frame = (t_float *)(w[2]);
+ t_float *in = (t_float *)(w[3]);
+ t_float *out = (t_float *)(w[4]);
+ while (nblock--) *out++ = (*frame++ += *in++);
+ return (w + 5);
+}
+
+static void frameaccum_dsp(t_frameaccum *x, t_signal **sp)
+{
+ int nblock = sp[0]->s_n;
+ if (nblock > x->x_size)
+ x->x_frame = grow_nodata(&nblock, &x->x_size, x->x_frame,
+ FRAMEACCUM_INISIZE, x->x_frameini,
+ sizeof(*x->x_frame));
+ memset(x->x_frame, 0, nblock * sizeof(*x->x_frame)); /* CHECKED */
+ dsp_add(frameaccum_perform, 4, nblock, x->x_frame,
+ sp[0]->s_vec, sp[1]->s_vec);
+}
+
+static void frameaccum_free(t_frameaccum *x)
+{
+ if (x->x_frame != x->x_frameini)
+ freebytes(x->x_frame, x->x_size * sizeof(*x->x_frame));
+}
+
+static void *frameaccum_new(t_symbol *s, int ac, t_atom *av)
+{
+ t_frameaccum *x = (t_frameaccum *)pd_new(frameaccum_class);
+ int size;
+ x->x_size = FRAMEACCUM_INISIZE;
+ x->x_frame = x->x_frameini;
+ if ((size = sys_getblksize()) > FRAMEACCUM_INISIZE)
+ x->x_frame = grow_nodata(&size, &x->x_size, x->x_frame,
+ FRAMEACCUM_INISIZE, x->x_frameini,
+ sizeof(*x->x_frame));
+ outlet_new((t_object *)x, &s_signal);
+ return (x);
+}
+
+void frameaccum_tilde_setup(void)
+{
+ frameaccum_class = class_new(gensym("frameaccum~"),
+ (t_newmethod)frameaccum_new,
+ (t_method)frameaccum_free,
+ sizeof(t_frameaccum), 0, 0);
+ sic_setup(frameaccum_class, frameaccum_dsp, SIC_FLOATTOSIGNAL);
+}
diff --git a/test/from_ascii_code-help.pd b/test/from_ascii_code-help.pd
new file mode 100644
index 0000000..0b4ee06
--- /dev/null
+++ b/test/from_ascii_code-help.pd
@@ -0,0 +1,19 @@
+#N canvas 1285 315 450 300 10;
+#X obj 107 212 print;
+#X msg 93 43 65;
+#X msg 139 47 43;
+#X obj 190 61 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X msg 52 49 32;
+#X obj 107 165 tof/from_ascii_code 13;
+#X msg 240 60 49 50 51 32 50 13;
+#X msg 280 95 54;
+#X msg 282 126 13;
+#X connect 1 0 5 0;
+#X connect 2 0 5 0;
+#X connect 3 0 5 0;
+#X connect 4 0 5 0;
+#X connect 5 0 0 0;
+#X connect 6 0 5 0;
+#X connect 7 0 5 0;
+#X connect 8 0 5 0;
diff --git a/test/from_ascii_code.c b/test/from_ascii_code.c
new file mode 100644
index 0000000..31f5086
--- /dev/null
+++ b/test/from_ascii_code.c
@@ -0,0 +1,111 @@
+#include "m_pd.h"
+
+//static char* from_ascii_code_text;
+// Common binbuf to all objects
+static t_binbuf* from_ascii_code_binbuf;
+
+typedef struct _from_ascii_code
+{
+
+ t_object x_ob;
+ int eof_is_set;
+ int eof;
+ t_outlet* outlet_left;
+ //t_outlet* outlet_right;
+ char* text;
+ int text_size;
+ int size;
+} t_from_ascii_code;
+
+static t_class *from_ascii_code_class;
+
+// Force output even if eof has not been received
+static void from_ascii_code_bang(t_from_ascii_code *x) {
+
+ if ( x->size ) {
+ binbuf_clear(from_ascii_code_binbuf);
+ binbuf_text(from_ascii_code_binbuf, x->text, x->size);
+ t_atom *argv = binbuf_getvec(from_ascii_code_binbuf);
+ int argc = binbuf_getnatom(from_ascii_code_binbuf);
+ if ( argc) {
+ if ( (argv->a_type == A_SYMBOL) ) {
+ outlet_anything(x->outlet_left,atom_getsymbol(argv),argc-1,argv+1);
+ } else {
+ outlet_anything(x->outlet_left,&s_list,argc,argv);
+ }
+ }
+ x->size = 0;
+ }
+}
+
+
+static void from_ascii_code_float(t_from_ascii_code *x, t_float f) {
+
+ if ( x->eof_is_set && f == x->eof ) {
+ from_ascii_code_bang(x);
+ } else if ( f > 31 && f < 127 ) {
+ x->text[x->size] = (char) f;
+ x->size = x->size + 1;
+ if ( x->size >= x->text_size ) {
+
+ x->text = resizebytes(x->text, x->text_size * sizeof(*(x->text)),
+ (x->text_size + 100) * sizeof(*(x->text)));
+ x->text_size = x->text_size + 100;
+ }
+ }
+}
+
+static void from_ascii_code_list(t_from_ascii_code *x, t_symbol *s, int argc, t_atom *argv) {
+ int i;
+ for ( i=0; i < argc; i++ ) {
+ if ( ((argv+i)->a_type == A_FLOAT) ) {
+ from_ascii_code_float(x,atom_getfloat(argv+i));
+ }
+ }
+}
+
+static void from_ascii_code_free(t_from_ascii_code *x) {
+
+ freebytes(x->text,x->text_size*sizeof(*(x->text)));
+}
+
+static void *from_ascii_code_new(t_symbol *s, int ac, t_atom *av)
+{
+ t_from_ascii_code *x = (t_from_ascii_code *)pd_new(from_ascii_code_class);
+
+ // set eof if eof is set
+ if ( ac && ((av)->a_type == A_FLOAT)) {
+ x->eof = (int) atom_getfloat(av);
+ x->eof_is_set = 1;
+ } else {
+ x->eof_is_set = 0;
+ }
+
+ // create string
+ x->text_size = 100;
+ x->text = getbytes(x->text_size*sizeof(*x->text));
+
+ x->size = 0;
+
+ x->outlet_left = outlet_new(&x->x_ob, &s_list);
+ //x->outlet_right = outlet_new(&x->x_ob, &s_float);
+
+ return (x);
+}
+
+void from_ascii_code_setup(void)
+{
+ // create binbuf (no need to ever free)
+ from_ascii_code_binbuf = binbuf_new();
+
+
+
+ from_ascii_code_class = class_new(gensym("from_ascii_code"),
+ (t_newmethod)from_ascii_code_new, (t_method)from_ascii_code_free,
+ sizeof(t_from_ascii_code), 0, A_GIMME, 0);
+
+ class_addbang(from_ascii_code_class, from_ascii_code_bang);
+ class_addfloat(from_ascii_code_class, from_ascii_code_float);
+ class_addlist(from_ascii_code_class, from_ascii_code_list);
+
+ }
diff --git a/test/imagebutton.c b/test/imagebutton.c
new file mode 100644
index 0000000..577924a
--- /dev/null
+++ b/test/imagebutton.c
@@ -0,0 +1,415 @@
+#include <m_pd.h>
+#include "g_canvas.h"
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+/* Append " x " to the following line to show debugging messages */
+#define DEBUG(x) x
+
+// TODO: NEED TO FREE UNUSED IMAGES!
+
+
+
+/* ------------------------ imagebutton ----------------------------- */
+
+static t_class *imagebutton_class;
+t_widgetbehavior imagebutton_widgetbehavior;
+
+
+typedef struct _imagebutton
+{
+ t_object x_obj;
+ t_glist * glist;
+ int width;
+ int height;
+ t_symbol* image_a;
+ t_symbol* image_b;
+ t_symbol* receive;
+ t_clock* clock_flash;
+ t_clock* clock_brk;
+ int flashing;
+ t_outlet* outlet;
+} t_imagebutton;
+
+
+static void imagebutton_bang(t_imagebutton *x)
+{
+
+ t_glist* glist = glist_getcanvas(x->glist);
+ if(x->flashing) {
+ sys_vgui(".x%x.c itemconfigure %ximage -image %x_imagebutton \n", glist, x,x->image_a);
+ clock_delay(x->clock_brk, 50);
+ //x->flashed = 1;
+ } else {
+ sys_vgui(".x%x.c itemconfigure %ximage -image %x_imagebutton \n", glist, x,x->image_b);
+ x->flashing = 1;
+
+ }
+ clock_delay(x->clock_flash, 250);
+
+ outlet_bang(x->outlet);
+}
+
+static void imagebutton_flash_timeout(t_imagebutton *x)
+{
+ t_glist* glist = glist_getcanvas(x->glist);
+ x->flashing = 0;
+ sys_vgui(".x%x.c itemconfigure %ximage -image %x_imagebutton \n", glist, x,x->image_a);
+
+}
+
+static void imagebutton_brk_timeout(t_imagebutton *x)
+{
+ t_glist* glist = glist_getcanvas(x->glist);
+ x->flashing = 1;
+ sys_vgui(".x%x.c itemconfigure %ximage -image %x_imagebutton \n", glist, x,x->image_b);
+
+}
+
+
+/* widget helper functions */
+
+static const char* imagebutton_get_filename(t_imagebutton *x,char *file) {
+ static char fname[MAXPDSTRING];
+ char *bufptr;
+ int fd;
+
+ fd=open_via_path(canvas_getdir(glist_getcanvas(x->glist))->s_name,
+ file, "",fname, &bufptr, MAXPDSTRING, 1);
+ if(fd>0){
+ fname[strlen(fname)]='/';
+ DEBUG(post("image file: %s",fname);)
+ close(fd);
+ return fname;
+ } else {
+ return 0;
+ }
+}
+
+static int imagebutton_click(t_imagebutton *x, struct _glist *glist,
+ int xpos, int ypos, int shift, int alt, int dbl, int doit) {
+ DEBUG(post("x:%i y:%i dbl:%i doit:%i",xpos,ypos,dbl,doit);)
+ //if ( doit) {
+ //sys_vgui(".x%x.c itemconfigure %ximage -state \"%s\"\n", x->glist, x, doit?"disabled":"normal");
+ if ( doit) imagebutton_bang(x) ;
+ //}
+ return (1);
+ }
+
+
+
+
+static void imagebutton_drawme(t_imagebutton *x, t_glist *glist, int firsttime) {
+ if (firsttime) {
+
+ sys_vgui(".x%x.c create image %d %d -anchor nw -image %x_imagebutton -disabledimage %x_imagebutton -tags %ximage\n",
+ glist_getcanvas(glist),
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x->image_a,x->image_b,x);
+
+
+ sys_vgui("pd [concat %s _imagesize [image width %x_imagebutton] [image height %x_imagebutton] \\;]\n",x->receive->s_name,x->image_a,x->image_a);
+
+
+ } else {
+ sys_vgui(".x%x.c coords %ximage %d %d\n",
+ glist_getcanvas(glist), x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
+ }
+
+}
+
+
+void imagebutton_erase(t_imagebutton* x,t_glist* glist)
+{
+ int n;
+ sys_vgui(".x%x.c delete %ximage\n",
+ glist_getcanvas(glist), x);
+
+}
+
+
+
+/* ------------------------ image widgetbehaviour----------------------------- */
+
+
+static void imagebutton_getrect(t_gobj *z, t_glist *glist,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ int width, height;
+ t_imagebutton* x = (t_imagebutton*)z;
+
+
+ width = x->width;
+ height = x->height;
+ *xp1 = text_xpix(&x->x_obj, glist);
+ *yp1 = text_ypix(&x->x_obj, glist);
+ *xp2 = text_xpix(&x->x_obj, glist) + width;
+ *yp2 = text_ypix(&x->x_obj, glist) + height;
+}
+
+static void imagebutton_displace(t_gobj *z, t_glist *glist,
+ int dx, int dy)
+{
+ t_imagebutton *x = (t_imagebutton *)z;
+ x->x_obj.te_xpix += dx;
+ x->x_obj.te_ypix += dy;
+ sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
+ glist_getcanvas(glist), x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->width, text_ypix(&x->x_obj, glist) + x->height);
+
+ imagebutton_drawme(x, glist, 0);
+ canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x);
+}
+
+static void imagebutton_select(t_gobj *z, t_glist *glist, int state)
+{
+ t_imagebutton *x = (t_imagebutton *)z;
+ if (state) {
+ sys_vgui(".x%x.c create rectangle \
+%d %d %d %d -tags %xSEL -outline blue\n",
+ glist_getcanvas(glist),
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->width, text_ypix(&x->x_obj, glist) + x->height,
+ x);
+ }
+ else {
+ sys_vgui(".x%x.c delete %xSEL\n",
+ glist_getcanvas(glist), x);
+ }
+
+
+
+}
+
+
+static void imagebutton_activate(t_gobj *z, t_glist *glist, int state)
+{
+/* t_text *x = (t_text *)z;
+ t_rtext *y = glist_findrtext(glist, x);
+ if (z->g_pd != gatom_class) rtext_activate(y, state);*/
+}
+
+static void imagebutton_delete(t_gobj *z, t_glist *glist)
+{
+ t_text *x = (t_text *)z;
+ //canvas_deletelinesfor(glist_getcanvas(glist), x);
+ canvas_deletelinesfor(glist, x);
+}
+
+
+static void imagebutton_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_imagebutton* s = (t_imagebutton*)z;
+ if (vis)
+ imagebutton_drawme(s, glist, 1);
+ else
+ imagebutton_erase(s,glist);
+}
+
+/* can we use the normal text save function ?? */
+/*
+static void imagebutton_save(t_gobj *z, t_binbuf *b)
+{
+ t_imagebutton *x = (t_imagebutton *)z;
+ binbuf_addv(b, "ssiissi", gensym("#X"),gensym("obj"),
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_image,x->x_type);
+ binbuf_addv(b, ";");
+}
+*/
+
+
+static void imagebutton_size(t_imagebutton* x,t_floatarg w,t_floatarg h) {
+ x->width = w;
+ x->height = h;
+}
+
+static void imagebutton_color(t_imagebutton* x,t_symbol* col)
+{
+/* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang ..
+ so color black does the same as bang, but doesn't forward the bang
+*/
+}
+
+/*
+static void imagebutton_open(t_gobj *z,t_symbol* file)
+{
+ t_imagebutton* x = (t_imagebutton*)z;
+ const char *fname;
+ int oldtype=x->x_type;
+
+
+ fname=imagebutton_get_filename(x,file->s_name);
+ if(fname){
+ x->x_image=file;
+ x->x_type=0;
+ if(glist_isvisible(x->glist)) {
+ if(!x->x_localimage) {
+ sys_vgui("image create photo img%x\n",x);
+ x->x_localimage=1;
+ }
+ sys_vgui("img%x blank\n",x);
+ sys_vgui("img%x configure -file %s\n",x,fname);
+ if(oldtype) sys_vgui(".x%x.c itemconfigure %xS -image img%x\n",
+ glist_getcanvas(x->glist),x,x);
+ }
+ }
+}
+ */
+
+static void imagebutton_imagesize_callback(t_imagebutton *x, t_float w, t_float h) {
+ DEBUG(post("received w %f h %f",w,h);)
+ x->width = w;
+ x->height = h;
+ canvas_fixlinesfor(glist_getcanvas(x->glist),(t_text*) x);
+}
+
+
+static void imagebutton_free(t_imagebutton *x) {
+
+ // check first if variable has been unset and image is unused
+ // then delete image and unset variable
+ DEBUG(sys_vgui("pd [concat DEBUG b in use [image inuse %x_imagebutton] \\;]\n",x->image_b);)
+ DEBUG(sys_vgui("pd [concat DEBUG a in use [image inuse %x_imagebutton] \\;]\n",x->image_a);)
+
+ sys_vgui("if { [info exists %x_imagebutton] == 1 && [image inuse %x_imagebutton] == 0} { image delete %x_imagebutton \n unset %x_imagebutton\n} \n",x->image_b,x->image_b,x->image_b,x->image_b);
+ sys_vgui("if { [info exists %x_imagebutton] == 1 && [image inuse %x_imagebutton] == 0} { image delete %x_imagebutton \n unset %x_imagebutton\n} \n",x->image_a,x->image_a,x->image_a,x->image_a);
+
+ DEBUG(sys_vgui("pd [concat DEBUG b exists [info exists %x_imagebutton] \\;]\n",x->image_b);)
+ DEBUG(sys_vgui("pd [concat DEBUG a exists [info exists %x_imagebutton] \\;]\n",x->image_a);)
+
+ if (x->receive) {
+ pd_unbind(&x->x_obj.ob_pd,x->receive);
+ }
+ clock_free(x->clock_flash);
+ clock_free(x->clock_brk);
+
+}
+
+
+static void *imagebutton_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_imagebutton *x = (t_imagebutton *)pd_new(imagebutton_class);
+
+ x->glist = (t_glist*) canvas_getcurrent();
+
+ // Set up a callback to get the size
+ x->width = 10;
+ x->height = 10;
+
+ x->flashing = 0;
+
+ x->image_a = NULL;
+ x->image_b = NULL;
+
+ t_symbol* image_a = NULL;
+ t_symbol* image_b = NULL;
+
+ const char *fname;
+
+ // CREATE IMAGES
+ // images are only created if they have not been created yet
+ // we use the symbol pointer to distinguish between image files
+
+
+ if ( argc && (argv)->a_type == A_SYMBOL ) {
+ image_a= atom_getsymbol(argv);
+ fname = imagebutton_get_filename(x,image_a->s_name); // Get image file path
+ if (fname) {
+ x->image_a = gensym(fname);
+ //sys_vgui("set %x_a \"%s\" \n",x,fname);
+ // Create the image only if the class has not already loaded the same image (with the same symbolic path name)
+ sys_vgui("if { [info exists %x_imagebutton] == 0} { image create photo %x_imagebutton -file \"%s\"\n set %x_imagebutton 1\n} \n",x->image_a,x->image_a,fname,x->image_a);
+ //sys_vgui("pd [concat test %x_imagebutton \\;]\n",x->image_a);
+ }
+ }
+
+
+
+ if ( argc > 1 && (argv+1)->a_type == A_SYMBOL ) {
+ image_b= atom_getsymbol(argv+1);
+ fname = imagebutton_get_filename(x,image_b->s_name); // Get image file path
+ if (fname) {
+ x->image_b = gensym(fname);
+ //sys_vgui("set %x_b \"%s\" \n",x,fname);
+ sys_vgui("if { [info exists %x_imagebutton] == 0} { image create photo %x_imagebutton -file \"%s\"\n set %x_imagebutton 1\n} \n",x->image_b,x->image_b,fname,x->image_b);
+ //sys_vgui("pd [concat test %x_imagebutton \\;]\n",x->image_b);
+ }
+ }
+
+ if (image_a == NULL || image_b == NULL) {
+ pd_error(x,"[imagebutton] requires two gif images");
+ return NULL;
+ }
+ char buf[MAXPDSTRING];
+ sprintf(buf, "#%lx", (long)x);
+ x->receive = gensym(buf);
+ pd_bind(&x->x_obj.ob_pd, x->receive );
+
+ x->clock_flash = clock_new(x, (t_method)imagebutton_flash_timeout);
+ x->clock_brk = clock_new(x, (t_method)imagebutton_brk_timeout);
+
+
+ x->outlet = outlet_new(&x->x_obj, &s_float);
+
+
+ return (x);
+
+}
+
+void imagebutton_setup(void)
+{
+ imagebutton_class = class_new(gensym("imagebutton"), (t_newmethod)imagebutton_new, (t_method)imagebutton_free,
+ sizeof(t_imagebutton),0, A_GIMME,0);
+
+ class_addmethod(imagebutton_class, (t_method)imagebutton_imagesize_callback,\
+ gensym("_imagesize"), A_DEFFLOAT, A_DEFFLOAT, 0);
+
+
+/*
+ class_addmethod(imagebutton_class, (t_method)imagebutton_size, gensym("size"),
+ A_FLOAT, A_FLOAT, 0);
+
+ class_addmethod(imagebutton_class, (t_method)imagebutton_color, gensym("color"),
+ A_SYMBOL, 0);
+*/
+ /*
+ class_addmethod(imagebutton_class, (t_method)imagebutton_open, gensym("open"),
+ A_SYMBOL, 0);
+ */
+ /*
+ class_addmethod(imagebutton_class, (t_method)imagebutton_set, gensym("set"),
+ A_SYMBOL, 0);
+ */
+ /*
+ class_addmethod(imagebutton_class, (t_method)imagebutton_load, gensym("load"),
+ A_SYMBOL, A_SYMBOL, 0);
+*/
+
+ imagebutton_widgetbehavior.w_getrectfn = imagebutton_getrect;
+ imagebutton_widgetbehavior.w_displacefn = imagebutton_displace;
+ imagebutton_widgetbehavior.w_selectfn = imagebutton_select;
+ imagebutton_widgetbehavior.w_activatefn = imagebutton_activate;
+ imagebutton_widgetbehavior.w_deletefn = imagebutton_delete;
+ imagebutton_widgetbehavior.w_visfn = imagebutton_vis;
+
+ imagebutton_widgetbehavior.w_clickfn = (t_clickfn)imagebutton_click;
+
+
+#if PD_MINOR_VERSION < 37
+ imagebutton_widgetbehavior.w_propertiesfn = NULL;
+ //imagebutton_widgetbehavior.w_savefn = imagebutton_save;
+#endif
+
+
+ class_setwidget(imagebutton_class,&imagebutton_widgetbehavior);
+#if PD_MINOR_VERSION >= 37
+ // class_setsavefn(imagebutton_class,&imagebutton_save);
+#endif
+
+}
+
+
diff --git a/test/pak.c b/test/pak.c
deleted file mode 100644
index ad1cf73..0000000
--- a/test/pak.c
+++ /dev/null
@@ -1,379 +0,0 @@
-static t_class *pak_class;
-static t_class *pak_inlet_class;
-
-typedef struct _pak
-{
- t_object x_obj;
- t_int x_n; // number of args
- t_atom *x_vec; // input values
- t_int x_nptr; // number of pointers
- t_gpointer *x_gpointer; // the pointers
- t_atom *x_outvec; // space for output values
- int count;
- struct _pak_inlet **proxy;
- t_inlet **in;
-} t_pak;
-
-
-
-typedef struct _pak_inlet
-{
- t_pd p_pd;
- t_pack *master;
- int id;
- t_symbol* type;
-} t_pak_inlet;
-
-
-static void *pak_new(t_symbol *s, int argc, t_atom *argv)
-{
- t_pak *x = (t_pak *)pd_new(pak_class);
- t_atom defarg[2], *vap, *vec, *vp;
- t_gpointer *gp;
- int nptr = 0;
- int i;
- if (!argc)
- {
- argv = defarg;
- argc = 2;
- SETFLOAT(&defarg[0], 0);
- SETFLOAT(&defarg[1], 0);
- }
-
- x->x_n = argc;
- vec = x->x_vec = (t_atom *)getbytes(argc * sizeof(*x->x_vec));
- x->x_outvec = (t_atom *)getbytes(argc * sizeof(*x->x_outvec));
-
- for (i = argc, ap = argv; i--; ap++)
- if (ap->a_type == A_SYMBOL && *ap->a_w.w_symbol->s_name == 'p')
- nptr++;
-
- gp = x->x_gpointer = (t_gpointer *)t_getbytes(nptr * sizeof (*gp));
- x->x_nptr = nptr;
-
-
- // Create inlet proxys
- x->count = argc - 1;
- if (x->count < 0) x->count = 0;
- x->in = (t_inlet **)getbytes(x->count * sizeof(t_inlet *));
- x->proxy = (t_pak_inlet**)getbytes(x->count * sizeof(t_pak_inlet*));
- //
-
- /*
-
- for (n = 0; n < x->count; n++) {
- x->proxy[n]=(t_pak_inlet*)pd_new(pak_inlet_class);
- x->proxy[n]->master = x;
- x->proxy[n]->id=n;
- x->in[n] = inlet_new ((t_object*)x, (t_pd*)x->proxy[n], 0,0);
- }
-
- */
-
- int n;
- for (i = 0, vp = x->x_vec, ap = argv; i < argc; i++, ap++, vp++)
- {
- n = i-1;
- if (ap->a_type == A_FLOAT)
- {
- *vp = *ap;
- if (i) {
- //floatinlet_new(&x->x_obj, &vp->a_w.w_float);
- x->proxy[n]=(t_pak_inlet*)pd_new(pak_inlet_class);
- x->proxy[n]->master = x;
- x->proxy[n]->id=n;
- x->proxy[n]->typr = &s_float;
- x->in[n] = inlet_new ((t_object*)x, (t_pd*)x->proxy[n], 0,0);
- }
- }
- else if (ap->a_type == A_SYMBOL)
- {
- char c = *ap->a_w.w_symbol->s_name;
- if (c == 's')
- {
- SETSYMBOL(vp, &s_symbol);
- if (i) symbolinlet_new(&x->x_obj, &vp->a_w.w_symbol);
- }
- else if (c == 'p')
- {
- vp->a_type = A_POINTER;
- vp->a_w.w_gpointer = gp;
- gpointer_init(gp);
- if (i) pointerinlet_new(&x->x_obj, gp);
- gp++;
- }
- else
- {
- if (c != 'f') pd_error(x, "pak: %s: bad type",
- ap->a_w.w_symbol->s_name);
- SETFLOAT(vp, 0);
- if (i) floatinlet_new(&x->x_obj, &vp->a_w.w_float);
- }
- }
- }
-
-
-
-
-
-
-
- outlet_new(&x->x_obj, &s_list);
- return (x);
-}
-
-static void pak_bang(t_pak *x)
-{
- int i, reentered = 0, size = x->x_n * sizeof (t_atom);
- t_gpointer *gp;
- t_atom *outvec;
- for (i = x->x_nptr, gp = x->x_gpointer; i--; gp++)
- if (!gpointer_check(gp, 1))
- {
- pd_error(x, "pak: stale pointer");
- return;
- }
- // reentrancy protection. The first time through use the pre-allocated
- // x_outvec; if we're reentered we have to allocate new memory.
- if (!x->x_outvec)
- {
- // LATER figure out how to deal with reentrancy and pointers...
- if (x->x_nptr)
- post("pak_bang: warning: reentry with pointers unprotected");
- outvec = t_getbytes(size);
- reentered = 1;
- }
- else
- {
- outvec = x->x_outvec;
- x->x_outvec = 0;
- }
- memcpy(outvec, x->x_vec, size);
- outlet_list(x->x_obj.ob_outlet, &s_list, x->x_n, outvec);
- if (reentered)
- t_freebytes(outvec, size);
- else x->x_outvec = outvec;
-}
-
-static void pak_pointer(t_pak *x, t_gpointer *gp)
-{
- if (x->x_vec->a_type == A_POINTER)
- {
- gpointer_unset(x->x_gpointer);
- *x->x_gpointer = *gp;
- if (gp->gp_stub) gp->gp_stub->gs_refcount++;
- pak_bang(x);
- }
- else pd_error(x, "pak_pointer: wrong type");
-}
-
-static void pak_float(t_pak *x, t_float f)
-{
- if (x->x_vec->a_type == A_FLOAT)
- {
- x->x_vec->a_w.w_float = f;
- pak_bang(x);
- }
- else pd_error(x, "pak_float: wrong type");
-}
-
-static void pak_symbol(t_pak *x, t_symbol *s)
-{
- if (x->x_vec->a_type == A_SYMBOL)
- {
- x->x_vec->a_w.w_symbol = s;
- pak_bang(x);
- }
- else pd_error(x, "pak_symbol: wrong type");
-}
-
-static void pak_list(t_pak *x, t_symbol *s, int ac, t_atom *av)
-{
- obj_list(&x->x_obj, 0, ac, av);
-}
-
-static void pak_anything(t_pak *x, t_symbol *s, int ac, t_atom *av)
-{
- t_atom *av2 = (t_atom *)getbytes((ac + 1) * sizeof(t_atom));
- int i;
- for (i = 0; i < ac; i++)
- av2[i + 1] = av[i];
- SETSYMBOL(av2, s);
- obj_list(&x->x_obj, 0, ac+1, av2);
- freebytes(av2, (ac + 1) * sizeof(t_atom));
-}
-
-
-static void pak_inlet(t_pak *y, t_symbol *s, int argc, t_atom *argv)
-{
- t_mux*x=y->p_master;
- if(y->id==x->i_selected)
- outlet_anything(x->x_obj.ob_outlet, s, argc, argv);
-}
-
-
-static void pak_free(t_pak *x)
-{
- t_gpointer *gp;
- int i;
- for (gp = x->x_gpointer, i = x->x_nptr; i--; gp++)
- gpointer_unset(gp);
- freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
- freebytes(x->x_outvec, x->x_n * sizeof(*x->x_outvec));
- freebytes(x->x_gpointer, x->x_nptr * sizeof(*x->x_gpointer));
-
- // Free proxys
- const int count = x->count;
-
- if(x->in && x->proxy){
- int n=0;
- for(n=0; n<count; n++){
- if(x->in[n]){
- inlet_free(x->in[n]);
- }
- x->in[n]=0;
- if(x->proxy[n]){
- t_pak_inlet *y=x->proxy[n];
- y->master=0;
- y->id=0;
- pd_free(&y->p_pd);
- }
- x->proxy[n]=0;
- }
- freebytes(x->in, x->count * sizeof(t_inlet *));
- freebytes(x->proxy, x->count * sizeof(t_pak_inlet*));
- }
-
-
-}
-
-static void pak_setup(void)
-{
- pak_class = class_new(gensym("pak"), (t_newmethod)pak_new,
- (t_method)pak_free, sizeof(t_pak), 0, A_GIMME, 0);
- class_addbang(pak_class, pak_bang);
- class_addpointer(pak_class, pak_pointer);
- class_addfloat(pak_class, pak_float);
- class_addsymbol(pak_class, pak_symbol);
- class_addlist(pak_class, pak_list);
- class_addanything(pak_class, pak_anything);
-
- // Setup proxies
-
- pak_inlet_class = class_new(0, 0, 0, sizeof(t_pak_inlet),CLASS_PD | CLASS_NOINLET, 0);
- class_addanything(pak_inlet_class, pak_inlet);
-
-}
-
-
-
-//////////////// MULTIPLEX //////////////
-
-
-/*
-
-
-
-static t_class *mux_class;
-static t_class *muxproxy_class;
-
-typedef struct _mux
-{
- t_object x_obj;
- struct _muxproxy **x_proxy;
-
- int i_count;
- int i_selected;
- t_inlet **in;
-} t_mux;
-
-
-typedef struct _muxproxy
-{
- t_pd p_pd;
- t_mux *p_master;
- int id;
-} t_muxproxy;
-
-static void mux_select(t_mux *x, t_float f)
-{
- x->i_selected=f;
-}
-
-static void mux_anything(t_muxproxy *y, t_symbol *s, int argc, t_atom *argv)
-{
- t_mux*x=y->p_master;
- if(y->id==x->i_selected)
- outlet_anything(x->x_obj.ob_outlet, s, argc, argv);
-}
-
-static void *mux_new(t_symbol *s, int argc, t_atom *argv)
-{
- int n = (argc < 2)?2:argc;
- t_mux *x = (t_mux *)pd_new(mux_class);
-
- x->i_selected=0;
- x->i_count = n;
- x->in = (t_inlet **)getbytes(x->i_count * sizeof(t_inlet *));
- x->x_proxy = (t_muxproxy**)getbytes(x->i_count * sizeof(t_muxproxy*));
-
- for (n = 0; n<x->i_count; n++) {
- x->x_proxy[n]=(t_muxproxy*)pd_new(muxproxy_class);
- x->x_proxy[n]->p_master = x;
- x->x_proxy[n]->id=n;
- x->in[n] = inlet_new ((t_object*)x, (t_pd*)x->x_proxy[n], 0,0);
- }
-
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym(""));
-
- outlet_new(&x->x_obj, 0);
- return (x);
-}
-
-static void mux_free(t_mux*x){
- const int count = x->i_count;
-
- if(x->in && x->x_proxy){
- int n=0;
- for(n=0; n<count; n++){
- if(x->in[n]){
- inlet_free(x->in[n]);
- }
- x->in[n]=0;
- if(x->x_proxy[n]){
- t_muxproxy *y=x->x_proxy[n];
- y->p_master=0;
- y->id=0;
- pd_free(&y->p_pd);
- }
- x->x_proxy[n]=0;
- }
- freebytes(x->in, x->i_count * sizeof(t_inlet *));
- freebytes(x->x_proxy, x->i_count * sizeof(t_muxproxy*));
- }
-
- // pd_free(&y->p_pd);
-}
-
-void multiplex_setup(void)
-{
- mux_class = class_new(gensym("multiplex"), (t_newmethod)mux_new,
- (t_method)mux_free, sizeof(t_mux), CLASS_NOINLET, A_GIMME, 0);
- class_addcreator((t_newmethod)mux_new, gensym("mux"), A_GIMME, 0);
-
- class_addmethod (mux_class, (t_method)mux_select, gensym(""), A_DEFFLOAT, 0);
-
- muxproxy_class = class_new(0, 0, 0,
- sizeof(t_muxproxy),
- CLASS_PD | CLASS_NOINLET, 0);
- class_addanything(muxproxy_class, mux_anything);
-
-
- zexy_register("multiplex");
-}
-
-void mux_setup(void)
-{
- multiplex_setup();
-}
-*/
diff --git a/test/test.c b/test/test.c
deleted file mode 100644
index 9c31307..0000000
--- a/test/test.c
+++ /dev/null
@@ -1,97 +0,0 @@
-
-
-//#include "tof.h"
-//#include "param.h"
-#include "m_pd.h"
-#include "g_canvas.h"
-
-static t_class *test_class;
-
-
-typedef struct _test
-{
- t_object x_obj;
- t_outlet* outlet;
- t_symbol* name;
- t_canvas* canvas;
- //t_symbol* target;
- //t_class* empty_s;
- //t_symbol* root;
-
-} t_test;
-
-
-
-// Dump out
-static void test_bang(t_test *x) {
- t_atom a;
- if (x->canvas) {
-
- SETFLOAT(&a,1);
- pd_typedmess((t_pd*)x->canvas,gensym("vis"),1,&a);
- }
-
-}
-
-
-
-static void test_free(t_test *x)
-{
- if (x->canvas) {
- //post("Deleting it");
- pd_free((t_pd *)x->canvas);
- }
- x->canvas = NULL;
-}
-
-
-static void *test_new(t_symbol *s, int ac, t_atom *av) {
- t_test *x = (t_test *)pd_new(test_class);
-
- // create a new canvas
- x->name = gensym("xiu");
-
- t_atom a;
- SETSYMBOL(&a, x->name);
- pd_typedmess(&pd_objectmaker,gensym("pd"),1,&a);
-
- x->canvas = (t_canvas*) pd_newest();
-
- // From this point on, we are hoping the "pd" object has been created
-
- // Change name to match pd's canvas naming scheme
- x->name = gensym("pd-xiu");
-
-
-
- // Hide the window (stupid way of doing this)
- if (x->canvas) {
- SETFLOAT(&a,0);
- pd_typedmess((t_pd*)x->canvas,gensym("vis"),1,&a);
- }
-
- // Try to change its name
- //canvas_setargs(int argc, t_atom *argv);
-
- x->outlet = outlet_new(&x->x_obj, &s_list);
-
- return (x);
-}
-
-void test_setup(void) {
- test_class = class_new(gensym("test"),
- (t_newmethod)test_new, (t_method)test_free,
- sizeof(t_test), 0, A_GIMME, 0);
-
- class_addbang(test_class, test_bang);
- //class_addsymbol(test_class, test_symbol);
-
- //class_addmethod(test_class, (t_method) test_values, gensym("values"), A_DEFSYMBOL,0);
-
- //class_addmethod(test_class, (t_method) test_guis, gensym("guis"), A_DEFSYMBOL,0);
- //class_addmethod(test_class, (t_method) test_updateguis, gensym("updateguis"), A_DEFSYMBOL,0);
-
-
- //class_addmethod(test_class, (t_method) test_update_guis, gensym("update"), A_DEFSYMBOL,0);
-
-}
diff --git a/test/to_ascii_code-help.pd b/test/to_ascii_code-help.pd
new file mode 100644
index 0000000..276bd99
--- /dev/null
+++ b/test/to_ascii_code-help.pd
@@ -0,0 +1,13 @@
+#N canvas 1371 321 506 219 10;
+#X msg 108 32 test;
+#X msg 262 34 1234;
+#X obj 95 74 tof/to_ascii_code 13;
+#X msg 173 36 list abcdef;
+#X obj 95 115 print codes;
+#X obj 214 115 print length;
+#X text 234 73 Optionnal argument: append ascii code;
+#X connect 0 0 2 0;
+#X connect 1 0 2 0;
+#X connect 2 0 4 0;
+#X connect 2 1 5 0;
+#X connect 3 0 2 0;
diff --git a/test/to_ascii_code.c b/test/to_ascii_code.c
new file mode 100644
index 0000000..8aa3155
--- /dev/null
+++ b/test/to_ascii_code.c
@@ -0,0 +1,97 @@
+#include "m_pd.h"
+
+// Common string to all objects
+static char* to_ascii_code_text;
+// Common binbuf to all objects
+static t_binbuf* to_ascii_code_binbuf;
+
+typedef struct _to_ascii_code
+{
+
+ t_object x_ob;
+ int eof_is_set;
+ int eof;
+ t_outlet* outlet_left;
+ //t_outlet* outlet_right;
+} t_to_ascii_code;
+
+static t_class *to_ascii_code_class;
+
+static void to_ascii_code_bang(t_to_ascii_code *x) {
+ // Do nothing
+}
+
+
+static void to_ascii_code_anything(t_to_ascii_code *x, t_symbol *s, int ac, t_atom *av) {
+
+ binbuf_clear(to_ascii_code_binbuf);
+ // Add selector if it is not standard
+ if ( s != &s_list && s != &s_float && s != &s_symbol && s != &s_) {
+ t_atom a;
+ SETSYMBOL(&a, s);
+ binbuf_add(to_ascii_code_binbuf,1,&a);
+ }
+ // Add all the atoms to the binbuf
+ binbuf_add(to_ascii_code_binbuf, ac, av);
+
+
+
+ // Get the contents as a text
+ int size=0;
+ binbuf_gettext(to_ascii_code_binbuf, &to_ascii_code_text, &size); //void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp);
+
+ // Convert to a list of floats
+
+ t_atom *list_floats = getbytes((size+1)*sizeof(*list_floats)); // Add some space for the eof character
+ int i;
+ for ( i=0; i < size; i++ ) {
+ SETFLOAT(list_floats+i,(t_float)to_ascii_code_text[i]);
+ }
+ if ( x->eof_is_set ) { // Append eof if set
+ SETFLOAT(list_floats+size, x->eof);
+ //outlet_float(x->outlet_right,size+1);
+ outlet_list(x->outlet_left,&s_list,size+1,list_floats);
+ } else {
+ //outlet_float(x->outlet_right,size);
+ outlet_list(x->outlet_left,&s_list,size,list_floats);
+ }
+ freebytes(list_floats, (size+1)*sizeof(*list_floats));
+
+}
+
+
+static void *to_ascii_code_new(t_symbol *s, int ac, t_atom *av)
+{
+ t_to_ascii_code *x = (t_to_ascii_code *)pd_new(to_ascii_code_class);
+
+ // set eof if eof is set
+ if ( ac && ((av)->a_type == A_FLOAT)) {
+ x->eof = (int) atom_getfloat(av);
+ x->eof_is_set = 1;
+ } else {
+ x->eof_is_set = 0;
+ }
+
+ x->outlet_left = outlet_new(&x->x_ob, &s_list);
+ //x->outlet_right = outlet_new(&x->x_ob, &s_float);
+
+ return (x);
+}
+
+void to_ascii_code_setup(void)
+{
+ // create binbuf (no need to ever free)
+ to_ascii_code_binbuf = binbuf_new();
+
+ // create text (no need to ever free)
+ to_ascii_code_text = getbytes(MAXPDSTRING*sizeof(*to_ascii_code_text));
+
+ to_ascii_code_class = class_new(gensym("to_ascii_code"),
+ (t_newmethod)to_ascii_code_new, 0,
+ sizeof(t_to_ascii_code), 0, A_GIMME, 0);
+
+ class_addbang(to_ascii_code_class, to_ascii_code_bang);
+ class_addanything(to_ascii_code_class, to_ascii_code_anything);
+
+
+ }
diff --git a/test/tokenArgs.c b/test/tokenArgs.c
deleted file mode 100644
index 80d8c16..0000000
--- a/test/tokenArgs.c
+++ /dev/null
@@ -1,80 +0,0 @@
-
-
-#include "../src/tof.h"
-
-
-static t_class *tokenArgs_class;
-
-
-typedef struct _tokenArgs
-{
- t_object x_obj;
- t_outlet* outlet;
- t_canvas* canvas;
- char token;
- int size;
- int ac;
- t_atom* av;
-} t_tokenArgs;
-
-
-
-// Dump out
-static void tokenArgs_bang(t_tokenArgs *x) {
-
- int ac_a;
- t_atom* av_a;
- t_symbol* selector_a;
- int iter = 0 ;
- while ( tof_next_tagged_argument(x->token, x->ac, x->av, &ac_a, &av_a,&iter)) {
- tof_set_selector(&selector_a,&ac_a,&av_a);
- outlet_anything(x->outlet, selector_a, ac_a, av_a);
- }
-
-}
-
-
-static void tokenArgs_free(t_tokenArgs *x)
-{
- freebytes(x->av,x->ac*sizeof(*(x->av)));
-}
-
-
-static void *tokenArgs_new(t_symbol *s) {
- t_tokenArgs *x = (t_tokenArgs *)pd_new(tokenArgs_class);
-
-
- x->token = s->s_name[0];
-
- //x->canvas = tof_get_canvas();
- // I guess the canvas is currently set :)
- int ac;
- t_atom* av;
- canvas_getargs(&ac, &av);
-
- x->ac = ac;
- x->av = getbytes(x->ac * sizeof(*(x->av)));
- tof_copy_atoms(av,x->av,x->ac);
-
- x->outlet = outlet_new(&x->x_obj, &s_list);
-
- return (x);
-}
-
-void tokenArgs_setup(void) {
- tokenArgs_class = class_new(gensym("tokenArgs"),
- (t_newmethod)tokenArgs_new, (t_method)tokenArgs_free,
- sizeof(t_tokenArgs), 0, A_DEFSYMBOL, 0);
-
- class_addbang(tokenArgs_class, tokenArgs_bang);
- //class_addsymbol(tokenArgs_class, tokenArgs_symbol);
-
- //class_addmethod(tokenArgs_class, (t_method) tokenArgs_values, gensym("values"), A_DEFSYMBOL,0);
-
- //class_addmethod(tokenArgs_class, (t_method) tokenArgs_guis, gensym("guis"), A_DEFSYMBOL,0);
- //class_addmethod(tokenArgs_class, (t_method) tokenArgs_updateguis, gensym("updateguis"), A_DEFSYMBOL,0);
-
-
- //class_addmethod(tokenArgs_class, (t_method) tokenArgs_update_guis, gensym("update"), A_DEFSYMBOL,0);
-
-}