void loud_notimplemented(t_pd *x, char *name) { if (name) loud_warning(x, 0, "\"%s\" method not implemented (yet)", name); else loud_warning(x, 0, "not implemented (yet)"); }
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); }
static void import_flushillegal(t_port *x) { if (x->x_illmess) { if (x->x_illmess == 1) loud_warning(0, "import", "[%d] illegal line", x->x_messcount); else loud_warning(0, "import", "[%d] %d illegal lines", x->x_messcount, x->x_illmess); x->x_illmess = 0; } }
/* LATER use hammer replacements */ static int imaction_P6_pack(t_port *x, char *arg) { int i; for (i = 7; i < x->x_inatoms; i++) { if (x->x_inmess[i].a_type == A_SYMBOL) { t_symbol *s = x->x_inmess[i].a_w.w_symbol; if (s->s_name[1]) { loud_warning(0, "import", "%s's argument '%s' bashed to 's'", port_getsymbol(x, 6)->s_name, s->s_name); x->x_inmess[i].a_w.w_symbol = gensym("s"); } else switch (*s->s_name) { case 'b': case 'f': case 's': case 'l': break; case 'i': x->x_inmess[i].a_w.w_symbol = gensym("f"); break; default: x->x_inmess[i].a_w.w_symbol = gensym("s"); } } } return (PORT_OK); }
static void *maxmode_new(t_symbol *s, int ac, t_atom *av) { t_maxmode *x = (t_maxmode *)pd_new(maxmode_class); int selective = ac; if (maxmode_withbanner && !ac) { post("this is maxmode %s, %s %s build", CYCLONE_VERSION, loud_ordinal(CYCLONE_BUILD), CYCLONE_RELEASE); loud_warning(0, "maxmode", "creating maxmode object without loading cyclone components"); maxmode_withbanner = 0; } if (selective) { /* a numeric argument is valid -- transparent object is created (global mode is not set, nothing is registered) */ while (ac--) if (av->a_type == A_SYMBOL) { /* FIXME register into fitter for per-patch-file, selective compatibility control */ av++; } } else if (!fittermax_get()) fittermax_set(); x->x_filehandle = hammerfile_new((t_pd *)x, 0, maxmode_readhook, 0, 0); outlet_new((t_object *)x, &s_float); x->x_modeout = outlet_new((t_object *)x, &s_symbol); return (x); }
static void import_embroken(t_port *x, char *cause) { if (x->x_lastbroken < x->x_messcount) /* ignore redundant calls */ { x->x_lastbroken = x->x_messcount; loud_warning(0, "import", "[%d] %s embedding broken by %s", x->x_messcount, x->x_emstate->s_name, cause); } }
static void import_unexpected(t_port *x) { if (x->x_lastunexpected < x->x_messcount) /* ignore redundant calls */ { x->x_lastunexpected = x->x_messcount; loud_warning(0, "import", "[%d] unexpected \"%s %s\"", x->x_messcount, port_gettarget(x)->s_name, port_getselector(x)->s_name); } }
static void import_eminconsistent(t_port *x, t_symbol *state) { if (import_emcheck(x, state) && x->x_lastinconsistent < x->x_messcount) /* ignore redundant calls */ { x->x_lastinconsistent = x->x_messcount; loud_warning(0, "import", "[%d] %s embedding ended inconsistently", x->x_messcount, state->s_name); } }
void tow_setup(void) { int result = LOADER_OK; if (zgetfn(&pd_objectmaker, gensym("widget"))) loud_warning(0, "tow", "widget is already loaded"); else result = unstable_load_lib("", "widget"); if (result == LOADER_NOFILE) loud_error(0, "widget library is missing"); else if (!zgetfn(&pd_objectmaker, gensym("widget"))) { loud_error(0, "version mismatch"); loud_errand(0, "use a more recent Pd release (or recompile toxy)."); } }
static t_int port_getint(t_port *x, int ndx) { if (ndx < x->x_inatoms) { t_atom *av = &x->x_inmess[ndx]; if (av->a_type == A_INT) return (av->a_w.w_index); else if (av->a_type == A_FLOAT) { loud_warning(0, "import", "[%d] float atom %d, int expected", x->x_messcount, ndx); return ((t_int)av->a_w.w_float); } } return (0); }
static int import_emcheckend(t_port *x, t_symbol *state, t_symbol *name) { if (import_emcheck(x, state)) { if (x->x_emcount /* empty ok for vtable, CHECKME other cases */ && x->x_emsize != x->x_emcount) loud_warning(0, "import", "[%d] corrupt %s (%d atoms declared, %d provided)", x->x_messcount, state->s_name, x->x_emsize, x->x_emcount); else { if (name != x->x_emname) /* warn and accept, LATER rethink */ import_eminconsistent(x, state); return (1); } } return (0); }
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 *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 *)plusobject_new(plustot_env_class, s, ac, av, 0); x->x_tin = tin; plusbob_preserve((t_plusbob *)tin); x->x_glist = gl; plusoutlet_new(&x->x_plusobject, &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, 0, "bad atom"); warned = 1; } av++; } } else loud_error(0, "+env: cannot initialize"); return (x); }
static void riddle_dsp(t_riddle *rd, t_signal **sp) { int failed = 0, unarmed = 1, doreblock = 0; int oldgraphsr = rd->rd_graphsr; int oldgraphblock = rd->rd_graphblock; int inslotno, ninslots = rd->rd_nsiginlets + rd->rd_nremoteslots; int outslotno; t_rdsource *inslot; t_rdsink *outslot; #ifdef RIDDLE_DEBUG riddlebug_post(rd, "\nriddle_dsp", 0); for (inslotno = 0, inslot = rd->rd_inslots; inslotno < ninslots; inslotno++, inslot++) loudbug_post("%d sources: %d reblocks of %d -> %d", inslotno, inslot->so_sourcecount, inslot->so_block, inslot->so_newblock); #endif rd->rd_graphsr = (int)sp[0]->s_sr; rd->rd_graphblock = sp[0]->s_n; /* this belongs to step 2., but should precede all "muteandreset" gotos */ if (rd->rd_wasdisabled = rd->rd_disabled) { rd->rd_disabled = 0; if (rd->rd_blockfn) doreblock = 1; else { loudbug_bug("riddle_dsp 1"); goto muteandreset; } } /* step 1: verify all source slots */ for (inslotno = 0, inslot = rd->rd_inslots; inslotno < ninslots; inslotno++, inslot++) { if (inslot->so_newblock > rd->rd_graphblock) { if (inslotno < rd->rd_nsiginlets) { loud_error((t_pd *)rd, "inslot %d: source block too large (%d > %d)", inslotno, inslot->so_newblock, rd->rd_graphblock); failed = 1; } } else if (inslot->so_sourcecount <= 0) { if (inslotno < rd->rd_nsiginlets) { /* bash unconfirmed declarations to graphblock */ inslot->so_newpattern = 0; inslot->so_newblock = rd->rd_graphblock; } else if (inslot->so_remote) { if (rdremote_getwriter(inslot->so_remote)) { loud_warning((t_pd *)rd, 0, "misplaced buffer reader..."); riddle_updatedsp(); failed = 1; /* LATER rethink */ } else { loud_warning((t_pd *)rd, 0, "orphaned buffer reader"); /* remote slots preserve unconfirmed declarations */ inslot->so_newpattern = inslot->so_pattern; if (inslot->so_block > 0) inslot->so_newblock = inslot->so_block; else inslot->so_newblock = rd->rd_graphblock; } } else loudbug_bug("riddle_dsp 2"); } else if (inslot->so_newblock <= 0) /* should not happen */ { loudbug_bug("riddle_dsp 3"); failed = 1; } } if (failed) goto muteandreset; /* step 2: determine outslot sizes/layouts -- blockfn fires on the very first call to riddle_dsp(), and then after any change of block or sr, and each time the object is disabled... LATER reconsider the pros and cons of performing the reblocking during every dsp call */ /* 2a: was there any change of inslot size/layout or graph block/sr? */ if (!doreblock && rd->rd_blockfn) { if (rd->rd_graphsr != oldgraphsr || rd->rd_graphblock != oldgraphblock) doreblock = 1; else for (inslotno = 0, inslot = rd->rd_inslots; inslotno < ninslots; inslotno++, inslot++) { if (inslot->so_newpattern != inslot->so_pattern || inslot->so_newblock != inslot->so_block) { doreblock = 1; break; } } } /* 2b: update the inslots, reset the outslots */ if (doreblock || !rd->rd_blockfn) { for (inslotno = 0, inslot = rd->rd_inslots; inslotno < ninslots; inslotno++, inslot++) { inslot->so_pattern = inslot->so_newpattern; inslot->so_block = inslot->so_newblock; } for (outslotno = 0, outslot = rd->rd_outslots; outslotno < rd->rd_nsigoutlets; outslotno++, outslot++) { outslot->si_pattern = 0; outslot->si_block = 0; outslot->si_isready = 0; } } /* 2c: call the instance-specific method which redeclares the outslots */ if (doreblock) { #ifdef RIDDLE_DEBUG riddlebug_post(rd, "REBLOCK", 0); #endif rd->rd_blockfn(rd); if (rd->rd_disabled) goto muteandreset; } /* 2d: assign defaults to undeclared outslots */ for (outslotno = 0, outslot = rd->rd_outslots; outslotno < rd->rd_nsigoutlets; outslotno++, outslot++) { if (outslot->si_block < 0) { loudbug_bug("riddle_dsp 4"); failed = 1; } else if (outslot->si_block == 0) outslot->si_block = rd->rd_graphblock; } /* LATER think about not redeclared remote writers */ if (failed) goto muteandreset; /* step 3: transfer outslot declarations down to destination objects */ #ifdef RIDDLE_DEBUG riddlebug_post(rd, "PUSH", 0); #endif if (riddle_validatesinks(rd)) { for (outslotno = 0, outslot = rd->rd_outslots; outslotno < rd->rd_nsigoutlets; outslotno++, outslot++) if (outslot->si_isready && rdsink_push(outslot, (t_object *)rd, outslot->si_outno) == 0) failed = 1; } else failed = 1; /* remote declarations are propagated directly from within rdremote_setoutblock/layout(), cf. rdremote_pushblock/layout() */ if (failed) goto muteandreset; /* step 4: call the wrappee */ if (rd->rd_dspfn) { rd->rd_dspfn(rd, sp); unarmed = 0; } else loudbug_bug("riddle_dsp 5"); /* step 5: mute if disabled, then reset the inslots */ muteandreset: if (unarmed) { rd->rd_disabled = 1; riddle_mute(rd, sp); } for (inslotno = 0, inslot = rd->rd_inslots; inslotno < ninslots; inslotno++, inslot++) { inslot->so_newpattern = 0; inslot->so_newblock = 0; inslot->so_sourcecount = 0; } }
int messtree_doit(t_messtree *mt, t_messslot **msp, int *nargp, t_pd *target, t_symbol *s, int ac, t_atom *av) { int result = MESSTREE_OK, nargpdummy; t_messslot *mspdummy; if (!msp) msp = &mspdummy; if (!nargp) nargp = &nargpdummy; if (s && s != mt->mt_selector) { loud_warning(target, (target ? 0 : "messtree"), "unexpected selector \"%s\"", s->s_name); *msp = 0; *nargp = 0; return (MESSTREE_CORRUPT); } if (ac && av->a_type == A_SYMBOL) { t_messtree *bch; for (bch = mt->mt_sublist; bch; bch = bch->mt_next) { if (av->a_w.w_symbol == bch->mt_selector) { if (bch->mt_sublist) return (messtree_doit(bch, msp, nargp, target, av->a_w.w_symbol, ac - 1, av + 1)); else { if (target && bch->mt_method) result = bch->mt_method(target, av->a_w.w_symbol, ac - 1, av + 1); *msp = (result == MESSTREE_OK ? bch->mt_slot : 0); *nargp = ac - 1; return (result); } } } if (mt->mt_nonexclusive) { if (target && mt->mt_method) result = mt->mt_method(target, 0, ac, av); /* LATER rethink */ *msp = (result == MESSTREE_OK ? mt->mt_slot : 0); *nargp = ac; return (result); } else { loud_warning(target, (target ? 0 : "messtree"), "unknown property \"%s\"", av->a_w.w_symbol->s_name); *msp = 0; *nargp = 0; return (MESSTREE_UNKNOWN); } } else { if (target && mt->mt_method) result = mt->mt_method(target, 0, ac, av); *msp = (result == MESSTREE_OK ? mt->mt_slot : 0); *nargp = ac; return (result); } }
static void append_doset(t_append *x, t_symbol *s, int ac, t_atom *av) { int newsize = ac * 2; if (s) newsize += 2; if (newsize > 0) { if (x->x_entered) { if (x->x_auxbuf) { loud_warning((t_pd *)x, 0, "\'set\' message overridden"); freebytes(x->x_auxbuf, x->x_auxsize * sizeof(*x->x_auxbuf)); x->x_auxsize = 0; } if (x->x_auxbuf = getbytes(newsize * sizeof(*x->x_auxbuf))) { t_atom *ap = x->x_auxbuf + ac; if (s) { ap++; SETSYMBOL(ap, s); ap++; } if (ac) memcpy(ap, av, ac * sizeof(*x->x_auxbuf)); x->x_auxsize = newsize; } } else { t_atom *ap; if (newsize > x->x_size) { int sz = newsize; x->x_messbuf = grow_nodata(&sz, &x->x_size, x->x_messbuf, APPEND_INISIZE, x->x_messini, sizeof(*x->x_messbuf)); if (sz != newsize) { ac = sz / 2; /* LATER rethink */ if (s) ac--; } } if (s) { append_setnatoms(x, ac + 1); ap = x->x_message; SETSYMBOL(ap, s); ap++; } else { append_setnatoms(x, ac); ap = x->x_message; } while (ac--) *ap++ = *av++; } } }
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 */ } }