Update of /cvsroot/pure-data/externals/miXed/toxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15203/toxy
Modified Files: Makefile Makefile.objects Makefile.sources build_counter tot.c toxy-shared.include widget.c widgettype.c widgettype.h Added Files: plustot.c plustot.env.c plustot.h plustot.in.c plustot.out.c plustot.print.c plustot.qlist.c plustot.var.c Log Message: many small improvements in toxy, plustot added
--- NEW FILE: plustot.c --- /* Copyright (c) 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 "g_canvas.h" #include "common/loud.h" #include "common/grow.h" #include "hammer/file.h" #include "common/props.h" #include "toxy/scriptlet.h" #include "toxy/plusbob.h" #include "plustot.h" #include "build_counter"
#define PLUSTOT_VERBOSE #define PLUSTOT_DEBUG //#define PLUSTOT_DEBUGREFCOUNTS [...1981 lines suppressed...]
plustin_basetype = plusenv_setup(); plustin_type = plustype_new(plustin_basetype, plusps_Ti, sizeof(t_plustin), (t_plustypefn)plustin_delete, 0, 0, 0); plustob_type = plustype_new(0, plusps_To, sizeof(t_plustob), (t_plustypefn)plustob_delete, 0, 0, (t_plustypefn)plustob_attach); plusvar_type = plustype_new(plustob_type, plusps_Tv, sizeof(t_plusvar), (t_plustypefn)plusvar_delete, 0, 0, 0);
plustot_env_setup(); plustot_in_setup(); plustot_var_setup(); plustot_out_setup(); plustot_qlist_setup(); plustot_print_setup(); }
--- NEW FILE: plustot.env.c --- /* Copyright (c) 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 <stdio.h> #include <string.h> #ifdef UNIX #include <unistd.h> #endif #ifdef NT #include <io.h> #endif #include "m_pd.h" #include "g_canvas.h" #include "common/loud.h" #include "hammer/file.h" #include "toxy/plusbob.h" #include "plustot.h"
typedef struct _plustot_env { t_object x_ob; t_plustin *x_tin; t_glist *x_glist; t_hammerfile *x_filehandle; } t_plustot_env;
static t_class *plustot_env_class;
static void plustot_env_takeover(t_glist *glist, t_plusbob *defparent, t_plusbob *newparent) { t_gobj *g; for (g = glist->gl_list; g; g = g->g_next) { if (pd_class(&g->g_pd) == canvas_class) { if (!plustin_glistfind((t_glist *)g, PLUSTIN_GLIST_THIS)) plustot_env_takeover((t_glist *)g, defparent, newparent); } else plusbob_detachownedchildren(defparent, newparent, (t_pd *)g); } }
static void plustot_env_evalfile(t_plustot_env *x, t_symbol *fname) { char buf1[MAXPDSTRING], buf2[MAXPDSTRING], *nameptr, *dir; int fd; dir = canvas_getdir(x->x_glist)->s_name; if ((fd = open_via_path(dir, fname->s_name, "", buf1, &nameptr, MAXPDSTRING, 0)) < 0) { loud_error((t_pd *)x, "file '%s' not found", fname->s_name); } else { Tcl_Interp *interp = plustin_getinterp(x->x_tin); FILE *fp; close(fd); strcpy(buf2, buf1); strcat(buf2, "/"); strcat(buf2, nameptr); sys_bashfilename(buf2, buf2); Tcl_Preserve(interp); if (Tcl_EvalFile(interp, buf2) != TCL_OK) { strcpy(buf1, "evaluation failed ("); strncat(buf1, buf2, MAXPDSTRING - strlen(buf1) - 2); strcat(buf1, ")"); plusloud_tclerror((t_pd *)x, interp, buf1); } Tcl_Release(interp); } }
static void plustot_env_evalfilehook(t_pd *z, t_symbol *fn, int ac, t_atom *av) { plustot_env_evalfile((t_plustot_env *)z, fn); }
static void plustot_env_bang(t_plustot_env *x) { outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_tin); }
static void plustot_env_source(t_plustot_env *x, t_symbol *s) { if (s && s != &s_) plustot_env_evalfile(x, s); else hammerpanel_open(x->x_filehandle, 0); }
static void plustot_env_free(t_plustot_env *x) { t_plustin *tin = plustin_glistprovide(x->x_glist, PLUSTIN_GLIST_UP, 0); plusbob_detachchildren((t_plusbob *)x->x_tin, (t_plusbob *)tin); plusbob_release((t_plusbob *)x->x_tin); hammerfile_free(x->x_filehandle); }
void *plustot_env_new(t_symbol *s, int ac, t_atom *av) { t_plustot_env *x = 0; t_glist *gl = canvas_getcurrent(); t_plustin *oldtin = plustin_glistfind(gl, PLUSTIN_GLIST_THIS); t_plustin *deftin = (oldtin ? 0 : plustin_glistfind(gl, PLUSTIN_GLIST_ANY)); t_plustin *tin = 0; if ((tin = oldtin) || (tin = plustin_glistprovide(gl, PLUSTIN_GLIST_THIS, 1))) { int warned = 0; x = (t_plustot_env *)pd_new(plustot_env_class); x->x_tin = tin; plusbob_preserve((t_plusbob *)tin); x->x_glist = gl; outlet_new((t_object *)x, &s_symbol); if (deftin) /* true if both oldtin == 0 (we are first in this glist) and plustin_default != 0 (bobs exist already) */ plustot_env_takeover(x->x_glist, (t_plusbob *)deftin, (t_plusbob *)tin); x->x_filehandle = hammerfile_new((t_pd *)x, 0, plustot_env_evalfilehook, 0, 0); while (ac--) { if (av->a_type == A_SYMBOL) plustot_env_evalfile(x, av->a_w.w_symbol); else if (!warned) { loud_warning((t_pd *)x, "bad atom"); warned = 1; } av++; } } else loud_error(0, "+env: cannot initialize"); return (x); }
void plustot_env_setup(void) { plustot_env_class = class_new(gensym("+env"), 0, (t_method)plustot_env_free, sizeof(t_plustot_env), 0, 0); class_addbang(plustot_env_class, plustot_env_bang); class_addmethod(plustot_env_class, (t_method)plustot_env_source, gensym("source"), A_DEFSYM, 0); hammerfile_setup(plustot_env_class, 0); }
--- NEW FILE: plustot.h --- /* Copyright (c) 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. */
#ifndef __PLUSTOT_H__ #define __PLUSTOT_H__
#define PD_EXTERN EXTERN #undef EXTERN #include <tcl.h> #undef EXTERN #define EXTERN PD_EXTERN #undef PD_EXTERN
EXTERN_STRUCT _plustin; #define t_plustin struct _plustin EXTERN_STRUCT _plustob; #define t_plustob struct _plustob EXTERN_STRUCT _plusvar; #define t_plusvar struct _plusvar
t_symbol *plusps_Ti; t_symbol *plusps_To; t_symbol *plusps_Tv;
#define PLUSTOB_MAKEIT ((Tcl_Obj *)-1)
typedef int (*t_plusifsharedfn)(t_plusbob *, Tcl_Obj *);
enum { PLUSTIN_GLIST_THIS, PLUSTIN_GLIST_ANY, PLUSTIN_GLIST_UP };
void plusloud_tclerror(t_pd *caller, Tcl_Interp *interp, char *msg);
t_plustin *plustin_create(t_plustype *tp, t_plusbob *parent, t_symbol *id); Tcl_Interp *plustin_getinterp(t_plustin *tin); t_symbol *plustin_glistid(t_glist *gl); t_plustin *plustin_glistfind(t_glist *gl, int mode); t_plustin *plustin_glistprovide(t_glist *gl, int mode, int create); t_symbol *plustin_getglistname(t_plustin *tin);
t_plustob *plustob_create(t_plustype *tp, t_plustin *tin, Tcl_Obj *ob); t_plustob *plustob_new(t_plustin *tin, Tcl_Obj *ob); void plustob_setifshared(t_plustob *tob, t_plusifsharedfn ifsharedfn); int plustob_isshared(t_plustob *tob); Tcl_Obj *plustob_getvalue(t_plustob *tob); t_plustin *plustag_tobtin(t_symbol *s, t_pd *caller); Tcl_Obj *plustag_tobvalue(t_symbol *s, t_pd *caller); Tcl_Obj *plusatom_tobvalue(t_atom *ap, t_pd *caller); Tcl_Obj *plustob_set(t_plustob *tob, t_plustin *tin, Tcl_Obj *ob); Tcl_Obj *plustob_setfloat(t_plustob *tob, t_float f); Tcl_Obj *plustob_setsymbol(t_plustob *tob, t_symbol *s); Tcl_Obj *plustob_setlist(t_plustob *tob, int ac, t_atom *av); Tcl_Obj *plustob_setbinbuf(t_plustob *tob, t_binbuf *bb); Tcl_Obj *plustob_grabresult(t_plustob *tob); Tcl_Obj *plustob_evalob(t_plustob *tob, Tcl_Obj *ob);
t_plusvar *plusvar_create(t_plustype *tp, t_plustin *tin, Tcl_Obj *ob, char *name, char *index); t_plusvar *plusvar_new(char *name, char *index, t_plustin *tin); Tcl_Obj *plusvar_push(t_plusvar *var); Tcl_Obj *plusvar_pull(t_plusvar *var); Tcl_Obj *plusvar_set(t_plusvar *var, Tcl_Obj *ob, int doit); Tcl_Obj *plusvar_setfloat(t_plusvar *var, t_float f, int doit); Tcl_Obj *plusvar_setsymbol(t_plusvar *var, t_symbol *s, int doit); Tcl_Obj *plusvar_setlist(t_plusvar *var, int ac, t_atom *av, int doit);
void plustot_env_setup(void); void plustot_in_setup(void); void plustot_var_setup(void); void plustot_out_setup(void); void plustot_qlist_setup(void); void plustot_print_setup(void);
void *plustot_env_new(t_symbol *s, int ac, t_atom *av); void *plustot_in_new(t_symbol *s, int ac, t_atom *av); void *plustot_var_new(t_symbol *s, int ac, t_atom *av); void *plustot_out_new(t_symbol *s, int ac, t_atom *av); void *plustot_qlist_new(t_symbol *s, int ac, t_atom *av); void *plustot_print_new(t_symbol *s, int ac, t_atom *av);
#endif
--- NEW FILE: plustot.in.c --- /* Copyright (c) 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 "common/loud.h" #include "toxy/plusbob.h" #include "plustot.h"
typedef struct _plusproxy_in { t_pd pp_pd; t_plustob *pp_tob; } t_plusproxy_in;
typedef struct _plustot_in { t_object x_ob; t_glist *x_glist; t_plustob *x_tob; t_plusproxy_in *x_proxy; } t_plustot_in;
static t_class *plusproxy_in_class; static t_class *plustot_in_class;
static t_plusproxy_in *plusproxy_in_new(t_pd *master) { t_plusproxy_in *pp = (t_plusproxy_in *)pd_new(plusproxy_in_class); pp->pp_tob = ((t_plustot_in *)master)->x_tob; return (pp); }
static void plusproxy_in_float(t_plusproxy_in *pp, t_float f) { plustob_setfloat(pp->pp_tob, f); }
static void plusproxy_in_symbol(t_plusproxy_in *pp, t_symbol *s) { plustob_setsymbol(pp->pp_tob, s); }
static void plusproxy_in_list(t_plusproxy_in *pp, t_symbol *s, int ac, t_atom *av) { plustob_setlist(pp->pp_tob, ac, av); }
static void plustot_in_bang(t_plustot_in *x) { if (plustob_getvalue(x->x_tob)) outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_tob); }
static void plustot_in_float(t_plustot_in *x, t_float f) { if (plustob_setfloat(x->x_tob, f)) outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_tob); }
static void plustot_in_symbol(t_plustot_in *x, t_symbol *s) { if (plustob_setsymbol(x->x_tob, s)) outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_tob); }
static void plustot_in_list(t_plustot_in *x, t_symbol *s, int ac, t_atom *av) { if (plustob_setlist(x->x_tob, ac, av)) outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_tob); }
static void plustot_in_free(t_plustot_in *x) { plusbob_release((t_plusbob *)x->x_tob); if (x->x_proxy) pd_free((t_pd *)x->x_proxy); }
void *plustot_in_new(t_symbol *s, int ac, t_atom *av) { t_plustot_in *x = 0; t_glist *glist = canvas_getcurrent(); t_plustin *tin = 0; t_plustob *tob = 0; if ((tin = plustin_glistprovide(glist, PLUSTIN_GLIST_ANY, 0)) && (tob = plustob_new(tin, 0))) { x = (t_plustot_in *)pd_new(plustot_in_class); plusbob_preserve((t_plusbob *)tob); plusbob_setowner((t_plusbob *)tob, (t_pd *)x); plustob_setlist(tob, ac, av); x->x_glist = glist; x->x_tob = tob; x->x_proxy = plusproxy_in_new((t_pd *)x); inlet_new((t_object *)x, (t_pd *)x->x_proxy, 0, 0); outlet_new((t_object *)x, &s_symbol); } else { loud_error(0, "+in: cannot initialize"); if (tin) { plusbob_preserve((t_plusbob *)tin); plusbob_release((t_plusbob *)tin); } } return (x); }
void plustot_in_setup(void) { plustot_in_class = class_new(gensym("+in"), 0, (t_method)plustot_in_free, sizeof(t_plustot_in), 0, 0); class_addbang(plustot_in_class, plustot_in_bang); class_addfloat(plustot_in_class, plustot_in_float); class_addsymbol(plustot_in_class, plustot_in_symbol); class_addlist(plustot_in_class, plustot_in_list);
plusproxy_in_class = class_new(gensym("+in proxy"), 0, 0, sizeof(t_plusproxy_in), CLASS_PD, 0); class_addfloat(plusproxy_in_class, plusproxy_in_float); class_addsymbol(plusproxy_in_class, plusproxy_in_symbol); class_addlist(plusproxy_in_class, plusproxy_in_list); }
--- NEW FILE: plustot.out.c --- /* Copyright (c) 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 "common/loud.h" #include "toxy/plusbob.h" #include "plustot.h"
typedef struct _plustot_out { t_object x_ob; t_binbuf *x_bb; } t_plustot_out;
static t_class *plustot_out_class;
static void plustot_out_symbol(t_plustot_out *x, t_symbol *s) { Tcl_Obj *ob = plustag_tobvalue(s, (t_pd *)x); if (ob) { int len; char *ptr; Tcl_IncrRefCount(ob); ptr = Tcl_GetStringFromObj(ob, &len); if (ptr && len) { int ac; binbuf_text(x->x_bb, ptr, len); if (ac = binbuf_getnatom(x->x_bb)) { t_atom *av = binbuf_getvec(x->x_bb); if (av->a_type == A_SYMBOL) outlet_anything(((t_object *)x)->ob_outlet, av->a_w.w_symbol, ac - 1, av + 1); else if (av->a_type == A_FLOAT) { if (ac > 1) outlet_list(((t_object *)x)->ob_outlet, &s_list, ac, av); else outlet_float(((t_object *)x)->ob_outlet, av->a_w.w_float); } } } Tcl_DecrRefCount(ob); } }
static void plustot_out_free(t_plustot_out *x) { binbuf_free(x->x_bb); }
void *plustot_out_new(t_symbol *s, int ac, t_atom *av) { t_plustot_out *x = (t_plustot_out *)pd_new(plustot_out_class); x->x_bb = binbuf_new(); outlet_new((t_object *)x, &s_anything); return (x); }
void plustot_out_setup(void) { plustot_out_class = class_new(gensym("+out"), 0, (t_method)plustot_out_free, sizeof(t_plustot_out), 0, 0); class_addsymbol(plustot_out_class, plustot_out_symbol); }
--- NEW FILE: plustot.print.c --- /* Copyright (c) 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 "common/loud.h" #include "toxy/plusbob.h" #include "plustot.h"
typedef struct _plustot_print { t_object x_ob; t_symbol *x_label; t_binbuf *x_bb; } t_plustot_print;
static t_class *plustot_print_class;
static void plustot_print_symbol(t_plustot_print *x, t_symbol *s) { Tcl_Obj *ob = plustag_tobvalue(s, (t_pd *)x); if (ob) { int len; char *ptr; Tcl_IncrRefCount(ob); ptr = Tcl_GetStringFromObj(ob, &len); if (ptr && len) { int ac; binbuf_text(x->x_bb, ptr, len); if (ac = binbuf_getnatom(x->x_bb)) { t_plustin *tin = plustag_tobtin(s, (t_pd *)x); t_symbol *glname = (tin ? plustin_getglistname(tin) : 0); t_atom *av = binbuf_getvec(x->x_bb); if (av->a_type == A_SYMBOL || av->a_type == A_FLOAT) { char *lstring = (x->x_label ? x->x_label->s_name : loud_symbolname(plustag_typename(s, 1, (t_pd *)x), "???")); if (glname) startpost("%s (%s):", lstring, glname->s_name); else startpost("%s:", lstring); } /* FIXME {1.0, 1.0}, etc. */ if (av->a_type == A_SYMBOL) { startpost(" %s", av->a_w.w_symbol->s_name); postatom(ac - 1, av + 1); endpost(); } else if (av->a_type == A_FLOAT) { if (ac > 1) { postatom(ac, av); endpost(); } else post(" %g", av->a_w.w_float); } } /* LATER consider printing empty list as 'bang' */ } Tcl_DecrRefCount(ob); } }
static void plustot_print_free(t_plustot_print *x) { binbuf_free(x->x_bb); }
void *plustot_print_new(t_symbol *s, int ac, t_atom *av) { t_plustot_print *x = (t_plustot_print *)pd_new(plustot_print_class); x->x_label = (ac && av->a_type == A_SYMBOL ? av->a_w.w_symbol : 0); x->x_bb = binbuf_new(); return (x); }
void plustot_print_setup(void) { plustot_print_class = class_new(gensym("+print"), 0, (t_method)plustot_print_free, sizeof(t_plustot_print), 0, 0); class_addsymbol(plustot_print_class, plustot_print_symbol); }
--- NEW FILE: plustot.qlist.c --- /* Copyright (c) 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 "unstable/fragile.h" #include "common/loud.h" #include "toxy/plusbob.h" #include "plustot.h"
#define PLUSTOT_QLIST_DEBUG
/* Need only an access to x_binbuf field. */ typedef struct _qlist { t_object x_ob; t_outlet *x_bangout; void *x_binbuf; } t_qlist;
typedef struct _plusproxy_qlist { t_pd pp_pd; struct _plustot_qlist *pp_master; } t_plusproxy_qlist;
typedef struct _plustot_qlist { t_object x_ob; t_glist *x_glist; t_plustob *x_tob; t_outlet *x_rightout; t_plusproxy_qlist *x_proxy; } t_plustot_qlist;
static t_class *plusproxy_qlist_class; static t_class *plustot_qlist_class;
static t_binbuf *plustot_qlist_usurp(t_plustot_qlist *x) { static t_symbol *types[2]; static int ntypes = 0; t_object *booty; if (ntypes == 0) { types[0] = gensym("qlist"); types[1] = gensym("textfile"); ntypes = 2; } if (booty = fragile_outlet_destination( ((t_object *)x)->ob_outlet, ntypes, types, (t_pd *)x, "(connect left outlet to a qlist or textfile)")) { t_binbuf *bb = ((t_qlist *)booty)->x_binbuf; #ifdef PLUSTOT_QLIST_DEBUG post("booty '%s' at %x:", class_getname(*(t_pd *)booty), (int)booty); binbuf_print(bb); #endif return (bb); } else return (0); }
static t_plusproxy_qlist *plusproxy_qlist_new(t_plustot_qlist *master) { t_plusproxy_qlist *pp = (t_plusproxy_qlist *)pd_new(plusproxy_qlist_class); pp->pp_master = master; return (pp); }
static void plusproxy_qlist_symbol(t_plusproxy_qlist *pp, t_symbol *s) { t_plustot_qlist *x = pp->pp_master; Tcl_Interp *interp = 0; if (plustag_isvalid(s, 0)) { t_plustin *tin; Tcl_Obj *ob; if ((tin = plustag_tobtin(s, PLUSBOB_OWNER)) && (ob = plustob_getvalue((t_plustob *)s))) { t_binbuf *bb; if (bb = plustot_qlist_usurp(x)) { int nlists; Tcl_Obj **lists; interp = plustin_getinterp(tin); if (Tcl_ListObjGetElements(interp, ob, &nlists, &lists) == TCL_OK) { int lc; Tcl_Obj **lp; binbuf_clear(bb); for (lc = 0, lp = lists; lc < nlists; lc++, lp++) { int natoms; Tcl_Obj **atoms; if (Tcl_ListObjGetElements(interp, *lp, &natoms, &atoms) == TCL_OK) { int ac; Tcl_Obj **ap; for (ac = 0, ap = atoms; ac < natoms; ac++, ap++) { double d; int len; char *ptr; Tcl_IncrRefCount(*ap); if (Tcl_GetDoubleFromObj(interp, *ap, &d) == TCL_OK) { t_atom at; SETFLOAT(&at, (float)d); binbuf_add(bb, 1, &at); } else if ((ptr = Tcl_GetStringFromObj(*ap, &len)) && len) { t_atom at; if (ptr[len - 1]) { char buf[MAXPDSTRING]; if (len > MAXPDSTRING - 1) len = MAXPDSTRING - 1; strncpy(buf, ptr, len); buf[len] = 0; ptr = buf; } SETSYMBOL(&at, gensym(ptr)); binbuf_add(bb, 1, &at); } /* FIXME else */ Tcl_DecrRefCount(*ap); } binbuf_addsemi(bb); } else { binbuf_clear(bb); goto notalist; } } } else goto notalist; } } } return; notalist: if (interp) plusloud_tclerror((t_pd *)x, interp, "not a list"); }
static void plustot_qlist_bang(t_plustot_qlist *x) { t_binbuf *bb; if (bb = plustot_qlist_usurp(x)) { if (plustob_setbinbuf(x->x_tob, bb)) outlet_plusbob(x->x_rightout, (t_plusbob *)x->x_tob); } }
static void plustot_qlist_free(t_plustot_qlist *x) { plusbob_release((t_plusbob *)x->x_tob); if (x->x_proxy) pd_free((t_pd *)x->x_proxy); }
void *plustot_qlist_new(t_symbol *s, int ac, t_atom *av) { t_plustot_qlist *x = 0; t_glist *glist = canvas_getcurrent(); t_plustin *tin = 0; t_plustob *tob = 0; if ((tin = plustin_glistprovide(glist, PLUSTIN_GLIST_ANY, 0)) && (tob = plustob_new(tin, 0))) { x = (t_plustot_qlist *)pd_new(plustot_qlist_class); plusbob_preserve((t_plusbob *)tob); plusbob_setowner((t_plusbob *)tob, (t_pd *)x); plustob_setlist(tob, ac, av); x->x_glist = glist; x->x_tob = tob; x->x_proxy = plusproxy_qlist_new(x); inlet_new((t_object *)x, (t_pd *)x->x_proxy, 0, 0); outlet_new((t_object *)x, &s_anything); x->x_rightout = outlet_new((t_object *)x, &s_symbol); } else { loud_error(0, "+qlist: cannot initialize"); if (tin) { plusbob_preserve((t_plusbob *)tin); plusbob_release((t_plusbob *)tin); } } return (x); }
void plustot_qlist_setup(void) { plustot_qlist_class = class_new(gensym("+qlist"), 0, (t_method)plustot_qlist_free, sizeof(t_plustot_qlist), 0, 0); class_addbang(plustot_qlist_class, plustot_qlist_bang);
plusproxy_qlist_class = class_new(gensym("+qlist proxy"), 0, 0, sizeof(t_plusproxy_qlist), CLASS_PD, 0); class_addsymbol(plusproxy_qlist_class, plusproxy_qlist_symbol); }
--- NEW FILE: plustot.var.c --- /* Copyright (c) 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 "common/loud.h" #include "toxy/plusbob.h" #include "plustot.h"
typedef struct _plusproxy_var { t_pd pp_pd; t_plusvar *pp_var; } t_plusproxy_var;
typedef struct _plustot_var { t_object x_ob; t_glist *x_glist; t_plusvar *x_var; t_plusproxy_var *x_proxy; } t_plustot_var;
static t_class *plusproxy_var_class; static t_class *plustot_var_class;
static t_plusproxy_var *plusproxy_var_new(t_pd *master) { t_plusproxy_var *pp = (t_plusproxy_var *)pd_new(plusproxy_var_class); pp->pp_var = ((t_plustot_var *)master)->x_var; return (pp); }
static void plusproxy_var_float(t_plusproxy_var *pp, t_float f) { plusvar_setfloat(pp->pp_var, f, 1); }
static void plusproxy_var_symbol(t_plusproxy_var *pp, t_symbol *s) { plusvar_setsymbol(pp->pp_var, s, 1); }
static void plusproxy_var_list(t_plusproxy_var *pp, t_symbol *s, int ac, t_atom *av) { plusvar_setlist(pp->pp_var, ac, av, 1); }
static void plustot_var_bang(t_plustot_var *x) { if (plusvar_pull(x->x_var)) outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_var); }
static void plustot_var_float(t_plustot_var *x, t_float f) { if (plusvar_setfloat(x->x_var, f, 1)) outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_var); }
static void plustot_var_symbol(t_plustot_var *x, t_symbol *s) { if (plusvar_setsymbol(x->x_var, s, 1)) outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_var); }
static void plustot_var_list(t_plustot_var *x, t_symbol *s, int ac, t_atom *av) { if (plusvar_setlist(x->x_var, ac, av, 1)) outlet_plusbob(((t_object *)x)->ob_outlet, (t_plusbob *)x->x_var); }
static void plustot_var_free(t_plustot_var *x) { plusbob_release((t_plusbob *)x->x_var); if (x->x_proxy) pd_free((t_pd *)x->x_proxy); }
void *plustot_var_new(t_symbol *s, int ac, t_atom *av) { t_plustot_var *x = 0; t_glist *glist = canvas_getcurrent(); t_plustin *tin = 0; t_plusvar *var = 0; if (ac && av->a_type == A_SYMBOL && (tin = plustin_glistprovide(glist, PLUSTIN_GLIST_ANY, 0)) && (var = plusvar_new(av->a_w.w_symbol->s_name, 0, tin))) { x = (t_plustot_var *)pd_new(plustot_var_class); plusbob_preserve((t_plusbob *)var); plusbob_setowner((t_plusbob *)var, (t_pd *)x); plusvar_setlist(var, ac - 1, av + 1, 1); x->x_glist = glist; x->x_var = var; x->x_proxy = plusproxy_var_new((t_pd *)x); inlet_new((t_object *)x, (t_pd *)x->x_proxy, 0, 0); outlet_new((t_object *)x, &s_symbol); } else { if (!ac || av->a_type != A_SYMBOL) loud_error(0, "+var: missing name of a variable"); else loud_error(0, "+var: cannot initialize"); if (tin) { plusbob_preserve((t_plusbob *)tin); plusbob_release((t_plusbob *)tin); } } return (x); }
void plustot_var_setup(void) { plustot_var_class = class_new(gensym("+var"), 0, (t_method)plustot_var_free, sizeof(t_plustot_var), 0, 0); class_addbang(plustot_var_class, plustot_var_bang); class_addfloat(plustot_var_class, plustot_var_float); class_addsymbol(plustot_var_class, plustot_var_symbol); class_addlist(plustot_var_class, plustot_var_list);
plusproxy_var_class = class_new(gensym("+var proxy"), 0, 0, sizeof(t_plusproxy_var), CLASS_PD, 0); class_addfloat(plusproxy_var_class, plusproxy_var_float); class_addsymbol(plusproxy_var_class, plusproxy_var_symbol); class_addlist(plusproxy_var_class, plusproxy_var_list); }
Index: Makefile =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 24 Sep 2003 10:46:19 -0000 1.1 --- Makefile 19 Feb 2004 22:23:18 -0000 1.2 *************** *** 1,2 **** --- 1,6 ---- ROOT_DIR = .. + redefault: default.wiq default + default.wiq: $(ROOT_DIR)/test/toxy/default.wid + $(ROOT_DIR)/quoteinitializer $< \ + '"puts [concat loading built-in widget definitions]\n"' > $@ include $(ROOT_DIR)/Makefile.common
Index: Makefile.objects =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/Makefile.objects,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.objects 26 Sep 2003 07:29:14 -0000 1.2 --- Makefile.objects 19 Feb 2004 22:23:18 -0000 1.3 *************** *** 8,11 **** --- 8,31 ---- toxy/scriptlet.o
+ PLUSTOT_OBJECTS = \ + unstable/fragile.o \ + unstable/forky.o \ + common/loud.o \ + common/grow.o \ + hammer/file.o \ + common/props.o \ + toxy/scriptlet.o \ + toxy/plusbob.o + + PLUSTOT_PRIVATEOBJECTS = \ + plustot.env.o \ + plustot.in.o \ + plustot.var.o \ + plustot.out.o \ + plustot.qlist.o \ + plustot.print.o + + PLUSTOT_LIBS = $(TCL_LIB) + TOW_OBJECTS = \ common/loud.o \
Index: Makefile.sources =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/Makefile.sources,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile.sources 24 Sep 2003 10:46:19 -0000 1.1 --- Makefile.sources 19 Feb 2004 22:23:18 -0000 1.2 *************** *** 1,5 **** ! TYPES = TOT TOW WIDGET
TOT_SOURCES = tot.c TOW_SOURCES = tow.c WIDGET_SOURCES = widget.c --- 1,6 ---- ! TYPES = TOT TOW WIDGET PLUSTOT
TOT_SOURCES = tot.c TOW_SOURCES = tow.c WIDGET_SOURCES = widget.c + PLUSTOT_SOURCES = plustot.c
Index: build_counter =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/build_counter,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** build_counter 24 Sep 2003 10:46:19 -0000 1.1 --- build_counter 19 Feb 2004 22:23:18 -0000 1.2 *************** *** 1,3 **** #define TOXY_VERSION "0.1" #define TOXY_RELEASE "alpha" ! #define TOXY_BUILD 1 --- 1,3 ---- #define TOXY_VERSION "0.1" #define TOXY_RELEASE "alpha" ! #define TOXY_BUILD 2
Index: tot.c =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/tot.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tot.c 3 Oct 2003 12:08:32 -0000 1.2 --- tot.c 19 Feb 2004 22:23:18 -0000 1.3 *************** *** 457,465 **** sprintf(buf, "tot%x", (int)x); pd_bind((t_pd *)x, x->x_target = gensym(buf)); - x->x_transient = - scriptlet_new((t_pd *)x, x->x_target, x->x_target, 0, tot_cvhook); - x->x_persistent = - scriptlet_new((t_pd *)x, x->x_target, x->x_target, 0, tot_cvhook); x->x_glist = canvas_getcurrent(); if (s1 && s1 != &s_ && strcmp(s1->s_name, ".")) { --- 457,465 ---- sprintf(buf, "tot%x", (int)x); pd_bind((t_pd *)x, x->x_target = gensym(buf)); x->x_glist = canvas_getcurrent(); + x->x_transient = scriptlet_new((t_pd *)x, x->x_target, x->x_target, + 0, x->x_glist, tot_cvhook); + x->x_persistent = scriptlet_new((t_pd *)x, x->x_target, x->x_target, + 0, x->x_glist, tot_cvhook); if (s1 && s1 != &s_ && strcmp(s1->s_name, ".")) {
Index: toxy-shared.include =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/toxy-shared.include,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** toxy-shared.include 3 Oct 2003 12:08:32 -0000 1.2 --- toxy-shared.include 19 Feb 2004 22:23:18 -0000 1.3 *************** *** 10,13 **** --- 10,15 ---- shared/hammer/gui.c shared/hammer/gui.h + shared/unstable/fragile.c + shared/unstable/fragile.h shared/unstable/forky.c shared/unstable/forky.h *************** *** 17,20 **** --- 19,24 ---- shared/common/props.c shared/common/props.h + shared/toxy/plusbob.c + shared/toxy/plusbob.h shared/toxy/scriptlet.c shared/toxy/scriptlet.h
Index: widget.c =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/widget.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** widget.c 3 Oct 2003 12:08:32 -0000 1.2 --- widget.c 19 Feb 2004 22:23:18 -0000 1.3 *************** *** 24,28 **** //#define TOW_DEBUG
! enum { WIDGET_NOUPDATE = 0, WIDGET_RECONFIG, WIDGET_REVIS };
typedef struct _towentry --- 24,28 ---- //#define TOW_DEBUG
! enum { WIDGET_NOVIS = 0, WIDGET_PUSHVIS, WIDGET_REVIS };
typedef struct _towentry *************** *** 63,69 **** t_symbol *x_background; int x_hasstate; - int x_update; /* see widget_update() */ - int x_selected; int x_disabled; int x_vised; t_clock *x_transclock; --- 63,69 ---- t_symbol *x_background; int x_hasstate; int x_disabled; + int x_selected; + int x_update; /* see widget_update() */ int x_vised; t_clock *x_transclock; *************** *** 96,103 **** static t_symbol *widgetps_atfloat; static t_symbol *widgetps_atsymbol;
! static char *widget_propsresolver(t_pd *z, int ac, t_atom *av) { ! t_widget *x = (t_widget *)z; int len; scriptlet_reset(x->x_auxscript); --- 96,105 ---- static t_symbol *widgetps_atfloat; static t_symbol *widgetps_atsymbol; + static t_symbol *widgetps_atstore; + static t_symbol *widgetps_atrestore;
! static char *widget_propsresolver(t_pd *owner, int ac, t_atom *av) { ! t_widget *x = (t_widget *)owner; int len; scriptlet_reset(x->x_auxscript); *************** *** 108,114 **** }
! static t_canvas *widget_cvhook(t_pd *z) { ! return (glist_getcanvas(((t_widget *)z)->x_glist)); }
--- 110,116 ---- }
! static t_canvas *widget_cvhook(t_pd *caller) { ! return (glist_getcanvas(((t_widget *)caller)->x_glist)); }
*************** *** 166,177 **** t_text *newt, *oldt = (t_text *)x; t_binbuf *bb = binbuf_new(); ! int nopt, nbnd, narg; t_atom *opt = props_getall(x->x_options, &nopt); ! t_atom *bnd = props_getall(x->x_handlers, &nbnd); t_atom *arg = props_getall(x->x_arguments, &narg); binbuf_addv(bb, "sss", gensym("widget"), x->x_type, x->x_name); if (narg) binbuf_add(bb, narg, arg); if (nopt) binbuf_add(bb, nopt, opt); ! if (nbnd) binbuf_add(bb, nbnd, bnd); canvas_setcurrent(x->x_glist); newt = (t_text *)pd_new(makeshift_class); --- 168,179 ---- t_text *newt, *oldt = (t_text *)x; t_binbuf *bb = binbuf_new(); ! int nopt, nhnd, narg; t_atom *opt = props_getall(x->x_options, &nopt); ! t_atom *hnd = props_getall(x->x_handlers, &nhnd); t_atom *arg = props_getall(x->x_arguments, &narg); binbuf_addv(bb, "sss", gensym("widget"), x->x_type, x->x_name); if (narg) binbuf_add(bb, narg, arg); if (nopt) binbuf_add(bb, nopt, opt); ! if (nhnd) binbuf_add(bb, nhnd, hnd); canvas_setcurrent(x->x_glist); newt = (t_text *)pd_new(makeshift_class); *************** *** 212,215 **** --- 214,221 ---- t_widget *x = (t_widget *)z; t_text *t = (t_text *)z; + #if 0 + post("displace %d %d (%d %d -> %d %d)", + dx, dy, t->te_xpix, t->te_ypix, t->te_xpix + dx, t->te_ypix + dy); + #endif t->te_xpix += dx; t->te_ypix += dy; *************** *** 220,228 **** }
! static void widget_select(t_gobj *z, t_glist *glist, int state) { t_widget *x = (t_widget *)z; char *mypathname = widget_getmypathname(x, glist)->s_name; ! if (state) { sys_vgui("%s config -bg blue %s\n", mypathname, --- 226,234 ---- }
! static void widget_select(t_gobj *z, t_glist *glist, int flag) { t_widget *x = (t_widget *)z; char *mypathname = widget_getmypathname(x, glist)->s_name; ! if (flag) { sys_vgui("%s config -bg blue %s\n", mypathname, *************** *** 236,240 **** (x->x_background ? x->x_background->s_name : "gray")); else ! sys_vgui("%s config -bg %s\n", mypathname, (x->x_background ? x->x_background->s_name : "gray"), (x->x_hasstate ? "-state normal" : "")); --- 242,246 ---- (x->x_background ? x->x_background->s_name : "gray")); else ! sys_vgui("%s config -bg %s %s\n", mypathname, (x->x_background ? x->x_background->s_name : "gray"), (x->x_hasstate ? "-state normal" : "")); *************** *** 291,294 **** --- 297,307 ---- }
+ static void widget_getconfig(t_widget *x) + { + sys_vgui("::toxy::itemgetconfig %s %s\n", + widget_getmypathname(x, x->x_glist)->s_name, + x->x_cbtarget->s_name); + } + static void widget_vis(t_gobj *z, t_glist *glist, int vis) { *************** *** 297,301 **** char *cvpathname = widget_getcvpathname(x, glist)->s_name; char *mypathname = widget_getmypathname(x, glist)->s_name; ! x->x_update = WIDGET_NOUPDATE; if (vis) { --- 310,314 ---- char *cvpathname = widget_getcvpathname(x, glist)->s_name; char *mypathname = widget_getmypathname(x, glist)->s_name; ! x->x_update = WIDGET_NOVIS; if (vis) { *************** *** 319,327 **** if (rt) rtext_free(rt); #endif ! if (x->x_vised) ! { ! sys_vgui("destroy %s\n", mypathname); ! x->x_vised = 0; ! } } } --- 332,336 ---- if (rt) rtext_free(rt); #endif ! x->x_vised = 0; } } *************** *** 331,337 **** t_widget *x = (t_widget *)z; t_text *t = (t_text *)x; ! int nopt, nbnd, narg; t_atom *opt = props_getall(x->x_options, &nopt); ! t_atom *bnd = props_getall(x->x_handlers, &nbnd); t_atom *arg = props_getall(x->x_arguments, &narg); binbuf_addv(bb, "ssiisss", gensym("#X"), gensym("obj"), --- 340,346 ---- t_widget *x = (t_widget *)z; t_text *t = (t_text *)x; ! int nopt, nhnd, narg; t_atom *opt = props_getall(x->x_options, &nopt); ! t_atom *hnd = props_getall(x->x_handlers, &nhnd); t_atom *arg = props_getall(x->x_arguments, &narg); binbuf_addv(bb, "ssiisss", gensym("#X"), gensym("obj"), *************** *** 340,344 **** if (narg) binbuf_add(bb, narg, arg); if (nopt) binbuf_add(bb, nopt, opt); ! if (nbnd) binbuf_add(bb, nbnd, bnd); binbuf_addsemi(bb); } --- 349,353 ---- if (narg) binbuf_add(bb, narg, arg); if (nopt) binbuf_add(bb, nopt, opt); ! if (nhnd) binbuf_add(bb, nhnd, hnd); binbuf_addsemi(bb); } *************** *** 406,430 **** };
! static void widget_update(t_widget *x) { ! t_atom *ap; ! int ac; ! scriptlet_reset(x->x_optscript); ! ap = props_getall(widgettype_getoptions(x->x_typedef), &ac); ! if (ac) scriptlet_add(x->x_optscript, 0, 0, ac, ap); ! ap = props_getall(x->x_options, &ac); ! if (ac) scriptlet_add(x->x_optscript, 0, 0, ac, ap); ! if (x->x_update && ! glist_isvisible(x->x_glist)) /* FIXME the condition */ { ! if (x->x_update == WIDGET_REVIS) { ! widget_vis((t_gobj *)x, x->x_glist, 0); ! widget_vis((t_gobj *)x, x->x_glist, 1); } - else widget_pushoptions(x, 1); - x->x_update = WIDGET_NOUPDATE; } ! /* LATER cache handlers */ }
--- 415,449 ---- };
! static void widget_update(t_widget *x, t_props *op) { ! if (op == x->x_options) { ! t_atom *ap; ! int ac; ! scriptlet_reset(x->x_optscript); ! ap = props_getall(widgettype_getoptions(x->x_typedef), &ac); ! if (ac) scriptlet_add(x->x_optscript, 0, 0, ac, ap); ! ap = props_getall(x->x_options, &ac); ! if (ac) scriptlet_add(x->x_optscript, 0, 0, ac, ap); ! if (x->x_update && ! glist_isvisible(x->x_glist)) /* FIXME the condition */ { ! if (x->x_update == WIDGET_REVIS) ! { ! widget_vis((t_gobj *)x, x->x_glist, 0); ! widget_vis((t_gobj *)x, x->x_glist, 1); ! } ! else if (x->x_update == WIDGET_PUSHVIS) ! { ! widget_pushoptions(x, 1); ! widget_getconfig(x); ! } ! x->x_update = WIDGET_NOVIS; } } ! else ! { ! /* LATER cache handlers */ ! } }
*************** *** 439,443 **** loud_error((t_pd *)x, "no value given for %s '%s'", props_getname(op), empty->s_name); ! widget_update(x); return (empty); } --- 458,462 ---- loud_error((t_pd *)x, "no value given for %s '%s'", props_getname(op), empty->s_name); ! widget_update(x, op); return (empty); } *************** *** 465,469 **** { t_symbol *empty; ! x->x_update = WIDGET_RECONFIG; if (empty = widget_addmessage(x, s, ac, av)) loud_errand((t_pd *)x, --- 484,488 ---- { t_symbol *empty; ! x->x_update = WIDGET_PUSHVIS; if (empty = widget_addmessage(x, s, ac, av)) loud_errand((t_pd *)x, *************** *** 559,562 **** --- 578,595 ---- }
+ static void widget_store(t_widget *x, t_symbol *s) + { + if (s == &s_) + s = x->x_varname; + /* FIXME */ + } + + static void widget_restore(t_widget *x, t_symbol *s) + { + if (s == &s_) + s = x->x_varname; + /* FIXME */ + } + static void widget_set(t_widget *x, t_symbol *s, int ac, t_atom *av) { *************** *** 565,572 **** { t_symbol *empty = 0; - x->x_update = WIDGET_RECONFIG; ac--; av++; if (*prp->s_name == '-') empty = widget_addprops(x, x->x_options, 1, prp, ac, av); else if (*prp->s_name == '@') empty = widget_addprops(x, x->x_handlers, 1, prp, ac, av); --- 598,607 ---- { t_symbol *empty = 0; ac--; av++; if (*prp->s_name == '-') + { + x->x_update = WIDGET_PUSHVIS; empty = widget_addprops(x, x->x_options, 1, prp, ac, av); + } else if (*prp->s_name == '@') empty = widget_addprops(x, x->x_handlers, 1, prp, ac, av); *************** *** 596,601 **** if (op && props_remove(op, s)) { ! x->x_update = WIDGET_REVIS; ! widget_update(x); } else loud_warning((t_pd *)x, "%s %s has not been specified", --- 631,636 ---- if (op && props_remove(op, s)) { ! if (op == x->x_options) x->x_update = WIDGET_REVIS; ! widget_update(x, op); } else loud_warning((t_pd *)x, "%s %s has not been specified", *************** *** 626,630 **** { x->x_update = WIDGET_REVIS; ! widget_update(x); }
--- 661,667 ---- { x->x_update = WIDGET_REVIS; ! widget_update(x, x->x_options); ! widget_update(x, x->x_handlers); ! widget_update(x, x->x_arguments); }
*************** *** 683,693 **** }
! /* FIXME this is a hack (see also widget_select) */ ! /* FIXME why <Leave> is being issued on button press? */ static void widget__inout(t_widget *x, t_floatarg f) { if (x->x_disabled) { ! if (!x->x_glist->gl_edit) { if (!x->x_selected) --- 720,730 ---- }
! /* see also widget_select() */ static void widget__inout(t_widget *x, t_floatarg f) { + int disable = (int)f && x->x_glist->gl_edit; if (x->x_disabled) { ! if (!disable) { if (!x->x_selected) *************** *** 700,751 **** } } ! else if ((int)f && x->x_glist->gl_edit) { ! char *mypathname = widget_getmypathname(x, x->x_glist)->s_name; ! if (x->x_hasstate) ! sys_vgui("%s config -state disabled\n", mypathname); x->x_disabled = 1; } }
! static void widget__click(t_widget *x, t_floatarg fx, t_floatarg fy, ! t_floatarg fb, t_floatarg fm) { if (x->x_glist->gl_havewindow) /* LATER calculate on-parent coords */ { - t_text *t = (t_text *)x; - t_atom at[4]; - fx += t->te_xpix; - fy += t->te_ypix; - SETFLOAT(&at[0], fx); - SETFLOAT(&at[1], fy); - SETFLOAT(&at[2], fb); - SETFLOAT(&at[3], fm); if (x->x_cvtarget->s_thing) /* LATER rethink */ ! typedmess(x->x_cvtarget->s_thing, widgetps_mouse, 4, at); else ! typedmess((t_pd *)x->x_glist, widgetps_mouse, 4, at); ! widget__inout(x, 1.); } }
/* LATER think how to grab the mouse when dragging */ ! static void widget__motion(t_widget *x, t_floatarg fx, t_floatarg fy) { if (x->x_glist->gl_havewindow) /* LATER calculate on-parent coords */ { ! t_text *t = (t_text *)x; ! t_atom at[3]; ! fx += t->te_xpix; ! fy += t->te_ypix; ! SETFLOAT(&at[0], fx); ! SETFLOAT(&at[1], fy); ! SETFLOAT(&at[2], 0); if (x->x_cvtarget->s_thing) /* LATER rethink */ ! typedmess(x->x_cvtarget->s_thing, widgetps_motion, 3, at); else ! typedmess((t_pd *)x->x_glist, widgetps_motion, 3, at); } } --- 737,788 ---- } } ! else if (disable) { ! if (!x->x_selected) ! { ! char *mypathname = widget_getmypathname(x, x->x_glist)->s_name; ! if (x->x_hasstate) ! sys_vgui("%s config -state disabled\n", mypathname); ! } x->x_disabled = 1; } }
! static void widget__click(t_widget *x, t_symbol *s, int ac, t_atom *av) { + if (ac != 4) + { + loud_error((t_pd *)x, "bad arguments to the '%s' method", s->s_name); + return; + } if (x->x_glist->gl_havewindow) /* LATER calculate on-parent coords */ { if (x->x_cvtarget->s_thing) /* LATER rethink */ ! typedmess(x->x_cvtarget->s_thing, widgetps_mouse, ac, av); else ! typedmess((t_pd *)x->x_glist, widgetps_mouse, ac, av); ! widget__inout(x, 2.); } }
/* LATER think how to grab the mouse when dragging */ ! static void widget__motion(t_widget *x, t_symbol *s, int ac, t_atom *av) { + if (ac != 3) + { + loud_error((t_pd *)x, "bad arguments to the '%s' method", s->s_name); + return; + } if (x->x_glist->gl_havewindow) /* LATER calculate on-parent coords */ { ! #if 0 ! post("motion %g %g", av[0].a_w.w_float, av[1].a_w.w_float); ! #endif if (x->x_cvtarget->s_thing) /* LATER rethink */ ! typedmess(x->x_cvtarget->s_thing, widgetps_motion, ac, av); else ! typedmess((t_pd *)x->x_glist, widgetps_motion, ac, av); } } *************** *** 800,803 **** --- 837,842 ---- bp = scriptlet_getcontents(x->x_iniscript, &sz); post("instance initializer (size %d):\n"%s"", sz, bp); + bp = masterwidget_getcontents(&sz); + post("setup definitions (size %d):\n"%s"", sz, bp); } #endif *************** *** 816,819 **** --- 855,860 ---- static void widget_free(t_widget *x) { + sys_vgui("::toxy::itemdestroy %s %s\n", + widget_getmypathname(x, x->x_glist)->s_name, x->x_varname->s_name); gui_unbind((t_pd *)x, x->x_cbtarget); gui_unbind((t_pd *)x, x->x_rptarget); *************** *** 863,874 **** x->x_tkclass = x->x_type;
x->x_iniscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget, ! x->x_name, widget_cvhook); x->x_optscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget, ! x->x_name, widget_cvhook); x->x_auxscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget, ! x->x_name, widget_cvhook); x->x_transient = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget, ! x->x_name, widget_cvhook);
x->x_options = props_new((t_pd *)x, "option", "-", 0, 0); --- 904,923 ---- x->x_tkclass = x->x_type;
+ x->x_glist = canvas_getcurrent(); + sprintf(buf, ".x%x.c", (int)x->x_glist); + x->x_cvpathname = gensym(buf); + sprintf(buf, ".x%x", (int)x->x_glist); + x->x_cvtarget = gensym(buf); + sprintf(buf, "::toxy::v%x", (int)x); + x->x_varname = gensym(buf); + x->x_iniscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget, ! x->x_name, x->x_glist, widget_cvhook); x->x_optscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget, ! x->x_name, x->x_glist, widget_cvhook); x->x_auxscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget, ! x->x_name, x->x_glist, widget_cvhook); x->x_transient = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget, ! x->x_name, x->x_glist, widget_cvhook);
x->x_options = props_new((t_pd *)x, "option", "-", 0, 0); *************** *** 877,888 **** widget_propsresolver);
- sprintf(buf, ".^.c.%s%x", x->x_name->s_name, (int)x); - x->x_glist = canvas_getcurrent(); - sprintf(buf, ".x%x.c", (int)x->x_glist); - x->x_cvpathname = gensym(buf); - sprintf(buf, ".x%x", (int)x->x_glist); - x->x_cvtarget = gensym(buf); - sprintf(buf, "::toxy::v%x", (int)x); - x->x_varname = gensym(buf); outlet_new((t_object *)x, &s_anything); /* LATER consider estimating these, based on widget class and options */ --- 926,929 ---- *************** *** 895,899 **** x->x_background = 0; x->x_hasstate = 0; ! x->x_update = WIDGET_NOUPDATE; x->x_disabled = 0; x->x_vised = 0; --- 936,940 ---- x->x_background = 0; x->x_hasstate = 0; ! x->x_update = WIDGET_NOVIS; x->x_disabled = 0; x->x_vised = 0; *************** *** 1154,1157 **** --- 1195,1200 ---- widgetps_atfloat = gensym("@float"); widgetps_atsymbol = gensym("@symbol"); + widgetps_atstore = gensym("@store"); + widgetps_atrestore = gensym("@restore"); widgettype_setup(); widget_class = class_new(gensym("widget"), *************** *** 1166,1169 **** --- 1209,1216 ---- class_addsymbol(widget_class, widget_symbol); class_addanything(widget_class, widget_anything); + class_addmethod(widget_class, (t_method)widget_store, + gensym("store"), A_DEFSYMBOL, 0); + class_addmethod(widget_class, (t_method)widget_restore, + gensym("restore"), A_DEFSYMBOL, 0); class_addmethod(widget_class, (t_method)widget_set, gensym("set"), A_GIMME, 0); *************** *** 1188,1194 **** gensym("_inout"), A_FLOAT, 0); class_addmethod(widget_class, (t_method)widget__click, ! gensym("_click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); class_addmethod(widget_class, (t_method)widget__motion, ! gensym("_motion"), A_FLOAT, A_FLOAT, 0); #ifdef WIDGET_DEBUG class_addmethod(widget_class, (t_method)widget_debug, --- 1235,1241 ---- gensym("_inout"), A_FLOAT, 0); class_addmethod(widget_class, (t_method)widget__click, ! gensym("_click"), A_GIMME, 0); class_addmethod(widget_class, (t_method)widget__motion, ! gensym("_motion"), A_GIMME, 0); #ifdef WIDGET_DEBUG class_addmethod(widget_class, (t_method)widget_debug,
Index: widgettype.c =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/widgettype.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** widgettype.c 3 Oct 2003 12:08:32 -0000 1.2 --- widgettype.c 19 Feb 2004 22:23:18 -0000 1.3 *************** *** 12,15 **** --- 12,19 ---- #include "widgettype.h"
+ static char masterwidget_builtin[] = + #include "default.wiq" + ; + #define WIDGETTYPE_VERBOSE //#define WIDGETTYPE_DEBUG *************** *** 43,47 **** static t_masterwidget *masterwidget = 0;
! static t_canvas *widgettype_cvhook(t_pd *z) { return (0); --- 47,51 ---- static t_masterwidget *masterwidget = 0;
! static t_canvas *widgettype_cvhook(t_pd *caller) { return (0); *************** *** 64,83 **** wt->wt_arguments = props_new(0, "argument", "#", wt->wt_options, 0); wt->wt_iniscript = scriptlet_new((t_pd *)wt, mw->mw_target, mw->mw_target, ! 0, widgettype_cvhook); dict_bind(mw->mw_typemap, (t_pd *)wt, wt->wt_typekey); return (wt); }
! static t_canvas *masterwidget_cvhook(t_pd *z) { return (0); }
! static t_scriptlet *masterwidget_cmnthook(t_pd *z, char *rc, char sel, char *buf) { t_masterwidget *mw = masterwidget; if (!*buf) ! return (0); if (sel == '>') { --- 68,87 ---- wt->wt_arguments = props_new(0, "argument", "#", wt->wt_options, 0); wt->wt_iniscript = scriptlet_new((t_pd *)wt, mw->mw_target, mw->mw_target, ! 0, 0, widgettype_cvhook); dict_bind(mw->mw_typemap, (t_pd *)wt, wt->wt_typekey); return (wt); }
! static t_canvas *masterwidget_cvhook(t_pd *caller) { return (0); }
! static t_scriptlet *masterwidget_cmnthook(t_pd *caller, char *rc, char sel, char *buf) { t_masterwidget *mw = masterwidget; if (!*buf) ! return (SCRIPTLET_UNLOCK); if (sel == '>') { *************** *** 91,111 **** typekey = dict_key(mw->mw_typemap, buf); typeval = (t_widgettype *)dict_value(mw->mw_typemap, typekey); ! if (z == (t_pd *)mw) ! { /* default.wid */ ! if (typeval) { ! /* LATER rethink */ ! loud_warning((t_pd *)mw, "redefinition of '%s'\ in "%s.wid" file, ignored", buf, rc); ! return (0); } } else { /* <type>.wid */ ! if (z != (t_pd *)typeval) { loud_warning((t_pd *)mw, "alien definition of '%s'\ in "%s.wid" file, ignored", buf, rc); ! return (0); } } --- 95,123 ---- typekey = dict_key(mw->mw_typemap, buf); typeval = (t_widgettype *)dict_value(mw->mw_typemap, typekey); ! if (caller == (t_pd *)mw) ! { /* default.wid or built-in defaults */ ! if (mw->mw_defaulttype) ! { /* no default type in default.wid, extracting built-in one */ ! if (typeval != mw->mw_defaulttype) ! return (SCRIPTLET_LOCK); ! } ! else { ! if (typeval) ! { ! /* LATER rethink */ ! loud_warning((t_pd *)mw, "redefinition of '%s'\ in "%s.wid" file, ignored", buf, rc); ! return (SCRIPTLET_LOCK); ! } } } else { /* <type>.wid */ ! if (caller != (t_pd *)typeval) { loud_warning((t_pd *)mw, "alien definition of '%s'\ in "%s.wid" file, ignored", buf, rc); ! return (SCRIPTLET_LOCK); } } *************** *** 151,155 **** } } ! return (0); }
--- 163,167 ---- } } ! return (SCRIPTLET_UNLOCK); }
*************** *** 171,181 **** if (masterwidget->mw_parsedtype) { ! if (scriptlet_rcload(wt->wt_iniscript, s->s_name, ".wid", ! masterwidget_cmnthook) == SCRIPTLET_OK) { #ifdef WIDGETTYPE_VERBOSE post("using %s's initializer", s->s_name); #endif } } return (wt); --- 183,211 ---- if (masterwidget->mw_parsedtype) { ! t_scriptlet *mwsp = ! scriptlet_new((t_pd *)masterwidget, masterwidget->mw_target, ! masterwidget->mw_target, 0, 0, 0); ! if (scriptlet_rcload(mwsp, (t_pd *)wt, ! s->s_name, ".wid", 0, masterwidget_cmnthook) ! == SCRIPTLET_OK) { #ifdef WIDGETTYPE_VERBOSE post("using %s's initializer", s->s_name); #endif + if (!scriptlet_isempty(mwsp)) + { + t_scriptlet *sp = + scriptlet_new((t_pd *)masterwidget, masterwidget->mw_target, + masterwidget->mw_target, 0, 0, 0); + if (scriptlet_evaluate(mwsp, sp, 0, 0, 0, 0)) + { + scriptlet_push(sp); + scriptlet_append(masterwidget->mw_setupscript, mwsp); + } + else bug("widgettype_get"); + scriptlet_free(sp); + } } + scriptlet_free(mwsp); } return (wt); *************** *** 219,229 **** }
- int masterwidget_evaluate(t_scriptlet *outsp, int visedonly, - int ac, t_atom *av, t_props *argprops) - { - return (scriptlet_evaluate(masterwidget->mw_defaulttype->wt_iniscript, - outsp, visedonly, ac, av, argprops)); - } - void widgettype_setup(void) { --- 249,252 ---- *************** *** 239,245 **** }
void masterwidget_initialize(void) { ! t_scriptlet *sp; t_symbol *typekey; t_widgettype *typeval; --- 262,280 ---- }
+ int masterwidget_evaluate(t_scriptlet *outsp, int visedonly, + int ac, t_atom *av, t_props *argprops) + { + return (scriptlet_evaluate(masterwidget->mw_defaulttype->wt_iniscript, + outsp, visedonly, ac, av, argprops)); + } + + char *masterwidget_getcontents(int *szp) + { + return (scriptlet_getcontents(masterwidget->mw_setupscript, szp)); + } + void masterwidget_initialize(void) { ! int rcresult; t_symbol *typekey; t_widgettype *typeval; *************** *** 254,265 **** masterwidget->mw_typemap = dict_new(0);
! sp = masterwidget->mw_setupscript = scriptlet_new((t_pd *)masterwidget, masterwidget->mw_target, ! masterwidget->mw_target, 0, 0); ! masterwidget->mw_parsedtype = 0; masterwidget->mw_bb = binbuf_new();
! if (scriptlet_rcload(sp, "default", ".wid", ! masterwidget_cmnthook) == SCRIPTLET_OK) { #ifdef WIDGETTYPE_VERBOSE --- 289,303 ---- masterwidget->mw_typemap = dict_new(0);
! masterwidget->mw_setupscript = scriptlet_new((t_pd *)masterwidget, masterwidget->mw_target, ! masterwidget->mw_target, 0, 0, 0); masterwidget->mw_bb = binbuf_new(); + masterwidget->mw_parsedtype = 0; + masterwidget->mw_defaulttype = 0;
! rcresult = ! scriptlet_rcload(masterwidget->mw_setupscript, 0, "default", ".wid", ! masterwidget_builtin, masterwidget_cmnthook); ! if (rcresult == SCRIPTLET_OK) { #ifdef WIDGETTYPE_VERBOSE *************** *** 269,300 **** else { ! loud_warning((t_pd *)masterwidget, "missing file 'default.wid'"); ! ! /* no setup scriptlet, LATER use built-in default */ ! #if 0 ! scriptlet_reset(sp); ! scriptlet_addstring(sp, ... ! #endif } typekey = dict_key(masterwidget->mw_typemap, "default"); ! if (typeval = (t_widgettype *)dict_value(masterwidget->mw_typemap, typekey)) masterwidget->mw_defaulttype = typeval; ! else { ! /* no master initializer, LATER use built-in default */ masterwidget->mw_defaulttype = widgettype_new(masterwidget, "default", 0, 0); ! sp = masterwidget->mw_defaulttype->wt_iniscript; ! #if 0 ! scriptlet_reset(sp); ! scriptlet_addstring(sp, ... ! #endif } - sp = scriptlet_new((t_pd *)masterwidget, - masterwidget->mw_target, masterwidget->mw_target, 0, 0); - if (scriptlet_evaluate(masterwidget->mw_setupscript, sp, 0, 0, 0, 0)) - scriptlet_push(sp); else ! bug("masterwidget_initialize"); ! scriptlet_free(sp); } --- 307,347 ---- else { ! loud_warning((t_pd *)masterwidget, ! "no file 'default.wid'... using built-in defaults"); } typekey = dict_key(masterwidget->mw_typemap, "default"); ! if ((typeval = (t_widgettype *)dict_value(masterwidget->mw_typemap, typekey)) ! && !scriptlet_isempty(masterwidget->mw_setupscript)) ! { masterwidget->mw_defaulttype = typeval; ! rcresult = SCRIPTLET_OK; ! } ! else if (rcresult == SCRIPTLET_OK) { ! /* LATER think about adding only missing part to existing local defs */ ! loud_warning((t_pd *)masterwidget, "%s missing in file 'default.wid'", ! (typeval ? "setup definitions" : "master initializer")); masterwidget->mw_defaulttype = widgettype_new(masterwidget, "default", 0, 0); ! scriptlet_reset(masterwidget->mw_setupscript); ! rcresult = ! scriptlet_rcparse(masterwidget->mw_setupscript, 0, "default", ! masterwidget_builtin, masterwidget_cmnthook); } else ! { ! bug("masterwidget_initialize 1"); ! rcresult = SCRIPTLET_BADFILE; ! } ! if (rcresult == SCRIPTLET_OK) ! { ! t_scriptlet *sp = ! scriptlet_new((t_pd *)masterwidget, masterwidget->mw_target, ! masterwidget->mw_target, 0, 0, 0); ! if (scriptlet_evaluate(masterwidget->mw_setupscript, sp, 0, 0, 0, 0)) ! scriptlet_push(sp); ! else ! bug("masterwidget_initialize 2"); ! scriptlet_free(sp); ! } }
Index: widgettype.h =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/toxy/widgettype.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** widgettype.h 24 Sep 2003 10:46:19 -0000 1.1 --- widgettype.h 19 Feb 2004 22:23:18 -0000 1.2 *************** *** 22,30 **** int widgettype_evaluate(t_widgettype *wt, t_scriptlet *outsp, int visedonly, int ac, t_atom *av, t_props *argprops); int masterwidget_evaluate(t_scriptlet *outsp, int visedonly, int ac, t_atom *av, t_props *argprops); void masterwidget_initialize(void);
- void widgettype_setup(void); - #endif --- 22,31 ---- int widgettype_evaluate(t_widgettype *wt, t_scriptlet *outsp, int visedonly, int ac, t_atom *av, t_props *argprops); + void widgettype_setup(void); + + char *masterwidget_getcontents(int *szp); int masterwidget_evaluate(t_scriptlet *outsp, int visedonly, int ac, t_atom *av, t_props *argprops); void masterwidget_initialize(void);
#endif