int loud_floatarg(t_class *c, int which, int ac, t_atom *av, t_float *vp, t_float minval, t_float maxval, int underaction, int overaction, char *what) { int result = LOUD_ARGOK; if (which < ac) { av += which; if (av->a_type == A_FLOAT) { t_float f = av->a_w.w_float; if (f < minval) { *vp = (underaction & LOUD_CLIP ? minval : f); if (underaction) result = LOUD_ARGUNDER; } else if (f > maxval) { *vp = (overaction & LOUD_CLIP ? maxval : f); if (overaction) result = LOUD_ARGOVER; } else *vp = f; } else result = LOUD_ARGTYPE; } else result = LOUD_ARGMISSING; if (what) { switch (result) { case LOUD_ARGUNDER: if (underaction & LOUD_WARN) { if (underaction & LOUD_CLIP) loud_warning(&c, 0, "%s rounded up to %g", what, minval); else loud_warning(&c, 0, "less than %g %s requested", minval, what); } break; case LOUD_ARGOVER: if (overaction & LOUD_WARN) { if (overaction & LOUD_CLIP) loud_warning(&c, 0, "%s truncated to %g", what, maxval); else loud_warning(&c, 0, "more than %g %s requested", maxval, what); } break; case LOUD_ARGTYPE: loud_error(0, "bad argument %d (%s)", which, class_getname(c)); break; default:; } } return (result); }
void loudx_setcontext(t_loudcontext *lc, t_pd *caller, char *callername, t_symbol *s, int ac, t_atom *av) { if (lc->lc_callername) freebytes(lc->lc_callername, lc->lc_cnsize); lc->lc_caller = caller; if (callername) { lc->lc_cnsize = strlen(callername) + 1; lc->lc_callername = getbytes(lc->lc_cnsize); strcpy(lc->lc_callername, callername); } else { lc->lc_callername = 0; lc->lc_cnsize = 0; } lc->lc_selector = s; lc->lc_ac = ac; lc->lc_av = av; if (callername) lc->lc_andindent = lc->lc_cnsize + 9; else if (caller) lc->lc_andindent = strlen(class_getname(*caller)) + 10; else if (s) lc->lc_andindent = strlen(s->s_name) + 10; else lc->lc_andindent = strlen(LOUD_ERROR_DEFAULT) + 1; }
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 loudbug_post("booty '%s' at %x:", class_getname(*(t_pd *)booty), (int)booty); loudbug_postbinbuf(bb); #endif return (bb); } else return (0); }
/* derive a host */ static t_xeq *xeq_derived_hostify(t_hyphen *x, int tablesize, t_symbol *refname, t_method tickmethod) { t_xeq *base = 0; t_binbuf *bb = 0; int i; #ifdef XEQ_VERBOSE if (!refname || refname == &s_) post("hostifying %s without a reference name", class_getname(*(t_pd *)x)); #endif if (!hyphen_multiderive(x, xeq_base_class, tablesize)) return (0); base = XEQ_BASE(x); x->x_host = (t_hyphen *)base; bb = binbuf_new(); /* initialize first base and attach a reference name to it, LATER use <id>-<refname> scheme */ hyphen_initialize((t_hyphen *)base, xeq_base_class, 0); hyphen_attach((t_hyphen *)base, refname); for (i = 0; i < XEQ_NBASES(x); i++, base++) { xeq_newbase(base, bb, tickmethod); } hyphen_forallfriends((t_hyphen *)XEQ_BASE(x), xeqhook_multicast_setbinbuf, 0); return (XEQ_BASE(x)); }
/* FIXME need access to glob_pdobject... */ static t_pd *pddplink_pdtarget(t_pddplink *x) { t_pd *pdtarget = gensym("pd")->s_thing; if (pdtarget && !strcmp(class_getname(*pdtarget), "pd")) return (pdtarget); else return ((t_pd *)x); /* internal error */ }
void riddlebug_post(t_riddle *rd, char *pfx, char *fmt, ...) { char buf[MAXPDSTRING]; va_list ap; if (fmt) { va_start(ap, fmt); vsnprintf(buf, MAXPDSTRING-1, fmt, ap); va_end(ap); fprintf(stderr, "%s \"%s\" (%x): %s\n", pfx, class_getname(*(t_pd *)rd), (int)rd, buf); } else fprintf(stderr, "%s \"%s\" (%x)\n", pfx, class_getname(*(t_pd *)rd), (int)rd); #ifdef _WIN32 fflush(stderr); #endif }
void loud_warning(t_pd *x, char *who, char *fmt, ...) { char buf[MAXPDSTRING]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); post("warning (%s): %s", (x ? class_getname(*x) : (who ? who : "miXed")), buf); va_end(ap); }
void loud_errand(t_pd *x, char *fmt, ...) { char buf[MAXPDSTRING]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); post("%*s%s", (int)(x ? strlen(class_getname(*x)) + 10 : strlen(LOUD_ERROR_DEFAULT) + 1), "", buf); va_end(ap); }
static int hammergui_setup(void) { ps_hashhammergui = gensym("#hammergui"); ps__hammergui = gensym("_hammergui"); ps__up = gensym("_up"); ps__focus = gensym("_focus"); ps__vised = gensym("_vised"); if (ps_hashhammergui->s_thing) { char *cname = class_getname(*ps_hashhammergui->s_thing); #ifdef HAMMERGUI_DEBUG fprintf(stderr, "'%s' already registered as the global hammergui sink \n", (cname ? cname : "???")); #endif if (strcmp(cname, ps__hammergui->s_name)) { /* FIXME protect against the danger of someone else (e.g. receive) binding to #hammergui */ bug("hammergui_setup"); return (0); } else { /* FIXME compatibility test */ hammergui_class = *ps_hashhammergui->s_thing; return (1); } } hammergui_class = class_new(ps__hammergui, 0, 0, sizeof(t_hammergui), CLASS_PD | CLASS_NOINLET, 0); class_addanything(hammergui_class, hammergui_anything); class_addmethod(hammergui_class, (t_method)hammergui__remouse, gensym("_remouse"), 0); class_addmethod(hammergui_class, (t_method)hammergui__refocus, gensym("_refocus"), 0); class_addmethod(hammergui_class, (t_method)hammergui__revised, gensym("_revised"), 0); class_addmethod(hammergui_class, (t_method)hammergui__up, ps__up, A_FLOAT, 0); class_addmethod(hammergui_class, (t_method)hammergui__focus, ps__focus, A_SYMBOL, A_FLOAT, 0); class_addmethod(hammergui_class, (t_method)hammergui__vised, ps__vised, A_SYMBOL, A_FLOAT, 0); /* if older than 0.43, create an 0.43-style pdsend */ sys_gui("if {[llength [info procs ::pdsend]] == 0} {"); sys_gui("proc ::pdsend {args} {::pd \"[join $args { }] ;\"}}\n"); /* Protect against pdCmd being called (via "Canvas <Destroy>" binding) during Tcl_Finalize(). FIXME this should be a standard exit handler. */ sys_gui("proc hammergui_exithook {cmd op} {proc ::pdsend {} {}}\n"); sys_gui("if {[info tclversion] >= 8.4} {\n\ trace add execution exit enter hammergui_exithook}\n");
void max_default(t_pd *x, t_symbol *s, int argc, t_atom *argv) { int i; char str[80]; startpost("%s: unknown message %s", class_getname(pd_class(x)), s->s_name); for (i = 0; i < argc; i++) { atom_string(argv+i, str, 80); poststring(str); } endpost(); }
void loud_error(t_pd *x, char *fmt, ...) { char buf[MAXPDSTRING]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); if (x) { startpost("%s's ", class_getname(*x)); //pd_error(x, buf); } else post("%s %s", LOUD_ERROR_DEFAULT, buf); va_end(ap); }
/* null owner defaults to class name, pass "" to supress */ void hammereditor_open(t_hammerfile *f, char *title, char *owner) { if (!owner) owner = class_getname(*f->f_master); if (!*owner) owner = 0; if (!title) { title = owner; owner = 0; } if (owner) sys_vgui("hammereditor_open .%x %dx%d {%s: %s} %d\n", (int)f, 600, 340, owner, title, (f->f_editorfn != 0)); else sys_vgui("hammereditor_open .%x %dx%d {%s} %d\n", (int)f, 600, 340, (title ? title : "Untitled"), (f->f_editorfn != 0)); }
/* The class might have been created by another dll... This is public, because apart from the "_patchboard" class above, it is called for the "_raftentry" class too. LATER rethink. */ t_class *patchvalue_classnew(t_symbol *cname, size_t size) { t_class *cls; t_symbol *bindsym; char buf[MAXPDSTRING]; sprintf(buf, "#%s", cname->s_name); bindsym = gensym(buf); if (bindsym->s_thing) { t_pd *pd = bindsym->s_thing; char *name = class_getname(*pd); if (strcmp(name, cname->s_name)) { /* FIXME handle this properly... */ loudbug_bug("patchvalue_classnew"); } else return (*pd); } cls = class_new(cname, 0, 0, size, CLASS_PD | CLASS_NOINLET, 0); pd_bind(pd_new(cls), bindsym); /* never unbound */ return (cls); }
static t_object *dummy_newobject(t_symbol *s, t_dummy_slot **slotp) { t_object *x; t_dummy_slot *sl; int fnd; for (fnd = 0; fnd < dummy_nclasses; fnd++) /* LATER compare symbols, rather than strings */ if (dummy_classes[fnd] /* empty slot: abstraction replacement */ && !strcmp(class_getname(dummy_classes[fnd]), s->s_name)) break; x = (t_object *)pd_new(dummy_classes[fnd]); sl = &dummy_slots[fnd]; if (fnd == dummy_nclasses) loudbug_bug("dummy_newobject"); /* create a "_dummy" in this case */ else if (!sl->s_warned) { loud_warning((t_pd *)x, 0, "dummy substitution"); sl->s_warned = 1; } if (slotp) *slotp = sl; return (x); }
void loudx_error(t_loudcontext *lc, char *fmt, ...) { char buf[MAXPDSTRING]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); if (lc->lc_caller) { startpost("%s's ", (lc->lc_callername ? lc->lc_callername : class_getname(*lc->lc_caller))); //pd_error(lc->lc_caller, buf); } else { if (lc->lc_callername) post("error (%s): %s", lc->lc_callername, buf); else if (lc->lc_selector) post("error (%s): %s", lc->lc_selector->s_name, buf); else post("%s %s", LOUD_ERROR_DEFAULT, buf); } va_end(ap); }
static int rdsink_push(t_rdsink *si, t_object *x, int outno) { int result = 1; t_outlet *op; t_outconnect *oc = obj_starttraverseoutlet(x, &op, outno); while (oc) { t_object *dst; t_inlet *ip; int inno; oc = obj_nexttraverseoutlet(oc, &dst, &ip, &inno); if (dst) { int siginno = obj_siginletindex(dst, inno); if (siginno < 0) { /* should not happen, LATER rethink */ } else if (zgetfn((t_pd *)dst, rdps__reblock)) { si->si_outbuf->a_w.w_float = (t_float)siginno; typedmess((t_pd *)dst, rdps__reblock, 4, si->si_outbuf); } else if (pd_class((t_pd *)dst) == canvas_class) { t_gobj *ob; int i; for (i = 0, ob = ((t_canvas *)dst)->gl_list; ob; ob = ob->g_next) { if (pd_class((t_pd *)ob) == vinlet_class) { if (i == inno) break; else i++; } } if (ob) { #ifdef RIDDLE_DEBUG riddlebug_post(si->si_riddle, "PUSH-SUBCANVAS", "vinlet %d (\"%s\")", inno, class_getname(*(t_pd *)ob)); #endif rdsink_push(si, (t_object *)ob, 0); } else loudbug_bug("rdsink_push 1"); } else if (pd_class((t_pd *)dst) == voutlet_class) { t_rdvoutlet *vout = (t_rdvoutlet *)dst; if (vout->x_canvas) { int n; t_outlet *o; for (o = ((t_object *)vout->x_canvas)->ob_outlet, n = 0; o; o = (t_outlet *)(((t_rdoutlet *)o)->o_next), n++) if (o == vout->x_parentoutlet) break; if (o) { #ifdef RIDDLE_DEBUG riddlebug_post(si->si_riddle, "PUSH-OUTLET", "outno %d, graph %x", n, (int)vout->x_canvas); #endif rdsink_push(si, (t_object *)vout->x_canvas, n); } else loudbug_bug("rdsink_push 2"); } #ifdef RIDDLE_DEBUG else riddlebug_post(si->si_riddle, "PUSH-OUTLET", "void canvas..."); #endif } else { char *dstname = class_getname(*(t_pd *)dst); #ifdef RIDDLE_DEBUG riddlebug_post(si->si_riddle, "PUSH-RIDDLESS", "inlet %d (\"%s\")", inno, dstname); #endif if (si->si_flags & RIDDLE_STRICTNESSMASK) { if (strcmp(dstname, "print~")) { loud_error((t_pd *)x, "not a riddle: \"%s\"", dstname); result = 0; } } else if (!strcmp(dstname, "send~") || !strcmp(dstname, "throw~")) { loud_error((t_pd *)x, "bad destination: \"%s\"", dstname); result = 0; } } } } return (result); }
void maxmode_setup(void) { int dresult = LOADER_OK; if (zgetfn(&pd_objectmaker, gensym("maxmode"))) { loud_error(0, "maxmode is already loaded"); return; } maxmode_class = class_new(gensym("maxmode"), (t_newmethod)maxmode_new, (t_method)maxmode_free, sizeof(t_maxmode), 0, A_GIMME, 0); class_addbang(maxmode_class, maxmode_bang); class_addmethod(maxmode_class, (t_method)maxmode_set, gensym("set"), A_DEFSYM, 0); class_addmethod(maxmode_class, (t_method)maxmode_get, gensym("get"), 0); class_addmethod(maxmode_class, (t_method)maxmode_cd, gensym("cd"), A_DEFSYM, 0); class_addmethod(maxmode_class, (t_method)maxmode_pwd, gensym("pwd"), A_SYMBOL, 0); class_addmethod(maxmode_class, (t_method)maxmode_import, gensym("import"), A_DEFSYM, 0); class_addmethod(maxmode_class, (t_method)maxmode_click, gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); hammerfile_setup(maxmode_class, 0); if (canvas_getcurrent()) { fitter_setup(0, 0); if (!zgetfn(&pd_objectmaker, gensym("cyclone"))) /* cycloneless maxmode -- banner is posted by the oldest maxmode object with no creation arguments */ maxmode_withbanner = 1; } else { fittermax_set(); if (zgetfn(&pd_objectmaker, gensym("cyclone"))) loud_warning(0, "maxmode", "cyclone is already loaded"); else { if (unstable_load_lib("", "cyclone") == LOADER_NOFILE) loud_error(0, "cyclone library is missing"); else if (!zgetfn(&pd_objectmaker, gensym("cyclone"))) loud_error(0, "miXed/Pd version mismatch"); } } maxmode_dummiesndx = fragile_class_count(); if (zgetfn(&pd_objectmaker, gensym("dummies"))) loud_warning(0, "maxmode", "dummies are already loaded"); else dresult = unstable_load_lib("", "dummies"); maxmode_lastndx = fragile_class_count() - 1; if (dresult == LOADER_NOFILE) loud_warning(0, "maxmode", "dummies not found"); else { t_symbol *s = gensym("_cc.dummies"); if (s->s_thing && !s->s_next && !strcmp(class_getname(*s->s_thing), "_cc.dummies")) maxmode_dproxy = s->s_thing; else loudbug_bug("maxmode_setup"); /* FIXME */ } }
void loud_classarg(t_class *c) { loud_error(0, "missing or bad arguments in \"%s\"", class_getname(c)); }