aboutsummaryrefslogtreecommitdiff
path: root/grid
diff options
context:
space:
mode:
Diffstat (limited to 'grid')
-rw-r--r--grid/CHANGES.LOG10
-rw-r--r--grid/INSTALL15
-rw-r--r--grid/Makefile83
-rw-r--r--grid/README19
-rw-r--r--grid/g_grid.h36
-rw-r--r--grid/grid-patch.diff76
-rw-r--r--grid/grid.c670
-rw-r--r--grid/grid.tk204
-rw-r--r--grid/grid.tk2c164
-rw-r--r--grid/grid2.c539
-rw-r--r--grid/help-grid.pd198
-rwxr-xr-xgrid/tk2c.bash24
12 files changed, 2038 insertions, 0 deletions
diff --git a/grid/CHANGES.LOG b/grid/CHANGES.LOG
new file mode 100644
index 0000000..c4d8211
--- /dev/null
+++ b/grid/CHANGES.LOG
@@ -0,0 +1,10 @@
+0.4
+ Added functions bang, values, valuemotion, xvalues, xvaluemotion made by Maurizio Umberto Puxeddu
+ Integrated patch from Joseph A. Sarlo for connections
+0.3
+ Fixed "goto x y" message
+ ( hall of shame contest : confusion between absolute and relative coordinates )
+0.2
+ Added "goto x y" message
+0.1
+ first implementation
diff --git a/grid/INSTALL b/grid/INSTALL
new file mode 100644
index 0000000..22c4df6
--- /dev/null
+++ b/grid/INSTALL
@@ -0,0 +1,15 @@
+untar in /my/pd/dir/externs
+
+cd /my/pd/dir/externs/grid
+
+make clean
+
+make
+
+make install
+
+open help-grid.pd
+
+Thanx for getting here.
+Yves/
+comments and bugs @ ydegoyon@free.fr
diff --git a/grid/Makefile b/grid/Makefile
new file mode 100644
index 0000000..7412ac0
--- /dev/null
+++ b/grid/Makefile
@@ -0,0 +1,83 @@
+NAME=grid
+CSYM=grid
+
+current: pd_linux
+
+# ----------------------- NT -----------------------
+
+pd_nt: $(NAME).dll
+
+.SUFFIXES: .dll
+
+PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo
+VC="C:\Program Files\Microsoft Visual Studio\Vc98"
+
+PDNTINCLUDE = /I. /I\tcl\include /I\ftp\pd\src /I$(VC)\include
+
+PDNTLDIR = $(VC)\lib
+PDNTLIB = $(PDNTLDIR)\libc.lib \
+ $(PDNTLDIR)\oldnames.lib \
+ $(PDNTLDIR)\kernel32.lib \
+ \ftp\pd\bin\pd.lib
+
+.c.dll:
+ cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c
+ link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB)
+
+# ----------------------- IRIX 5.x -----------------------
+
+pd_irix5: $(NAME).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
+
+# ----------------------- IRIX 6.x -----------------------
+
+pd_irix6: $(NAME).pd_irix6
+
+.SUFFIXES: .pd_irix6
+
+SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \
+ -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \
+ -Ofast=ip32
+
+.c.pd_irix6:
+ cc $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c
+ ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o
+ rm $*.o
+
+# ----------------------- LINUX i386 -----------------------
+
+pd_linux: $(NAME).pd_linux
+
+.SUFFIXES: .pd_linux
+
+LINUXCFLAGS = -DPD -DUNIX -DICECAST -O2 -funroll-loops -fomit-frame-pointer \
+ -Wall -W -Wno-shadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch #-Werror
+
+LINUXINCLUDE = -I../../src
+
+.c.pd_linux:
+ ./tk2c.bash < $*.tk > $*.tk2c
+ cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm
+ strip --strip-unneeded $*.pd_linux
+ rm -f $*.o ../$*.pd_linux
+ ln -s $*/$*.pd_linux ..
+
+# ----------------------------------------------------------
+
+install:
+ cp help-*.pd ../../doc/5.reference
+
+clean:
+ rm -f *.o *.pd_* so_locations
diff --git a/grid/README b/grid/README
new file mode 100644
index 0000000..fa0f1b7
--- /dev/null
+++ b/grid/README
@@ -0,0 +1,19 @@
+Version 0.01
+copyleft 2001 by Yves Degoyon
+tarballs and updates available @ http://ydegoyon.free.fr
+
+grid : 2-dimensional control object, ala "kaospad"
+
+To install grid, follow the steps from INSTALL
+
+This software is published under GPL terms.
+
+This is software with ABSOLUTELY NO WARRANTY.
+Use it at your OWN RISK. It's possible to damage e.g. hardware or your hearing
+due to a bug or for other reasons.
+We do not warrant that the program is free of infringement of any third-party
+patents.
+
+*****************************************************************************
+
+
diff --git a/grid/g_grid.h b/grid/g_grid.h
new file mode 100644
index 0000000..e58da9f
--- /dev/null
+++ b/grid/g_grid.h
@@ -0,0 +1,36 @@
+/* Copyright (c) 2002 Yves Degoyon
+* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* a header for grid which enables to control
+* 2 parameters with the mouse cursor
+*/
+
+#ifndef __G_GRID_H
+#define __G_GRID_H
+
+typedef struct _grid
+{
+ t_object x_obj;
+ t_glist *x_glist;
+ t_symbol *x_name;
+ t_outlet *x_xoutlet;
+ t_outlet *x_youtlet;
+ int x_height; /* height of the grid */
+ t_float x_min; /* minimum value of x */
+ t_float x_max; /* max value of x */
+ int x_width; /* width of the grid */
+ t_float y_min; /* minimum value of y */
+ t_float y_max; /* max value of y */
+ t_float x_current; /* x coordinate of current position */
+ t_float y_current; /* y coordinate of current position */
+ int x_selected; /* stores selected state */
+ int x_point; /* indicates if a point is plotted */
+ int x_grid; /* indicates if a grid is requested */
+ t_float x_xstep; /* sets the step ( grain ) for x */
+ t_float x_ystep; /* sets the step ( grain ) for y */
+ int x_xlines; /* number of vertical lines */
+ int x_ylines; /* number of horizontal lines */
+} t_grid;
+
+#endif
diff --git a/grid/grid-patch.diff b/grid/grid-patch.diff
new file mode 100644
index 0000000..b9972eb
--- /dev/null
+++ b/grid/grid-patch.diff
@@ -0,0 +1,76 @@
+--- ../grid-pristine/grid.c Mon Sep 16 15:29:14 2002
++++ grid.c Mon Sep 16 17:24:21 2002
+@@ -91,19 +91,22 @@
+ static void grid_draw_new(t_grid *x, t_glist *glist)
+ {
+ t_canvas *canvas=glist_getcanvas(glist);
++ char *tagRoot;
+
++ rtext_new(glist, (t_text *)x, glist->gl_editor->e_rtext, 0);
++ tagRoot = rtext_gettag(glist_findrtext(glist,(t_text *)x));
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -fill #124392 -tags %xGRID\n",
+ canvas, x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_obj.te_xpix + x->x_width, x->x_obj.te_ypix + x->x_height,
+ x);
+- GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -tags %xOUTL\n",
++ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -tags %so0\n",
+ canvas, x->x_obj.te_xpix, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+7, x->x_obj.te_ypix + x->x_height+2,
+- x);
+- GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -tags %xOUTR\n",
++ tagRoot);
++ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -tags %so1\n",
+ canvas, x->x_obj.te_xpix+x->x_width-7, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix + x->x_height+2,
+- x);
++ tagRoot);
+
+ if ( x->x_grid )
+ {
+@@ -136,17 +139,19 @@
+ static void grid_draw_move(t_grid *x, t_glist *glist)
+ {
+ t_canvas *canvas=glist_getcanvas(glist);
++ char *tagRoot;
+
++ tagRoot = rtext_gettag(glist_findrtext(glist,(t_text *)x));
+ GRID_SYS_VGUI7(".x%x.c coords %xGRID %d %d %d %d\n",
+ canvas, x,
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix+x->x_height);
+- GRID_SYS_VGUI7(".x%x.c coords %xOUTL %d %d %d %d\n",
+- canvas, x,
++ GRID_SYS_VGUI7(".x%x.c coords %so0 %d %d %d %d\n",
++ canvas, tagRoot,
+ x->x_obj.te_xpix, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+7, x->x_obj.te_ypix + x->x_height+2 );
+- GRID_SYS_VGUI7(".x%x.c coords %xOUTR %d %d %d %d\n",
+- canvas, x,
++ GRID_SYS_VGUI7(".x%x.c coords %so1 %d %d %d %d\n",
++ canvas, tagRoot,
+ x->x_obj.te_xpix+x->x_width-7, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix + x->x_height+2 );
+ if ( x->x_point )
+@@ -183,10 +188,12 @@
+ {
+ t_canvas *canvas=glist_getcanvas(glist);
+ int i;
++ char *tagRoot;
+
++ tagRoot = rtext_gettag(glist_findrtext(glist,(t_text *)x));
+ GRID_SYS_VGUI3(".x%x.c delete %xGRID\n", canvas, x);
+- GRID_SYS_VGUI3(".x%x.c delete %xOUTL\n", canvas, x);
+- GRID_SYS_VGUI3(".x%x.c delete %xOUTR\n", canvas, x);
++ GRID_SYS_VGUI3(".x%x.c delete %so0\n", canvas, tagRoot);
++ GRID_SYS_VGUI3(".x%x.c delete %so1\n", canvas, tagRoot);
+ if (x->x_grid)
+ {
+ for (i=1; i<x->x_xlines; i++ )
+@@ -203,6 +210,7 @@
+ GRID_SYS_VGUI3(".x%x.c delete %xPOINT\n", canvas, x);
+ x->x_point = 0;
+ }
++ rtext_free(glist_findrtext(glist, (t_text *)x));
+ }
+
+ static void grid_draw_select(t_grid* x,t_glist* glist)
diff --git a/grid/grid.c b/grid/grid.c
new file mode 100644
index 0000000..642d3ce
--- /dev/null
+++ b/grid/grid.c
@@ -0,0 +1,670 @@
+/* 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_grid.c written by Yves Degoyon 2002 */
+/* grid control object : two dimensionnal grid */
+/* thanks to Thomas Musil, Miller Puckette, Guenther Geiger and Krzystof Czaja */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <ctype.h>
+#include "m_imp.h"
+#include "g_canvas.h"
+#include "t_tk.h"
+#include "g_grid.h"
+
+#ifdef NT
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#define DEFAULT_GRID_WIDTH 200
+#define DEFAULT_GRID_HEIGHT 200
+#define DEFAULT_GRID_NBLINES 10
+
+t_widgetbehavior grid_widgetbehavior;
+static t_class *grid_class;
+static int gridcount=0;
+
+static int guidebug=0;
+static int pointsize = 5;
+
+static char *grid_version = "grid: version 0.4, written by Yves Degoyon (ydegoyon@free.fr)";
+
+#define GRID_SYS_VGUI2(a,b) if (guidebug) \
+ post(a,b);\
+ sys_vgui(a,b)
+
+#define GRID_SYS_VGUI3(a,b,c) if (guidebug) \
+ post(a,b,c);\
+ sys_vgui(a,b,c)
+
+#define GRID_SYS_VGUI4(a,b,c,d) if (guidebug) \
+ post(a,b,c,d);\
+ sys_vgui(a,b,c,d)
+
+#define GRID_SYS_VGUI7(a,b,c,d,e,f,g) if (guidebug) \
+ post(a,b,c,d,e,f,g );\
+ sys_vgui(a,b,c,d,e,f,g)
+
+#define GRID_SYS_VGUI9(a,b,c,d,e,f,g,h,i) if (guidebug) \
+ post(a,b,c,d,e,f,g,h,i );\
+ sys_vgui(a,b,c,d,e,f,g,h,i)
+
+/* drawing functions */
+static void grid_draw_update(t_grid *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int xpoint=x->x_current, ypoint=x->y_current;
+
+ // later : try to figure out what's this test for ??
+ // if (glist_isvisible(glist))
+ // {
+ // delete previous point if existing
+ if (x->x_point)
+ {
+ GRID_SYS_VGUI3(".x%x.c delete %xPOINT\n", canvas, x);
+ }
+
+ if ( x->x_current < x->x_obj.te_xpix ) xpoint = x->x_obj.te_xpix;
+ if ( x->x_current > x->x_obj.te_xpix + x->x_width - pointsize )
+ xpoint = x->x_obj.te_xpix + x->x_width - pointsize;
+ if ( x->y_current < x->x_obj.te_ypix ) ypoint = x->x_obj.te_ypix;
+ if ( x->y_current > x->x_obj.te_ypix + x->x_height - pointsize )
+ ypoint = x->x_obj.te_ypix + x->x_height - pointsize;
+ // draw the selected point
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -fill #FF0000 -tags %xPOINT\n",
+ canvas, xpoint, ypoint, xpoint+pointsize, ypoint+pointsize, x);
+ x->x_point = 1;
+ // }
+ // else
+ // {
+ // post( "grid : position updated in an invisible grid" );
+ // }
+}
+
+static void grid_draw_new(t_grid *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ char *tagRoot;
+
+ rtext_new(glist, (t_text *)x, glist->gl_editor->e_rtext, 0);
+ tagRoot = rtext_gettag(glist_findrtext(glist,(t_text *)x));
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -fill #124392 -tags %xGRID\n",
+ canvas, x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_obj.te_xpix + x->x_width, x->x_obj.te_ypix + x->x_height,
+ x);
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -tags %so0\n",
+ canvas, x->x_obj.te_xpix, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+7, x->x_obj.te_ypix + x->x_height+2,
+ tagRoot);
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -tags %so1\n",
+ canvas, x->x_obj.te_xpix+x->x_width-7, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix + x->x_height+2,
+ tagRoot);
+
+ if ( x->x_grid )
+ {
+ int xlpos = x->x_obj.te_xpix+x->x_width/x->x_xlines;
+ int ylpos = x->x_obj.te_ypix+x->x_height/x->x_ylines;
+ int xcount = 1;
+ int ycount = 1;
+ while ( xlpos < x->x_obj.te_xpix+x->x_width )
+ {
+ GRID_SYS_VGUI9(".x%x.c create line %d %d %d %d -fill #FFFFFF -tags %xLINE%d%d\n",
+ canvas, xlpos, x->x_obj.te_ypix,
+ xlpos, x->x_obj.te_ypix+x->x_height,
+ x, xcount, 0 );
+ xlpos+=x->x_width/x->x_xlines;
+ xcount++;
+ }
+ while ( ylpos < x->x_obj.te_ypix+x->x_height )
+ {
+ GRID_SYS_VGUI9(".x%x.c create line %d %d %d %d -fill #FFFFFF -tags %xLINE%d%d\n",
+ canvas, x->x_obj.te_xpix, ylpos,
+ x->x_obj.te_xpix+x->x_width, ylpos,
+ x, 0, ycount);
+ ylpos+=x->x_height/x->x_ylines;
+ ycount++;
+ }
+ }
+ canvas_fixlinesfor( canvas, (t_text*)x );
+}
+
+static void grid_draw_move(t_grid *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ char *tagRoot;
+
+ tagRoot = rtext_gettag(glist_findrtext(glist,(t_text *)x));
+ GRID_SYS_VGUI7(".x%x.c coords %xGRID %d %d %d %d\n",
+ canvas, x,
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix+x->x_height);
+ GRID_SYS_VGUI7(".x%x.c coords %so0 %d %d %d %d\n",
+ canvas, tagRoot,
+ x->x_obj.te_xpix, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+7, x->x_obj.te_ypix + x->x_height+2 );
+ GRID_SYS_VGUI7(".x%x.c coords %so1 %d %d %d %d\n",
+ canvas, tagRoot,
+ x->x_obj.te_xpix+x->x_width-7, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix + x->x_height+2 );
+ if ( x->x_point )
+ {
+ grid_draw_update(x, glist);
+ }
+ if ( x->x_grid )
+ {
+ int xlpos = x->x_obj.te_xpix+x->x_width/x->x_xlines;
+ int ylpos = x->x_obj.te_ypix+x->x_height/x->x_ylines;
+ int xcount = 1;
+ int ycount = 1;
+ while ( xlpos < x->x_obj.te_xpix+x->x_width )
+ {
+ GRID_SYS_VGUI9(".x%x.c coords %xLINE%d%d %d %d %d %d\n",
+ canvas, x, xcount, 0, xlpos, x->x_obj.te_ypix,
+ xlpos, x->x_obj.te_ypix + x->x_height);
+ xlpos+=x->x_width/x->x_xlines;
+ xcount++;
+ }
+ while ( ylpos < x->x_obj.te_ypix+x->x_height )
+ {
+ GRID_SYS_VGUI9(".x%x.c coords %xLINE%d%d %d %d %d %d\n",
+ canvas, x, 0, ycount, x->x_obj.te_xpix, ylpos,
+ x->x_obj.te_xpix + x->x_width, ylpos);
+ ylpos+=x->x_height/x->x_ylines;
+ ycount++;
+ }
+ }
+ canvas_fixlinesfor( canvas, (t_text*)x );
+}
+
+static void grid_draw_erase(t_grid* x,t_glist* glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ int i;
+ char *tagRoot;
+
+ tagRoot = rtext_gettag(glist_findrtext(glist,(t_text *)x));
+ GRID_SYS_VGUI3(".x%x.c delete %xGRID\n", canvas, x);
+ GRID_SYS_VGUI3(".x%x.c delete %so0\n", canvas, tagRoot);
+ GRID_SYS_VGUI3(".x%x.c delete %so1\n", canvas, tagRoot);
+ if (x->x_grid)
+ {
+ for (i=1; i<x->x_xlines; i++ )
+ {
+ GRID_SYS_VGUI4(".x%x.c delete %xLINE%d0\n", canvas, x, i);
+ }
+ for (i=1; i<x->x_ylines; i++ )
+ {
+ GRID_SYS_VGUI4(".x%x.c delete %xLINE0%d\n", canvas, x, i);
+ }
+ }
+ if (x->x_point)
+ {
+ GRID_SYS_VGUI3(".x%x.c delete %xPOINT\n", canvas, x);
+ x->x_point = 0;
+ }
+ rtext_free(glist_findrtext(glist, (t_text *)x));
+}
+
+static void grid_draw_select(t_grid* x,t_glist* glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ if(x->x_selected)
+ {
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+ /* sets the item in blue */
+ GRID_SYS_VGUI3(".x%x.c itemconfigure %xGRID -outline #0000FF\n", canvas, x);
+ }
+ else
+ {
+ pd_unbind(&x->x_obj.ob_pd, x->x_name);
+ GRID_SYS_VGUI3(".x%x.c itemconfigure %xGRID -outline #000000\n", canvas, x);
+ }
+}
+
+static void grid_output_current(t_grid* x)
+{
+ t_float xvalue, yvalue;
+ t_float xmodstep, ymodstep;
+
+ xvalue = x->x_min + (x->x_current - x->x_obj.te_xpix) * (x->x_max-x->x_min) / x->x_width ;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
+ xmodstep = ((float)((int)(xvalue*10000) % (int)(x->x_xstep*10000))/10000.);
+ xvalue = xvalue - xmodstep;
+ outlet_float( x->x_xoutlet, xvalue );
+
+ yvalue = x->y_max - (x->y_current - x->x_obj.te_ypix ) * (x->y_max-x->y_min) / x->x_height ;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
+ ymodstep = ((float)((int)(yvalue*10000) % (int)(x->x_ystep*10000))/10000.);
+ yvalue = yvalue - ymodstep;
+ outlet_float( x->x_youtlet, yvalue );
+}
+
+/* ------------------------ grid widgetbehaviour----------------------------- */
+
+
+static void grid_getrect(t_gobj *z, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ t_grid* x = (t_grid*)z;
+
+ *xp1 = x->x_obj.te_xpix;
+ *yp1 = x->x_obj.te_ypix;
+ *xp2 = x->x_obj.te_xpix+x->x_width;
+ *yp2 = x->x_obj.te_ypix+x->x_height;
+}
+
+static void grid_save(t_gobj *z, t_binbuf *b)
+{
+ t_grid *x = (t_grid *)z;
+
+ // post( "saving grid : %s", x->x_name->s_name );
+ binbuf_addv(b, "ssiissiffiffiffiiff", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ gensym("grid"), x->x_name, x->x_width, x->x_min,
+ x->x_max, x->x_height,
+ x->y_min, x->y_max,
+ x->x_grid, x->x_xstep,
+ x->x_ystep, x->x_xlines, x->x_ylines,
+ x->x_current, x->y_current );
+ binbuf_addv(b, ";");
+}
+
+static void grid_properties(t_gobj *z, t_glist *owner)
+{
+ char buf[800];
+ t_grid *x=(t_grid *)z;
+
+ sprintf(buf, "pdtk_grid_dialog %%s %s %d %.2f %.2f %d %.2f %.2f %d %.2f %.2f %d %d\n",
+ x->x_name->s_name, x->x_width, x->x_min, x->x_max, x->x_height,
+ x->y_min, x->y_max, x->x_grid, x->x_xstep, x->x_ystep,
+ x->x_xlines, x->x_ylines );
+ // post("grid_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
+}
+
+static void grid_select(t_gobj *z, t_glist *glist, int selected)
+{
+ t_grid *x = (t_grid *)z;
+
+ x->x_selected = selected;
+ grid_draw_select( x, glist );
+}
+
+static void grid_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_grid *x = (t_grid *)z;
+
+ if (vis)
+ {
+ grid_draw_new( x, glist );
+ grid_draw_update( x, glist );
+ grid_output_current(x);
+ }
+ else
+ {
+ grid_draw_erase( x, glist );
+ }
+}
+
+static void grid_dialog(t_grid *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if ( !x ) {
+ post( "grid : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 12 )
+ {
+ post( "grid : error in the number of arguments ( %d instead of 12 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_SYMBOL || argv[1].a_type != A_FLOAT ||
+ argv[2].a_type != A_FLOAT || argv[3].a_type != A_FLOAT ||
+ argv[4].a_type != A_FLOAT || argv[5].a_type != A_FLOAT ||
+ argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
+ argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ||
+ argv[10].a_type != A_FLOAT || argv[11].a_type != A_FLOAT ) {
+ post( "grid : wrong arguments" );
+ return;
+ }
+ x->x_name = argv[0].a_w.w_symbol;
+ x->x_width = (int)argv[1].a_w.w_float;
+ x->x_min = argv[2].a_w.w_float;
+ x->x_max = argv[3].a_w.w_float;
+ x->x_height = (int)argv[4].a_w.w_float;
+ x->y_min = argv[5].a_w.w_float;
+ x->y_max = argv[6].a_w.w_float;
+ x->x_grid = argv[7].a_w.w_float;
+ x->x_xstep = argv[8].a_w.w_float;
+ x->x_ystep = argv[9].a_w.w_float;
+ x->x_xlines = argv[10].a_w.w_float;
+ x->x_ylines = argv[11].a_w.w_float;
+ grid_draw_erase(x, x->x_glist);
+ grid_draw_new(x, x->x_glist);
+}
+
+static void grid_delete(t_gobj *z, t_glist *glist)
+{
+ canvas_deletelinesfor( glist_getcanvas(glist), (t_text *)z);
+}
+
+static void grid_displace(t_gobj *z, t_glist *glist, int dx, int dy)
+{
+ t_grid *x = (t_grid *)z;
+ int xold = x->x_obj.te_xpix;
+ int yold = x->x_obj.te_ypix;
+
+ // post( "grid_displace dx=%d dy=%d", dx, dy );
+
+ x->x_obj.te_xpix += dx;
+ x->x_current += dx;
+ x->x_obj.te_ypix += dy;
+ x->y_current += dy;
+ if(xold != x->x_obj.te_xpix || yold != x->x_obj.te_ypix)
+ {
+ grid_draw_move(x, x->x_glist);
+ }
+}
+
+static void grid_motion(t_grid *x, t_floatarg dx, t_floatarg dy)
+{
+ int xold = x->x_current;
+ int yold = x->y_current;
+
+ // post( "grid_motion dx=%f dy=%f", dx, dy );
+
+ x->x_current += dx;
+ x->y_current += dy;
+ if(xold != x->x_current || yold != x->y_current)
+ {
+ grid_output_current(x);
+ grid_draw_update(x, x->x_glist);
+ }
+}
+
+static int grid_click(t_gobj *z, struct _glist *glist,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
+{
+ t_grid* x = (t_grid *)z;
+
+ // post( "grid_click doit=%d x=%d y=%d", doit, xpix, ypix );
+ if ( doit)
+ {
+ x->x_current = xpix;
+ x->y_current = ypix;
+ grid_output_current(x);
+ grid_draw_update(x, glist);
+ glist_grab(glist, &x->x_obj.te_g, (t_glistmotionfn)grid_motion,
+ 0, xpix, ypix);
+ }
+ return (1);
+}
+
+static void grid_goto(t_grid *x, t_floatarg newx, t_floatarg newy)
+{
+ int xold = x->x_current;
+ int yold = x->y_current;
+
+ if ( newx > x->x_width-1 ) newx = x->x_width-1;
+ if ( newx < 0 ) newx = 0;
+ if ( newy > x->x_height-1 ) newy = x->x_height-1;
+ if ( newy < 0 ) newy = 0;
+
+ // post( "grid_set x=%f y=%f", newx, newy );
+
+ x->x_current = newx + x->x_obj.te_xpix;
+ x->y_current = newy + x->x_obj.te_ypix;
+ if(xold != x->x_current || yold != x->y_current)
+ {
+ grid_output_current(x);
+ grid_draw_update(x, x->x_glist);
+ }
+}
+
+static void grid_values(t_grid* x, t_floatarg xvalue, t_floatarg yvalue)
+{
+ int xold = x->x_current;
+ int yold = x->y_current;
+
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
+
+ x->x_current = x->x_obj.te_xpix + ((xvalue - x->x_min) / x->x_max) * x->x_width;
+
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
+
+ x->y_current = x->x_obj.te_ypix + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
+
+ if(xold != x->x_current || yold != x->y_current) {
+ grid_output_current(x);
+ grid_draw_update(x, x->x_glist);
+ }
+}
+
+static void grid_xvalues(t_grid* x, t_floatarg xvalue, t_floatarg yvalue)
+{
+ int xold = x->x_current;
+ int yold = x->y_current;
+
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
+
+ x->x_current = x->x_obj.te_xpix + ((xvalue - x->x_min) / x->x_max) * x->x_width;
+
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
+
+ x->y_current = x->x_obj.te_ypix + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
+
+ if(xold != x->x_current || yold != x->y_current) {
+ grid_draw_update(x, x->x_glist);
+ }
+}
+
+static void grid_valuemotion(t_grid* x, t_floatarg dx, t_floatarg dy)
+{
+ int xold = x->x_current;
+ int yold = x->y_current;
+ t_float xvalue, yvalue;
+
+ xvalue = x->x_min + (x->x_current - x->x_obj.te_xpix) * (x->x_max-x->x_min) / x->x_width ;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
+
+ yvalue = x->y_max - (x->y_current - x->x_obj.te_ypix ) * (x->y_max-x->y_min) / x->x_height ;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
+
+ xvalue += dx;
+ yvalue += dy;
+
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
+
+ x->x_current = x->x_obj.te_xpix + ((xvalue - x->x_min) / x->x_max) * x->x_width;
+
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
+
+ x->y_current = x->x_obj.te_ypix + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
+
+ if(xold != x->x_current || yold != x->y_current) {
+ grid_output_current(x);
+ grid_draw_update(x, x->x_glist);
+ }
+}
+
+static void grid_xvaluemotion(t_grid* x, t_floatarg dx, t_floatarg dy)
+{
+ int xold = x->x_current;
+ int yold = x->y_current;
+ t_float xvalue, yvalue;
+
+ xvalue = x->x_min + (x->x_current - x->x_obj.te_xpix) * (x->x_max-x->x_min) / x->x_width ;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
+
+ yvalue = x->y_max - (x->y_current - x->x_obj.te_ypix ) * (x->y_max-x->y_min) / x->x_height ;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
+
+ xvalue += dx;
+ yvalue += dy;
+
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
+
+ x->x_current = x->x_obj.te_xpix + ((xvalue - x->x_min) / x->x_max) * x->x_width;
+
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
+
+ x->y_current = x->x_obj.te_ypix + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
+
+ if(xold != x->x_current || yold != x->y_current) {
+ grid_draw_update(x, x->x_glist);
+ }
+}
+
+static void grid_bang(t_grid *x) {
+ grid_output_current(x);
+}
+
+static t_grid *grid_new(t_symbol *s, int argc, t_atom *argv)
+{
+ int i, zz;
+ t_grid *x;
+ t_pd *x2;
+ char *str;
+
+ // post( "grid_new : create : %s argc =%d", s->s_name, argc );
+
+ x = (t_grid *)pd_new(grid_class);
+ // new grid created from the gui
+ if ( argc != 0 )
+ {
+ if ( argc != 14 )
+ {
+ post( "grid : error in the number of arguments ( %d instead of 14 )", argc );
+ return NULL;
+ }
+ if ( argv[0].a_type != A_SYMBOL || argv[1].a_type != A_FLOAT ||
+ argv[2].a_type != A_FLOAT || argv[3].a_type != A_FLOAT ||
+ argv[4].a_type != A_FLOAT || argv[5].a_type != A_FLOAT ||
+ argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
+ argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ||
+ argv[10].a_type != A_FLOAT || argv[11].a_type != A_FLOAT ||
+ argv[12].a_type != A_FLOAT || argv[13].a_type != A_FLOAT ) {
+ post( "grid : wrong arguments" );
+ return NULL;
+ }
+
+ // update grid count
+ if (!strncmp((str = argv[0].a_w.w_symbol->s_name), "grid", 5)
+ && (zz = atoi(str + 5)) > gridcount)
+ {
+ gridcount = zz;
+ }
+ x->x_name = argv[0].a_w.w_symbol;
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+ x->x_width = argv[1].a_w.w_float;
+ x->x_min = argv[2].a_w.w_float;
+ x->x_max = argv[3].a_w.w_float;
+ x->x_height = argv[4].a_w.w_float;
+ x->y_min = argv[5].a_w.w_float;
+ x->y_max = argv[6].a_w.w_float;
+ x->x_grid = argv[7].a_w.w_float;
+ x->x_xstep = argv[8].a_w.w_float;
+ x->x_ystep = argv[9].a_w.w_float;
+ x->x_xlines = argv[10].a_w.w_float;
+ x->x_ylines = argv[11].a_w.w_float;
+ x->x_current = argv[12].a_w.w_float;
+ x->y_current = argv[13].a_w.w_float;
+ x->x_point = 1;
+ }
+ else
+ {
+ char buf[40];
+
+ sprintf(buf, "grid%d", ++gridcount);
+ s = gensym(buf);
+
+ x->x_name = s;
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+
+ x->x_width = DEFAULT_GRID_WIDTH;
+ x->x_min = 0;
+ x->x_max = DEFAULT_GRID_WIDTH - 1;
+ x->x_height = DEFAULT_GRID_HEIGHT;
+ x->y_min = 0;
+ x->y_max = DEFAULT_GRID_HEIGHT - 1;
+ x->x_grid = 1;
+ x->x_xstep = 1.0;
+ x->x_ystep = 1.0;
+ x->x_xlines = DEFAULT_GRID_NBLINES;
+ x->x_ylines = DEFAULT_GRID_NBLINES;
+ x->x_current = 0;
+ x->y_current = 0;
+
+ }
+
+ // common fields for new and restored grids
+ x->x_point = 0;
+ x->x_selected = 0;
+ x->x_glist = (t_glist *) canvas_getcurrent();
+ x->x_xoutlet = outlet_new(&x->x_obj, &s_float );
+ x->x_youtlet = outlet_new(&x->x_obj, &s_float );
+
+ // post( "grid_new name : %s width: %d height : %d", x->x_name->s_name, x->x_width, x->x_height );
+
+ return (x);
+}
+
+static void grid_free(t_grid *x)
+{
+ post( "grid~: freeing ressources [NULL]" );
+}
+
+void grid_setup(void)
+{
+#include "grid.tk2c"
+ post ( grid_version );
+ grid_class = class_new(gensym("grid"), (t_newmethod)grid_new,
+ (t_method)grid_free, sizeof(t_grid), 0, A_GIMME, 0);
+ class_addmethod(grid_class, (t_method)grid_click, gensym("click"),
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ class_addmethod(grid_class, (t_method)grid_motion, gensym("motion"),
+ A_FLOAT, A_FLOAT, 0);
+ class_addmethod(grid_class, (t_method)grid_bang, gensym("bang"), 0);
+ class_addmethod(grid_class, (t_method)grid_values, gensym("values"),
+ A_FLOAT, A_FLOAT, 0);
+ class_addmethod(grid_class, (t_method)grid_valuemotion, gensym("valuemotion"),
+ A_FLOAT, A_FLOAT, 0);
+ class_addmethod(grid_class, (t_method)grid_xvalues, gensym("xvalues"),
+ A_FLOAT, A_FLOAT, 0);
+ class_addmethod(grid_class, (t_method)grid_xvaluemotion, gensym("xvaluemotion"),
+ A_FLOAT, A_FLOAT, 0);
+ class_addmethod(grid_class, (t_method)grid_goto, gensym("goto"), A_FLOAT, A_FLOAT, 0);
+ class_addmethod(grid_class, (t_method)grid_dialog, gensym("dialog"), A_GIMME, 0);
+ grid_widgetbehavior.w_getrectfn = grid_getrect;
+ grid_widgetbehavior.w_displacefn = grid_displace;
+ grid_widgetbehavior.w_selectfn = grid_select;
+ grid_widgetbehavior.w_activatefn = NULL;
+ grid_widgetbehavior.w_deletefn = grid_delete;
+ grid_widgetbehavior.w_visfn = grid_vis;
+ grid_widgetbehavior.w_clickfn = grid_click;
+ grid_widgetbehavior.w_propertiesfn = grid_properties;
+ grid_widgetbehavior.w_savefn = grid_save;
+ class_setwidget(grid_class, &grid_widgetbehavior);
+ class_sethelpsymbol(grid_class, gensym("help-grid.pd"));
+}
diff --git a/grid/grid.tk b/grid/grid.tk
new file mode 100644
index 0000000..fb8d403
--- /dev/null
+++ b/grid/grid.tk
@@ -0,0 +1,204 @@
+############ grid procedures -- ydegoyon@free.fr #########
+
+proc grid_apply {id} {
+# strip "." from the TK id to make a variable name suffix
+ set vid [string trimleft $id .]
+# for each variable, make a local variable to hold its name...
+ set var_graph_name [concat graph_name_$vid]
+ global $var_graph_name
+ set var_graph_width [concat graph_width_$vid]
+ global $var_graph_width
+ set var_graph_xmin [concat graph_xmin_$vid]
+ global $var_graph_xmin
+ set var_graph_xmax [concat graph_xmax_$vid]
+ global $var_graph_xmax
+ set var_graph_height [concat graph_height_$vid]
+ global $var_graph_height
+ set var_graph_ymin [concat graph_ymin_$vid]
+ global $var_graph_ymin
+ set var_graph_ymax [concat graph_ymax_$vid]
+ global $var_graph_ymax
+ set var_graph_grid [concat graph_grid_$vid]
+ global $var_graph_grid
+ set var_graph_xstep [concat graph_xstep_$vid]
+ global $var_graph_xstep
+ set var_graph_ystep [concat graph_ystep_$vid]
+ global $var_graph_ystep
+ set var_graph_xlines [concat graph_xlines_$vid]
+ global $var_graph_xlines
+ set var_graph_ylines [concat graph_ylines_$vid]
+ global $var_graph_ylines
+
+ set cmd [concat $id dialog \
+ [eval concat $$var_graph_name] \
+ [eval concat $$var_graph_width] \
+ [eval concat $$var_graph_xmin] \
+ [eval concat $$var_graph_xmax] \
+ [eval concat $$var_graph_height] \
+ [eval concat $$var_graph_ymin] \
+ [eval concat $$var_graph_ymax] \
+ [eval concat $$var_graph_grid] \
+ [eval concat $$var_graph_xstep] \
+ [eval concat $$var_graph_ystep] \
+ [eval concat $$var_graph_xlines] \
+ [eval concat $$var_graph_ylines] \
+ \;]
+ #puts stderr $cmd
+ pd $cmd
+}
+
+proc grid_cancel {id} {
+ set cmd [concat $id cancel \;]
+ #puts stderr $cmd
+ pd $cmd
+}
+
+proc grid_ok {id} {
+ grid_apply $id
+ grid_cancel $id
+}
+
+proc pdtk_grid_dialog {id name width xmin xmax height ymin ymax grid xstep ystep xlines ylines} {
+ set vid [string trimleft $id .]
+ set var_graph_name [concat graph_name_$vid]
+ global $var_graph_name
+ set var_graph_width [concat graph_width_$vid]
+ global $var_graph_width
+ set var_graph_xmin [concat graph_xmin_$vid]
+ global $var_graph_xmin
+ set var_graph_xmax [concat graph_xmax_$vid]
+ global $var_graph_xmax
+ set var_graph_height [concat graph_height_$vid]
+ global $var_graph_height
+ set var_graph_ymin [concat graph_ymin_$vid]
+ global $var_graph_ymin
+ set var_graph_ymax [concat graph_ymax_$vid]
+ global $var_graph_ymax
+ set var_graph_grid [concat graph_grid_$vid]
+ global $var_graph_grid
+ set var_graph_xstep [concat graph_xstep_$vid]
+ global $var_graph_xstep
+ set var_graph_ystep [concat graph_ystep_$vid]
+ global $var_graph_ystep
+ set var_graph_xlines [concat graph_xlines_$vid]
+ global $var_graph_xlines
+ set var_graph_ylines [concat graph_ylines_$vid]
+ global $var_graph_ylines
+
+ set $var_graph_name $name
+ set $var_graph_width $width
+ set $var_graph_xmin $xmin
+ set $var_graph_xmax $xmax
+ set $var_graph_height $height
+ set $var_graph_ymin $ymin
+ set $var_graph_ymax $ymax
+ set $var_graph_grid $grid
+ set $var_graph_xstep $xstep
+ set $var_graph_ystep $ystep
+ set $var_graph_xlines $xlines
+ set $var_graph_ylines $ylines
+
+ toplevel $id
+ wm title $id {grid}
+ wm protocol $id WM_DELETE_WINDOW [concat grid_cancel $id]
+
+ label $id.label -text {GRID PROPERTIES}
+ pack $id.label -side top
+
+ frame $id.buttonframe
+ pack $id.buttonframe -side bottom -fill x -pady 2m
+ button $id.buttonframe.cancel -text {Cancel}\
+ -command "grid_cancel $id"
+ button $id.buttonframe.apply -text {Apply}\
+ -command "grid_apply $id"
+ button $id.buttonframe.ok -text {OK}\
+ -command "grid_ok $id"
+ pack $id.buttonframe.cancel -side left -expand 1
+ pack $id.buttonframe.apply -side left -expand 1
+ pack $id.buttonframe.ok -side left -expand 1
+
+ frame $id.1rangef
+ pack $id.1rangef -side top
+ label $id.1rangef.lname -text "Name :"
+ entry $id.1rangef.name -textvariable $var_graph_name -width 7
+ pack $id.1rangef.lname $id.1rangef.name -side left
+
+ frame $id.2rangef
+ pack $id.2rangef -side top
+ label $id.2rangef.lwidth -text "Width :"
+ entry $id.2rangef.width -textvariable $var_graph_width -width 7
+ pack $id.2rangef.lwidth $id.2rangef.width -side left
+
+ frame $id.3rangef
+ pack $id.3rangef -side top
+ label $id.3rangef.lxmin -text "X min :"
+ entry $id.3rangef.xmin -textvariable $var_graph_xmin -width 7
+ pack $id.3rangef.lxmin $id.3rangef.xmin -side left
+
+ frame $id.4rangef
+ pack $id.4rangef -side top
+ label $id.4rangef.lxmax -text "X max :"
+ entry $id.4rangef.xmax -textvariable $var_graph_xmax -width 7
+ pack $id.4rangef.lxmax $id.4rangef.xmax -side left
+
+ frame $id.41rangef
+ pack $id.41rangef -side top
+ label $id.41rangef.lxstep -text "X step :"
+ entry $id.41rangef.xstep -textvariable $var_graph_xstep -width 7
+ pack $id.41rangef.lxstep $id.41rangef.xstep -side left
+
+ frame $id.42rangef
+ pack $id.42rangef -side top
+ label $id.42rangef.lxlines -text "X sections :"
+ entry $id.42rangef.xlines -textvariable $var_graph_xlines -width 7
+ pack $id.42rangef.lxlines $id.42rangef.xlines -side left
+
+ frame $id.5rangef
+ pack $id.5rangef -side top
+ label $id.5rangef.lheight -text "Height :"
+ entry $id.5rangef.height -textvariable $var_graph_height -width 7
+ pack $id.5rangef.lheight $id.5rangef.height -side left
+
+ frame $id.6rangef
+ pack $id.6rangef -side top
+ label $id.6rangef.lymin -text "Y min :"
+ entry $id.6rangef.ymin -textvariable $var_graph_ymin -width 7
+ pack $id.6rangef.lymin $id.6rangef.ymin -side left
+
+ frame $id.7rangef
+ pack $id.7rangef -side top
+ label $id.7rangef.lymax -text "Y max :"
+ entry $id.7rangef.ymax -textvariable $var_graph_ymax -width 7
+ pack $id.7rangef.lymax $id.7rangef.ymax -side left
+
+ frame $id.71rangef
+ pack $id.71rangef -side top
+ label $id.71rangef.lystep -text "Y step :"
+ entry $id.71rangef.ystep -textvariable $var_graph_ystep -width 7
+ pack $id.71rangef.lystep $id.71rangef.ystep -side left
+
+ frame $id.72rangef
+ pack $id.72rangef -side top
+ label $id.72rangef.lylines -text "Y sections :"
+ entry $id.72rangef.ylines -textvariable $var_graph_ylines -width 7
+ pack $id.72rangef.lylines $id.72rangef.ylines -side left
+
+ checkbutton $id.showgrid -text {Show Grid} -variable $var_graph_grid \
+ -anchor w
+ pack $id.showgrid -side top
+
+ bind $id.1rangef.name <KeyPress-Return> [concat grid_ok $id]
+ bind $id.2rangef.width <KeyPress-Return> [concat grid_ok $id]
+ bind $id.3rangef.xmin <KeyPress-Return> [concat grid_ok $id]
+ bind $id.4rangef.xmax <KeyPress-Return> [concat grid_ok $id]
+ bind $id.41rangef.xstep <KeyPress-Return> [concat grid_ok $id]
+ bind $id.42rangef.xlines <KeyPress-Return> [concat grid_ok $id]
+ bind $id.5rangef.height <KeyPress-Return> [concat grid_ok $id]
+ bind $id.6rangef.ymin <KeyPress-Return> [concat grid_ok $id]
+ bind $id.7rangef.ymax <KeyPress-Return> [concat grid_ok $id]
+ bind $id.71rangef.ystep <KeyPress-Return> [concat grid_ok $id]
+ bind $id.72rangef.ylines <KeyPress-Return> [concat grid_ok $id]
+ focus $id.1rangef.name
+}
+
+############ grid procedures END -- ydegoyon@free.fr #########
diff --git a/grid/grid.tk2c b/grid/grid.tk2c
new file mode 100644
index 0000000..3e8f18f
--- /dev/null
+++ b/grid/grid.tk2c
@@ -0,0 +1,164 @@
+// ########### grid procedures -- ydegoyon@free.fr #########
+sys_gui("proc grid_apply {id} {\n");
+// strip "." from the TK id to make a variable name suffix
+sys_gui("set vid [string trimleft $id .]\n");
+// for each variable, make a local variable to hold its name...
+sys_gui("set var_graph_name [concat graph_name_$vid]\n");
+sys_gui("global $var_graph_name\n");
+sys_gui("set var_graph_width [concat graph_width_$vid]\n");
+sys_gui("global $var_graph_width\n");
+sys_gui("set var_graph_xmin [concat graph_xmin_$vid]\n");
+sys_gui("global $var_graph_xmin\n");
+sys_gui("set var_graph_xmax [concat graph_xmax_$vid]\n");
+sys_gui("global $var_graph_xmax\n");
+sys_gui("set var_graph_height [concat graph_height_$vid]\n");
+sys_gui("global $var_graph_height\n");
+sys_gui("set var_graph_ymin [concat graph_ymin_$vid]\n");
+sys_gui("global $var_graph_ymin\n");
+sys_gui("set var_graph_ymax [concat graph_ymax_$vid]\n");
+sys_gui("global $var_graph_ymax\n");
+sys_gui("set var_graph_grid [concat graph_grid_$vid]\n");
+sys_gui("global $var_graph_grid\n");
+sys_gui("set var_graph_xstep [concat graph_xstep_$vid]\n");
+sys_gui("global $var_graph_xstep\n");
+sys_gui("set var_graph_ystep [concat graph_ystep_$vid]\n");
+sys_gui("global $var_graph_ystep\n");
+sys_gui("set var_graph_xlines [concat graph_xlines_$vid]\n");
+sys_gui("global $var_graph_xlines\n");
+sys_gui("set var_graph_ylines [concat graph_ylines_$vid]\n");
+sys_gui("global $var_graph_ylines\n");
+sys_gui("set cmd [concat $id dialog [eval concat $$var_graph_name] [eval concat $$var_graph_width] [eval concat $$var_graph_xmin] [eval concat $$var_graph_xmax] [eval concat $$var_graph_height] [eval concat $$var_graph_ymin] [eval concat $$var_graph_ymax] [eval concat $$var_graph_grid] [eval concat $$var_graph_xstep] [eval concat $$var_graph_ystep] [eval concat $$var_graph_xlines] [eval concat $$var_graph_ylines] \\;]\n");
+// puts stderr $cmd
+sys_gui("pd $cmd\n");
+sys_gui("}\n");
+sys_gui("proc grid_cancel {id} {\n");
+sys_gui("set cmd [concat $id cancel \\;]\n");
+// puts stderr $cmd
+sys_gui("pd $cmd\n");
+sys_gui("}\n");
+sys_gui("proc grid_ok {id} {\n");
+sys_gui("grid_apply $id\n");
+sys_gui("grid_cancel $id\n");
+sys_gui("}\n");
+sys_gui("proc pdtk_grid_dialog {id name width xmin xmax height ymin ymax grid xstep ystep xlines ylines} {\n");
+sys_gui("set vid [string trimleft $id .]\n");
+sys_gui("set var_graph_name [concat graph_name_$vid]\n");
+sys_gui("global $var_graph_name\n");
+sys_gui("set var_graph_width [concat graph_width_$vid]\n");
+sys_gui("global $var_graph_width\n");
+sys_gui("set var_graph_xmin [concat graph_xmin_$vid]\n");
+sys_gui("global $var_graph_xmin\n");
+sys_gui("set var_graph_xmax [concat graph_xmax_$vid]\n");
+sys_gui("global $var_graph_xmax\n");
+sys_gui("set var_graph_height [concat graph_height_$vid]\n");
+sys_gui("global $var_graph_height\n");
+sys_gui("set var_graph_ymin [concat graph_ymin_$vid]\n");
+sys_gui("global $var_graph_ymin\n");
+sys_gui("set var_graph_ymax [concat graph_ymax_$vid]\n");
+sys_gui("global $var_graph_ymax\n");
+sys_gui("set var_graph_grid [concat graph_grid_$vid]\n");
+sys_gui("global $var_graph_grid\n");
+sys_gui("set var_graph_xstep [concat graph_xstep_$vid]\n");
+sys_gui("global $var_graph_xstep\n");
+sys_gui("set var_graph_ystep [concat graph_ystep_$vid]\n");
+sys_gui("global $var_graph_ystep\n");
+sys_gui("set var_graph_xlines [concat graph_xlines_$vid]\n");
+sys_gui("global $var_graph_xlines\n");
+sys_gui("set var_graph_ylines [concat graph_ylines_$vid]\n");
+sys_gui("global $var_graph_ylines\n");
+sys_gui("set $var_graph_name $name\n");
+sys_gui("set $var_graph_width $width\n");
+sys_gui("set $var_graph_xmin $xmin\n");
+sys_gui("set $var_graph_xmax $xmax\n");
+sys_gui("set $var_graph_height $height\n");
+sys_gui("set $var_graph_ymin $ymin\n");
+sys_gui("set $var_graph_ymax $ymax\n");
+sys_gui("set $var_graph_grid $grid\n");
+sys_gui("set $var_graph_xstep $xstep\n");
+sys_gui("set $var_graph_ystep $ystep\n");
+sys_gui("set $var_graph_xlines $xlines\n");
+sys_gui("set $var_graph_ylines $ylines\n");
+sys_gui("toplevel $id\n");
+sys_gui("wm title $id {grid}\n");
+sys_gui("wm protocol $id WM_DELETE_WINDOW [concat grid_cancel $id]\n");
+sys_gui("label $id.label -text {GRID PROPERTIES}\n");
+sys_gui("pack $id.label -side top\n");
+sys_gui("frame $id.buttonframe\n");
+sys_gui("pack $id.buttonframe -side bottom -fill x -pady 2m\n");
+sys_gui("button $id.buttonframe.cancel -text {Cancel} -command \"grid_cancel $id\"\n");
+sys_gui("button $id.buttonframe.apply -text {Apply} -command \"grid_apply $id\"\n");
+sys_gui("button $id.buttonframe.ok -text {OK} -command \"grid_ok $id\"\n");
+sys_gui("pack $id.buttonframe.cancel -side left -expand 1\n");
+sys_gui("pack $id.buttonframe.apply -side left -expand 1\n");
+sys_gui("pack $id.buttonframe.ok -side left -expand 1\n");
+sys_gui("frame $id.1rangef\n");
+sys_gui("pack $id.1rangef -side top\n");
+sys_gui("label $id.1rangef.lname -text \"Name :\"\n");
+sys_gui("entry $id.1rangef.name -textvariable $var_graph_name -width 7\n");
+sys_gui("pack $id.1rangef.lname $id.1rangef.name -side left\n");
+sys_gui("frame $id.2rangef\n");
+sys_gui("pack $id.2rangef -side top\n");
+sys_gui("label $id.2rangef.lwidth -text \"Width :\"\n");
+sys_gui("entry $id.2rangef.width -textvariable $var_graph_width -width 7\n");
+sys_gui("pack $id.2rangef.lwidth $id.2rangef.width -side left\n");
+sys_gui("frame $id.3rangef\n");
+sys_gui("pack $id.3rangef -side top\n");
+sys_gui("label $id.3rangef.lxmin -text \"X min :\"\n");
+sys_gui("entry $id.3rangef.xmin -textvariable $var_graph_xmin -width 7\n");
+sys_gui("pack $id.3rangef.lxmin $id.3rangef.xmin -side left\n");
+sys_gui("frame $id.4rangef\n");
+sys_gui("pack $id.4rangef -side top\n");
+sys_gui("label $id.4rangef.lxmax -text \"X max :\"\n");
+sys_gui("entry $id.4rangef.xmax -textvariable $var_graph_xmax -width 7\n");
+sys_gui("pack $id.4rangef.lxmax $id.4rangef.xmax -side left\n");
+sys_gui("frame $id.41rangef\n");
+sys_gui("pack $id.41rangef -side top\n");
+sys_gui("label $id.41rangef.lxstep -text \"X step :\"\n");
+sys_gui("entry $id.41rangef.xstep -textvariable $var_graph_xstep -width 7\n");
+sys_gui("pack $id.41rangef.lxstep $id.41rangef.xstep -side left\n");
+sys_gui("frame $id.42rangef\n");
+sys_gui("pack $id.42rangef -side top\n");
+sys_gui("label $id.42rangef.lxlines -text \"X sections :\"\n");
+sys_gui("entry $id.42rangef.xlines -textvariable $var_graph_xlines -width 7\n");
+sys_gui("pack $id.42rangef.lxlines $id.42rangef.xlines -side left\n");
+sys_gui("frame $id.5rangef\n");
+sys_gui("pack $id.5rangef -side top\n");
+sys_gui("label $id.5rangef.lheight -text \"Height :\"\n");
+sys_gui("entry $id.5rangef.height -textvariable $var_graph_height -width 7\n");
+sys_gui("pack $id.5rangef.lheight $id.5rangef.height -side left\n");
+sys_gui("frame $id.6rangef\n");
+sys_gui("pack $id.6rangef -side top\n");
+sys_gui("label $id.6rangef.lymin -text \"Y min :\"\n");
+sys_gui("entry $id.6rangef.ymin -textvariable $var_graph_ymin -width 7\n");
+sys_gui("pack $id.6rangef.lymin $id.6rangef.ymin -side left\n");
+sys_gui("frame $id.7rangef\n");
+sys_gui("pack $id.7rangef -side top\n");
+sys_gui("label $id.7rangef.lymax -text \"Y max :\"\n");
+sys_gui("entry $id.7rangef.ymax -textvariable $var_graph_ymax -width 7\n");
+sys_gui("pack $id.7rangef.lymax $id.7rangef.ymax -side left\n");
+sys_gui("frame $id.71rangef\n");
+sys_gui("pack $id.71rangef -side top\n");
+sys_gui("label $id.71rangef.lystep -text \"Y step :\"\n");
+sys_gui("entry $id.71rangef.ystep -textvariable $var_graph_ystep -width 7\n");
+sys_gui("pack $id.71rangef.lystep $id.71rangef.ystep -side left\n");
+sys_gui("frame $id.72rangef\n");
+sys_gui("pack $id.72rangef -side top\n");
+sys_gui("label $id.72rangef.lylines -text \"Y sections :\"\n");
+sys_gui("entry $id.72rangef.ylines -textvariable $var_graph_ylines -width 7\n");
+sys_gui("pack $id.72rangef.lylines $id.72rangef.ylines -side left\n");
+sys_gui("checkbutton $id.showgrid -text {Show Grid} -variable $var_graph_grid -anchor w\n");
+sys_gui("pack $id.showgrid -side top\n");
+sys_gui("bind $id.1rangef.name <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.2rangef.width <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.3rangef.xmin <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.4rangef.xmax <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.41rangef.xstep <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.42rangef.xlines <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.5rangef.height <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.6rangef.ymin <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.7rangef.ymax <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.71rangef.ystep <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("bind $id.72rangef.ylines <KeyPress-Return> [concat grid_ok $id]\n");
+sys_gui("focus $id.1rangef.name\n");
+sys_gui("}\n");
+// ########### grid procedures END -- ydegoyon@free.fr #########
diff --git a/grid/grid2.c b/grid/grid2.c
new file mode 100644
index 0000000..924abd3
--- /dev/null
+++ b/grid/grid2.c
@@ -0,0 +1,539 @@
+/* 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_grid.c written by Yves Degoyon 2002 */
+/* grid control object : two dimensionnal grid */
+/* thanks to Thomas Musil, Miller Puckette, Guenther Geiger and Krzystof Czaja */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <ctype.h>
+#include "m_imp.h"
+#include "g_canvas.h"
+#include "t_tk.h"
+#include "g_grid.h"
+
+#ifdef NT
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+/* needed to create a grid from PD's menu
+void canvas_objtext(t_glist *gl, int xpos, int ypos, int selected, t_binbuf *b);
+void canvas_startmotion(t_canvas *x);
+*/
+
+#define DEFAULT_GRID_WIDTH 200
+#define DEFAULT_GRID_HEIGHT 200
+#define DEFAULT_GRID_NBLINES 10
+
+t_widgetbehavior grid_widgetbehavior;
+static t_class *grid_class;
+static int gridcount=0;
+
+static int guidebug=0;
+static int pointsize = 5;
+
+static char *grid_version = "grid: version 0.2, written by Yves Degoyon (ydegoyon@free.fr)";
+
+#define GRID_SYS_VGUI2(a,b) if (guidebug) \
+ post(a,b);\
+ sys_vgui(a,b)
+
+#define GRID_SYS_VGUI3(a,b,c) if (guidebug) \
+ post(a,b,c);\
+ sys_vgui(a,b,c)
+
+#define GRID_SYS_VGUI4(a,b,c,d) if (guidebug) \
+ post(a,b,c,d);\
+ sys_vgui(a,b,c,d)
+
+#define GRID_SYS_VGUI7(a,b,c,d,e,f,g) if (guidebug) \
+ post(a,b,c,d,e,f,g );\
+ sys_vgui(a,b,c,d,e,f,g)
+
+#define GRID_SYS_VGUI9(a,b,c,d,e,f,g,h,i) if (guidebug) \
+ post(a,b,c,d,e,f,g,h,i );\
+ sys_vgui(a,b,c,d,e,f,g,h,i)
+
+/* drawing functions */
+static void grid_draw_update(t_grid *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int xpoint=x->x_current, ypoint=x->y_current;
+
+ // later : try to figure out what's this test for ??
+ // if (glist_isvisible(glist))
+ // {
+ // delete previous point if existing
+ if (x->x_point)
+ {
+ GRID_SYS_VGUI3(".x%x.c delete %xPOINT\n", canvas, x);
+ }
+
+ if ( x->x_current < x->x_obj.te_xpix ) xpoint = x->x_obj.te_xpix;
+ if ( x->x_current > x->x_obj.te_xpix + x->x_width - pointsize )
+ xpoint = x->x_obj.te_xpix + x->x_width - pointsize;
+ if ( x->y_current < x->x_obj.te_ypix ) ypoint = x->x_obj.te_ypix;
+ if ( x->y_current > x->x_obj.te_ypix + x->x_height - pointsize )
+ ypoint = x->x_obj.te_ypix + x->x_height - pointsize;
+ // draw the selected point
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -fill #FF0000 -tags %xPOINT\n",
+ canvas, xpoint, ypoint, xpoint+pointsize, ypoint+pointsize, x);
+ x->x_point = 1;
+ // }
+ // else
+ // {
+ // post( "grid : position updated in an invisible grid" );
+ // }
+}
+
+static void grid_draw_new(t_grid *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -fill #124392 -tags %xGRID\n",
+ canvas, x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_obj.te_xpix + x->x_width, x->x_obj.te_ypix + x->x_height,
+ x);
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -tags %xOUTL\n",
+ canvas, x->x_obj.te_xpix, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+7, x->x_obj.te_ypix + x->x_height+2,
+ x);
+ GRID_SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -tags %xOUTR\n",
+ canvas, x->x_obj.te_xpix+x->x_width-7, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix + x->x_height+2,
+ x);
+
+ if ( x->x_grid )
+ {
+ int xlpos = x->x_obj.te_xpix+x->x_width/x->x_xlines;
+ int ylpos = x->x_obj.te_ypix+x->x_height/x->x_ylines;
+ int xcount = 1;
+ int ycount = 1;
+ while ( xlpos < x->x_obj.te_xpix+x->x_width )
+ {
+ GRID_SYS_VGUI9(".x%x.c create line %d %d %d %d -fill #FFFFFF -tags %xLINE%d%d\n",
+ canvas, xlpos, x->x_obj.te_ypix,
+ xlpos, x->x_obj.te_ypix+x->x_height,
+ x, xcount, 0 );
+ xlpos+=x->x_width/x->x_xlines;
+ xcount++;
+ }
+ while ( ylpos < x->x_obj.te_ypix+x->x_height )
+ {
+ GRID_SYS_VGUI9(".x%x.c create line %d %d %d %d -fill #FFFFFF -tags %xLINE%d%d\n",
+ canvas, x->x_obj.te_xpix, ylpos,
+ x->x_obj.te_xpix+x->x_width, ylpos,
+ x, 0, ycount);
+ ylpos+=x->x_height/x->x_ylines;
+ ycount++;
+ }
+ }
+ canvas_fixlinesfor( canvas, (t_text*)x );
+}
+
+static void grid_draw_move(t_grid *x, t_glist *glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ GRID_SYS_VGUI7(".x%x.c coords %xGRID %d %d %d %d\n",
+ canvas, x,
+ x->x_obj.te_xpix, x->x_obj.te_ypix,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix+x->x_height);
+ GRID_SYS_VGUI7(".x%x.c coords %xOUTL %d %d %d %d\n",
+ canvas, x,
+ x->x_obj.te_xpix, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+7, x->x_obj.te_ypix + x->x_height+2 );
+ GRID_SYS_VGUI7(".x%x.c coords %xOUTR %d %d %d %d\n",
+ canvas, x,
+ x->x_obj.te_xpix+x->x_width-7, x->x_obj.te_ypix + x->x_height+1,
+ x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix + x->x_height+2 );
+ if ( x->x_point )
+ {
+ grid_draw_update(x, glist);
+ }
+ if ( x->x_grid )
+ {
+ int xlpos = x->x_obj.te_xpix+x->x_width/x->x_xlines;
+ int ylpos = x->x_obj.te_ypix+x->x_height/x->x_ylines;
+ int xcount = 1;
+ int ycount = 1;
+ while ( xlpos < x->x_obj.te_xpix+x->x_width )
+ {
+ GRID_SYS_VGUI9(".x%x.c coords %xLINE%d%d %d %d %d %d\n",
+ canvas, x, xcount, 0, xlpos, x->x_obj.te_ypix,
+ xlpos, x->x_obj.te_ypix + x->x_height);
+ xlpos+=x->x_width/x->x_xlines;
+ xcount++;
+ }
+ while ( ylpos < x->x_obj.te_ypix+x->x_height )
+ {
+ GRID_SYS_VGUI9(".x%x.c coords %xLINE%d%d %d %d %d %d\n",
+ canvas, x, 0, ycount, x->x_obj.te_xpix, ylpos,
+ x->x_obj.te_xpix + x->x_width, ylpos);
+ ylpos+=x->x_height/x->x_ylines;
+ ycount++;
+ }
+ }
+ canvas_fixlinesfor( canvas, (t_text*)x );
+}
+
+static void grid_draw_erase(t_grid* x,t_glist* glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ int i;
+
+ GRID_SYS_VGUI3(".x%x.c delete %xGRID\n", canvas, x);
+ GRID_SYS_VGUI3(".x%x.c delete %xOUTL\n", canvas, x);
+ GRID_SYS_VGUI3(".x%x.c delete %xOUTR\n", canvas, x);
+ if (x->x_grid)
+ {
+ for (i=1; i<x->x_xlines; i++ )
+ {
+ GRID_SYS_VGUI4(".x%x.c delete %xLINE%d0\n", canvas, x, i);
+ }
+ for (i=1; i<x->x_ylines; i++ )
+ {
+ GRID_SYS_VGUI4(".x%x.c delete %xLINE0%d\n", canvas, x, i);
+ }
+ }
+ if (x->x_point)
+ {
+ GRID_SYS_VGUI3(".x%x.c delete %xPOINT\n", canvas, x);
+ x->x_point = 0;
+ }
+}
+
+static void grid_draw_select(t_grid* x,t_glist* glist)
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ if(x->x_selected)
+ {
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+ /* sets the item in blue */
+ GRID_SYS_VGUI3(".x%x.c itemconfigure %xGRID -outline #0000FF\n", canvas, x);
+ }
+ else
+ {
+ pd_unbind(&x->x_obj.ob_pd, x->x_name);
+ GRID_SYS_VGUI3(".x%x.c itemconfigure %xGRID -outline #000000\n", canvas, x);
+ }
+}
+
+static void grid_output_current(t_grid* x)
+{
+ t_float xvalue, yvalue;
+ t_float xmodstep, ymodstep;
+
+ xvalue = x->x_min + (x->x_current - x->x_obj.te_xpix) * (x->x_max-x->x_min) / x->x_width ;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
+ xmodstep = ((float)((int)(xvalue*10000) % (int)(x->x_xstep*10000))/10000.);
+ xvalue = xvalue - xmodstep;
+ outlet_float( x->x_xoutlet, xvalue );
+
+ yvalue = x->y_max - (x->y_current - x->x_obj.te_ypix ) * (x->y_max-x->y_min) / x->x_height ;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
+ ymodstep = ((float)((int)(yvalue*10000) % (int)(x->x_ystep*10000))/10000.);
+ yvalue = yvalue - ymodstep;
+ outlet_float( x->x_youtlet, yvalue );
+}
+
+/* ------------------------ grid widgetbehaviour----------------------------- */
+
+
+static void grid_getrect(t_gobj *z, t_glist *owner,
+ int *xp1, int *yp1, int *xp2, int *yp2)
+{
+ t_grid* x = (t_grid*)z;
+
+ *xp1 = x->x_obj.te_xpix;
+ *yp1 = x->x_obj.te_ypix;
+ *xp2 = x->x_obj.te_xpix+x->x_width;
+ *yp2 = x->x_obj.te_ypix+x->x_height;
+}
+
+static void grid_save(t_gobj *z, t_binbuf *b)
+{
+ t_grid *x = (t_grid *)z;
+
+ // post( "saving grid : %s", x->x_name->s_name );
+ binbuf_addv(b, "ssiissiffiffiffiiff", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ gensym("grid"), x->x_name, x->x_width, x->x_min,
+ x->x_max, x->x_height,
+ x->y_min, x->y_max,
+ x->x_grid, x->x_xstep,
+ x->x_ystep, x->x_xlines, x->x_ylines,
+ x->x_current, x->y_current );
+ binbuf_addv(b, ";");
+}
+
+static void grid_properties(t_gobj *z, t_glist *owner)
+{
+ char buf[800];
+ t_grid *x=(t_grid *)z;
+
+ sprintf(buf, "pdtk_grid_dialog %%s %s %d %.2f %.2f %d %.2f %.2f %d %.2f %.2f %d %d\n",
+ x->x_name->s_name, x->x_width, x->x_min, x->x_max, x->x_height,
+ x->y_min, x->y_max, x->x_grid, x->x_xstep, x->x_ystep,
+ x->x_xlines, x->x_ylines );
+ // post("grid_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
+}
+
+static void grid_select(t_gobj *z, t_glist *glist, int selected)
+{
+ t_grid *x = (t_grid *)z;
+
+ x->x_selected = selected;
+ grid_draw_select( x, glist );
+}
+
+static void grid_vis(t_gobj *z, t_glist *glist, int vis)
+{
+ t_grid *x = (t_grid *)z;
+
+ if (vis)
+ {
+ grid_draw_new( x, glist );
+ grid_draw_update( x, glist );
+ grid_output_current(x);
+ }
+ else
+ {
+ grid_draw_erase( x, glist );
+ }
+}
+
+static void grid_dialog(t_grid *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if ( !x ) {
+ post( "grid : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 12 )
+ {
+ post( "grid : error in the number of arguments ( %d instead of 12 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_SYMBOL || argv[1].a_type != A_FLOAT ||
+ argv[2].a_type != A_FLOAT || argv[3].a_type != A_FLOAT ||
+ argv[4].a_type != A_FLOAT || argv[5].a_type != A_FLOAT ||
+ argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
+ argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ||
+ argv[10].a_type != A_FLOAT || argv[11].a_type != A_FLOAT ) {
+ post( "grid : wrong arguments" );
+ return;
+ }
+ x->x_name = argv[0].a_w.w_symbol;
+ x->x_width = (int)argv[1].a_w.w_float;
+ x->x_min = argv[2].a_w.w_float;
+ x->x_max = argv[3].a_w.w_float;
+ x->x_height = (int)argv[4].a_w.w_float;
+ x->y_min = argv[5].a_w.w_float;
+ x->y_max = argv[6].a_w.w_float;
+ x->x_grid = argv[7].a_w.w_float;
+ x->x_xstep = argv[8].a_w.w_float;
+ x->x_ystep = argv[9].a_w.w_float;
+ x->x_xlines = argv[10].a_w.w_float;
+ x->x_ylines = argv[11].a_w.w_float;
+ grid_draw_erase(x, x->x_glist);
+ grid_draw_new(x, x->x_glist);
+}
+
+static void grid_delete(t_gobj *z, t_glist *glist)
+{
+ canvas_deletelinesfor( glist_getcanvas(glist), (t_text *)z);
+}
+
+static void grid_displace(t_gobj *z, t_glist *glist, int dx, int dy)
+{
+ t_grid *x = (t_grid *)z;
+ int xold = x->x_obj.te_xpix;
+ int yold = x->x_obj.te_ypix;
+
+ // post( "grid_displace dx=%d dy=%d", dx, dy );
+
+ x->x_obj.te_xpix += dx;
+ x->x_current += dx;
+ x->x_obj.te_ypix += dy;
+ x->y_current += dy;
+ if(xold != x->x_obj.te_xpix || yold != x->x_obj.te_ypix)
+ {
+ grid_draw_move(x, x->x_glist);
+ }
+}
+
+static void grid_motion(t_grid *x, t_floatarg dx, t_floatarg dy)
+{
+ int xold = x->x_current;
+ int yold = x->y_current;
+
+ // post( "grid_motion dx=%f dy=%f", dx, dy );
+
+ x->x_current += dx;
+ x->y_current += dy;
+ if(xold != x->x_current || yold != x->y_current)
+ {
+ grid_output_current(x);
+ grid_draw_update(x, x->x_glist);
+ }
+}
+
+static void grid_set(t_grid *x, t_floatarg x, t_floatarg y)
+{
+ int xold = x->x_current;
+ int yold = x->y_current;
+
+ // post( "grid_set x=%f y=%f", x, y );
+
+ x->x_current = x;
+ x->y_current = y;
+ if(xold != x->x_current || yold != x->y_current)
+ {
+ grid_output_current(x);
+ grid_draw_update(x, x->x_glist);
+ }
+}
+
+static int grid_click(t_gobj *z, struct _glist *glist,
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
+{
+ t_grid* x = (t_grid *)z;
+
+ // post( "grid_click doit=%d x=%d y=%d", doit, xpix, ypix );
+ if ( doit)
+ {
+ x->x_current = xpix;
+ x->y_current = ypix;
+ grid_output_current(x);
+ grid_draw_update(x, glist);
+ glist_grab(glist, &x->x_obj.te_g, (t_glistmotionfn)grid_motion,
+ 0, xpix, ypix);
+ }
+ return (1);
+}
+
+static t_grid *grid_new(t_symbol *s, int argc, t_atom *argv)
+{
+ int i, zz;
+ t_grid *x;
+ t_pd *x2;
+ char *str;
+
+ // post( "grid_new : create : %s argc =%d", s->s_name, argc );
+
+ x = (t_grid *)pd_new(grid_class);
+ // new grid created from the gui
+ if ( argc != 0 )
+ {
+ if ( argc != 14 )
+ {
+ post( "grid : error in the number of arguments ( %d instead of 14 )", argc );
+ return NULL;
+ }
+ if ( argv[0].a_type != A_SYMBOL || argv[1].a_type != A_FLOAT ||
+ argv[2].a_type != A_FLOAT || argv[3].a_type != A_FLOAT ||
+ argv[4].a_type != A_FLOAT || argv[5].a_type != A_FLOAT ||
+ argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
+ argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ||
+ argv[10].a_type != A_FLOAT || argv[11].a_type != A_FLOAT ||
+ argv[12].a_type != A_FLOAT || argv[13].a_type != A_FLOAT ) {
+ post( "grid : wrong arguments" );
+ return NULL;
+ }
+
+ // update grid count
+ if (!strncmp((str = argv[0].a_w.w_symbol->s_name), "grid", 5)
+ && (zz = atoi(str + 5)) > gridcount)
+ {
+ gridcount = zz;
+ }
+ x->x_name = argv[0].a_w.w_symbol;
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+ x->x_width = argv[1].a_w.w_float;
+ x->x_min = argv[2].a_w.w_float;
+ x->x_max = argv[3].a_w.w_float;
+ x->x_height = argv[4].a_w.w_float;
+ x->y_min = argv[5].a_w.w_float;
+ x->y_max = argv[6].a_w.w_float;
+ x->x_grid = argv[7].a_w.w_float;
+ x->x_xstep = argv[8].a_w.w_float;
+ x->x_ystep = argv[9].a_w.w_float;
+ x->x_xlines = argv[10].a_w.w_float;
+ x->x_ylines = argv[11].a_w.w_float;
+ x->x_current = argv[12].a_w.w_float;
+ x->y_current = argv[13].a_w.w_float;
+ x->x_point = 1;
+ }
+ else
+ {
+ char buf[40];
+
+ sprintf(buf, "grid%d", ++gridcount);
+ s = gensym(buf);
+
+ x->x_name = s;
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+
+ x->x_width = DEFAULT_GRID_WIDTH;
+ x->x_min = 0;
+ x->x_max = DEFAULT_GRID_WIDTH - 1;
+ x->x_height = DEFAULT_GRID_HEIGHT;
+ x->y_min = 0;
+ x->y_max = DEFAULT_GRID_HEIGHT - 1;
+ x->x_grid = 1;
+ x->x_xstep = 1.0;
+ x->x_ystep = 1.0;
+ x->x_xlines = DEFAULT_GRID_NBLINES;
+ x->x_ylines = DEFAULT_GRID_NBLINES;
+ x->x_current = 0;
+ x->y_current = 0;
+
+ }
+
+ // common fields for new and restored grids
+ x->x_point = 0;
+ x->x_selected = 0;
+ x->x_glist = (t_glist *) canvas_getcurrent();
+ x->x_xoutlet = outlet_new(&x->x_obj, &s_float );
+ x->x_youtlet = outlet_new(&x->x_obj, &s_float );
+
+ // post( "grid_new name : %s width: %d height : %d", x->x_name->s_name, x->x_width, x->x_height );
+
+ return (x);
+}
+
+static void grid_free(t_grid *x)
+{
+ // post( "grid~: grid_free" );
+}
+
+void grid_setup(void)
+{
+#include "grid.tk2c"
+ post( grid_version );
+ grid_class = class_new(gensym("grid"), (t_newmethod)grid_new,
+ (t_method)grid_free, sizeof(t_grid), 0, A_GIMME, 0);
+ class_addmethod(grid_class, (t_method)grid_set, gensym("set"), A_FLOAT, A_FLOAT, 0);
+ class_addmethod(grid_class, (t_method)grid_dialog, gensym("dialog"), A_GIMME, 0);
+ grid_widgetbehavior.w_getrectfn = grid_getrect;
+ grid_widgetbehavior.w_displacefn = grid_displace;
+ grid_widgetbehavior.w_selectfn = grid_select;
+ grid_widgetbehavior.w_activatefn = NULL;
+ grid_widgetbehavior.w_deletefn = grid_delete;
+ grid_widgetbehavior.w_visfn = grid_vis;
+ grid_widgetbehavior.w_clickfn = grid_click;
+ grid_widgetbehavior.w_propertiesfn = grid_properties;
+ grid_widgetbehavior.w_savefn = grid_save;
+ class_setwidget(grid_class, &grid_widgetbehavior);
+ class_sethelpsymbol(grid_class, gensym("help-grid.pd"));
+}
diff --git a/grid/help-grid.pd b/grid/help-grid.pd
new file mode 100644
index 0000000..b31c29e
--- /dev/null
+++ b/grid/help-grid.pd
@@ -0,0 +1,198 @@
+#N canvas 26 1 763 647 10;
+#X obj 71 76 grid grid1 200 0 199 200 0 199 1 1 1 10 10 188 197;
+#X floatatom 72 293 5 0 0;
+#X floatatom 257 282 5 0 0;
+#X text 41 21 Grid is a 2-dimensional control object;
+#X text 319 449 (invoke with <right mouse>Properties );
+#X text 322 439 You can set the following properties :;
+#X text 347 468 * Name;
+#X text 346 480 * Width : graphical x size;
+#X text 346 491 * X min : minimum value delivered by left outlet (
+X );
+#X text 346 503 * X max : maximum value delivered by left outlet (
+X );
+#X text 347 513 * X step : X delta for an X update;
+#X text 346 524 * X sections : number of vertical lines of the inner
+grid;
+#X text 347 534 * Height : graphical y size;
+#X text 346 546 * Y min : minimum value delivered by right outlet (
+Y );
+#X text 347 558 * Y max : maximum value delivered by right outlet (
+Y );
+#X text 346 579 * Y sections : number of horizontal lines of the inner
+grid;
+#X text 347 591 * Show Grid : option to draw an inner grid;
+#X text 328 609 bugs and comments @ ydegoyon@free.fr;
+#X text 120 292 X value;
+#X text 303 281 Y value;
+#X msg 587 271 \; pd dsp 0;
+#X msg 653 271 \; pd dsp 1;
+#X obj 276 417 *~;
+#X floatatom 276 360 0 0 0;
+#X obj 357 397 line~;
+#X floatatom 188 380 0 0 0;
+#X obj 188 494 cos~;
+#X obj 188 450 +~;
+#X floatatom 228 506 0 0 100;
+#N canvas 159 26 495 270 output 0;
+#X obj 338 160 t b;
+#X obj 338 110 f;
+#X obj 338 60 inlet;
+#X text 344 29 mute;
+#X obj 338 185 f;
+#X msg 425 178 0;
+#X msg 338 85 bang;
+#X obj 338 135 moses 1;
+#X obj 425 153 t b f;
+#X obj 397 117 moses 1;
+#X obj 83 148 dbtorms;
+#X obj 397 92 r master-lvl;
+#X obj 83 42 r master-lvl;
+#X obj 338 210 s master-lvl;
+#X obj 22 182 inlet~;
+#X obj 199 41 inlet;
+#X text 199 18 level;
+#X obj 199 100 s master-lvl;
+#X msg 96 65 set \$1;
+#X obj 96 89 outlet;
+#X msg 214 64 \; pd dsp 1;
+#X obj 83 194 line~;
+#X obj 22 212 *~;
+#X obj 22 241 dac~;
+#X obj 83 171 pack 0 50;
+#X text 20 159 audio;
+#X text 93 110 show level;
+#X connect 0 0 4 0;
+#X connect 1 0 7 0;
+#X connect 2 0 6 0;
+#X connect 4 0 13 0;
+#X connect 5 0 13 0;
+#X connect 6 0 1 0;
+#X connect 7 0 0 0;
+#X connect 7 1 8 0;
+#X connect 8 0 5 0;
+#X connect 9 1 4 1;
+#X connect 10 0 24 0;
+#X connect 11 0 1 1;
+#X connect 11 0 9 0;
+#X connect 12 0 10 0;
+#X connect 12 0 18 0;
+#X connect 14 0 22 0;
+#X connect 15 0 17 0;
+#X connect 15 0 20 0;
+#X connect 18 0 19 0;
+#X connect 21 0 22 1;
+#X connect 22 0 23 0;
+#X connect 22 0 23 1;
+#X connect 24 0 21 0;
+#X restore 190 533 pd output;
+#X msg 266 506 MUTE;
+#X obj 276 385 osc~ 0;
+#X obj 357 371 pack 0 50;
+#X floatatom 357 318 0 0 0;
+#X obj 357 345 / 100;
+#X text 188 345 carrier;
+#X text 184 355 frequency;
+#X text 261 336 frequency;
+#X text 262 319 modulation;
+#X obj 188 407 phasor~;
+#X msg 39 350 250;
+#X obj 39 328 loadbang;
+#X text 17 377 3-dimensional control;
+#X text 16 389 would be nice :-);
+#X text 393 310 modulation index;
+#X text 393 325 in hundredths;
+#X text 40 32 It was inspired by the chaospad device;
+#X text 346 568 * Y step : Y delta for an Y update;
+#X floatatom 474 85 5 0 0;
+#X floatatom 586 84 5 0 0;
+#X obj 411 82 pack f f;
+#X msg 332 81 goto \$1 \$2;
+#X msg 546 83 bang;
+#X text 524 84 X;
+#X text 333 63 Set position :;
+#X text 631 85 Y;
+#X floatatom 486 120 5 0 0;
+#X floatatom 586 121 5 0 0;
+#X obj 423 119 pack f f;
+#X msg 546 120 bang;
+#X text 530 120 X;
+#X text 634 121 Y;
+#X floatatom 528 156 5 0 0;
+#X floatatom 633 156 5 0 0;
+#X obj 465 153 pack f f;
+#X msg 593 154 bang;
+#X text 578 155 X;
+#X text 679 156 Y;
+#X floatatom 503 191 5 0 0;
+#X floatatom 607 190 5 0 0;
+#X obj 440 188 pack f f;
+#X msg 568 189 bang;
+#X text 553 190 X;
+#X text 656 191 Y;
+#X floatatom 539 224 5 0 0;
+#X floatatom 638 226 5 0 0;
+#X obj 472 223 pack f f;
+#X msg 600 224 bang;
+#X text 585 225 X;
+#X text 685 225 Y;
+#X msg 109 49 bang;
+#X msg 332 118 values \$1 \$2;
+#X text 333 100 Set values :;
+#X text 331 135 Set deltas for values :;
+#X msg 333 152 valuemotion \$1 \$2;
+#X msg 333 187 xvalues \$1 \$2;
+#X text 334 170 Set values without changing output :;
+#X text 332 205 Set deltas for values without changing output:;
+#X msg 334 223 xvaluemotion \$1 \$2;
+#X connect 0 0 1 0;
+#X connect 0 1 2 0;
+#X connect 1 0 23 0;
+#X connect 2 0 33 0;
+#X connect 22 0 27 1;
+#X connect 23 0 31 0;
+#X connect 24 0 22 1;
+#X connect 25 0 39 0;
+#X connect 26 0 29 0;
+#X connect 27 0 26 0;
+#X connect 28 0 29 1;
+#X connect 29 0 28 0;
+#X connect 30 0 29 2;
+#X connect 31 0 22 0;
+#X connect 32 0 24 0;
+#X connect 33 0 34 0;
+#X connect 34 0 32 0;
+#X connect 39 0 27 0;
+#X connect 40 0 25 0;
+#X connect 41 0 40 0;
+#X connect 48 0 50 0;
+#X connect 49 0 50 1;
+#X connect 49 0 52 0;
+#X connect 50 0 51 0;
+#X connect 51 0 0 0;
+#X connect 52 0 48 0;
+#X connect 56 0 58 0;
+#X connect 57 0 58 1;
+#X connect 57 0 59 0;
+#X connect 58 0 81 0;
+#X connect 59 0 56 0;
+#X connect 62 0 64 0;
+#X connect 63 0 64 1;
+#X connect 63 0 65 0;
+#X connect 64 0 84 0;
+#X connect 65 0 62 0;
+#X connect 68 0 70 0;
+#X connect 69 0 70 1;
+#X connect 69 0 71 0;
+#X connect 70 0 85 0;
+#X connect 71 0 68 0;
+#X connect 74 0 76 0;
+#X connect 75 0 76 1;
+#X connect 75 0 77 0;
+#X connect 76 0 88 0;
+#X connect 77 0 74 0;
+#X connect 80 0 0 0;
+#X connect 81 0 0 0;
+#X connect 84 0 0 0;
+#X connect 85 0 0 0;
+#X connect 88 0 0 0;
diff --git a/grid/tk2c.bash b/grid/tk2c.bash
new file mode 100755
index 0000000..9dfeb03
--- /dev/null
+++ b/grid/tk2c.bash
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+#set -x
+
+while read line
+do
+ for word in $line
+ do
+ if [ "X"$word != "X"${word#\#} ]
+ then
+ echo // ${line#\#}
+ break
+ else
+ line=${line//\'/\\\'}
+#useless, slashes never gets in
+ line=${line//\\/\\\\}
+#this one's dirty, i know
+ line=${line//;/\\\\;}
+ line=${line//\"/\\\"}
+ echo 'sys_gui("'$line'\n");'
+ break
+ fi
+ done
+done