void rhythms_memory_setup(void) { rhythms_memory_class = class_new(gensym("rhythms_memory"), (t_newmethod)rhythms_memory_new, (t_method)rhythms_memory_free, sizeof(t_rhythms_memory), CLASS_DEFAULT, A_GIMME, 0); class_addbang(rhythms_memory_class, (t_method)rhythms_memory_bang); class_addmethod(rhythms_memory_class, (t_method)end_measure, gensym("measure"), 0); class_doaddfloat(rhythms_memory_class, (t_method)add_event); class_addmethod(rhythms_memory_class, (t_method)crash, gensym("crash"), 0); // the user asks for a rhythm class_addmethod(rhythms_memory_class, (t_method)ask_rhythm, gensym("rhythm_out"), A_GIMME, 0); // adds a rhythm passing it as a list of floats class_addmethod(rhythms_memory_class, (t_method)add_rhythm, gensym("rhythm_in"), A_GIMME, 0); // builds a variation of a given rhythm class_addmethod(rhythms_memory_class, (t_method)variation, gensym("variation"), A_GIMME, 0); class_addmethod(rhythms_memory_class, (t_method)init, gensym("init"), 0); }
void class_addmethod(t_class *c, t_method fn, t_symbol *sel, t_atomtype arg1, ...) { va_list ap; t_methodentry *m; t_atomtype argtype = arg1; int nargs; va_start(ap, arg1); /* "signal" method specifies that we take audio signals but that we don't want automatic float to signal conversion. This is obsolete; you should now use the CLASS_MAINSIGNALIN macro. */ if (sel == &s_signal) { if (c->c_floatsignalin) post("warning: signal method overrides class_mainsignalin"); c->c_floatsignalin = -1; } /* check for special cases. "Pointer" is missing here so that pd_objectmaker's pointer method can be typechecked differently. */ if (sel == &s_bang) { if (argtype) goto phooey; class_addbang(c, fn); } else if (sel == &s_float) { if (argtype != A_FLOAT || va_arg(ap, t_atomtype)) goto phooey; class_doaddfloat(c, fn); } else if (sel == &s_symbol) { if (argtype != A_SYMBOL || va_arg(ap, t_atomtype)) goto phooey; class_addsymbol(c, fn); } else if (sel == &s_blob) /* MP 20070106 blob type */ { post("class_addmethod: %p", fn); if (argtype != A_BLOB || va_arg(ap, t_atomtype)) goto phooey; class_addblob(c, fn); } else if (sel == &s_list) { if (argtype != A_GIMME) goto phooey; class_addlist(c, fn); } else if (sel == &s_anything) { if (argtype != A_GIMME) goto phooey; class_addanything(c, fn); } else { /* Pd-extended doesn't use the aliasing automagic int i; for (i = 0; i < c->c_nmethod; i++) if (c->c_methods[i].me_name == sel) { char nbuf[80]; snprintf(nbuf, 80, "%s_aliased", sel->s_name); c->c_methods[i].me_name = gensym(nbuf); if (c == pd_objectmaker) post("warning: class '%s' overwritten; old one renamed '%s'", sel->s_name, nbuf); else post("warning: old method '%s' for class '%s' renamed '%s'", sel->s_name, c->c_name->s_name, nbuf); } */ c->c_methods = t_resizebytes(c->c_methods, c->c_nmethod * sizeof(*c->c_methods), (c->c_nmethod + 1) * sizeof(*c->c_methods)); m = c->c_methods + c->c_nmethod; c->c_nmethod++; m->me_name = sel; m->me_fun = (t_gotfn)fn; nargs = 0; while (argtype != A_NULL && nargs < MAXPDARG) { m->me_arg[nargs++] = argtype; argtype = va_arg(ap, t_atomtype); } if (argtype != A_NULL) error("%s_%s: only 5 arguments are typecheckable; use A_GIMME", c->c_name->s_name, sel->s_name); va_end(ap); m->me_arg[nargs] = A_NULL; } return; phooey: bug("class_addmethod: %s_%s: bad argument types\n", c->c_name->s_name, sel->s_name); }
void class_addmethod(t_class *c, t_method fn, t_symbol *sel, t_atomtype arg1, ...) { va_list ap; t_methodentry *m; t_atomtype argtype = arg1; int nargs, i; va_start(ap, arg1); /* "signal" method specifies that we take audio signals but that we don't want automatic float to signal conversion. This is obsolete; you should now use the CLASS_MAINSIGNALIN macro. */ if (sel == &s_signal) { if (c->c_floatsignalin) post("warning: signal method overrides class_mainsignalin"); c->c_floatsignalin = -1; } /* check for special cases. "Pointer" is missing here so that pd_objectmaker's pointer method can be typechecked differently. */ if (sel == &s_bang) { if (argtype) goto phooey; class_addbang(c, fn); } else if (sel == &s_float) { if (argtype != A_FLOAT || va_arg(ap, t_atomtype)) goto phooey; class_doaddfloat(c, fn); } else if (sel == &s_symbol) { if (argtype != A_SYMBOL || va_arg(ap, t_atomtype)) goto phooey; class_addsymbol(c, fn); } else if (sel == &s_list) { if (argtype != A_GIMME) goto phooey; class_addlist(c, fn); } else if (sel == &s_anything) { if (argtype != A_GIMME) goto phooey; class_addanything(c, fn); } else { t_atomtype argvec[MAXPDARG+1]; nargs = 0; while (argtype != A_NULL && nargs < MAXPDARG) { argvec[nargs++] = argtype; argtype = va_arg(ap, t_atomtype); } if (argtype != A_NULL) error("%s_%s: only 5 arguments are typecheckable; use A_GIMME", c->c_name->s_name, sel->s_name); argvec[nargs] = 0; #ifdef PDINSTANCE for (i = 0; i < pd_ninstances; i++) { class_addmethodtolist(c, &c->c_methods[i], c->c_nmethod, (t_gotfn)fn, dogensym(sel->s_name, 0, pd_instances[i]), argvec, pd_instances[i]); } #else class_addmethodtolist(c, &c->c_methods, c->c_nmethod, (t_gotfn)fn, sel, argvec, &pd_maininstance); #endif c->c_nmethod++; } goto done; phooey: bug("class_addmethod: %s_%s: bad argument types\n", c->c_name->s_name, sel->s_name); done: va_end(ap); return; }
void class_addmethod(t_class *c, t_method fn, t_symbol *sel, t_atomtype arg1, ...) { va_list ap; t_methodentry *m; t_atomtype argtype = arg1; int nargs; va_start(ap, arg1); /* "signal" method specifies that we take audio signals but that we don't want automatic float to signal conversion. This is obsolete; you should now use the CLASS_MAINSIGNALIN macro. */ if (sel == &s_signal) { if (c->c_floatsignalin) post("warning: signal method overrides class_mainsignalin"); c->c_floatsignalin = -1; } /* check for special cases. "Pointer" is missing here so that pd_objectmaker's pointer method can be typechecked differently. */ if (sel == &s_bang) { if (argtype) goto phooey; class_addbang(c, fn); } else if (sel == &s_float) { if (argtype != A_FLOAT || va_arg(ap, t_atomtype)) goto phooey; class_doaddfloat(c, fn); } else if (sel == &s_symbol) { if (argtype != A_SYMBOL || va_arg(ap, t_atomtype)) goto phooey; class_addsymbol(c, fn); } else if (sel == &s_list) { if (argtype != A_GIMME) goto phooey; class_addlist(c, fn); } else if (sel == &s_anything) { if (argtype != A_GIMME) goto phooey; class_addanything(c, fn); } else { c->c_methods = t_resizebytes(c->c_methods, c->c_nmethod * sizeof(*c->c_methods), (c->c_nmethod + 1) * sizeof(*c->c_methods)); m = c->c_methods + c->c_nmethod; c->c_nmethod++; m->me_name = sel; m->me_fun = (t_gotfn)fn; nargs = 0; while (argtype != A_NULL && nargs < MAXPDARG) { m->me_arg[nargs++] = argtype; argtype = va_arg(ap, t_atomtype); } if (argtype != A_NULL) error("%s_%s: only 5 arguments are typecheckable; use A_GIMME", c->c_name->s_name, sel->s_name); va_end(ap); m->me_arg[nargs] = A_NULL; } return; phooey: bug("class_addmethod: %s_%s: bad argument types\n", c->c_name->s_name, sel->s_name); }