Пример #1
0
Файл: m_obj.c Проект: cviejo/mPD
void obj_init(void)
{
    inlet_class = class_new(gensym("inlet"), 0, 0,
        sizeof(t_inlet), CLASS_PD, 0);
    class_addbang(inlet_class, inlet_bang);
    class_addpointer(inlet_class, inlet_pointer);
    class_addfloat(inlet_class, inlet_float);
    class_addsymbol(inlet_class, inlet_symbol);
    class_addblob(inlet_class, inlet_blob); /* MP 20061226 blob type */
    class_addlist(inlet_class, inlet_list);
    class_addanything(inlet_class, inlet_anything);

    pointerinlet_class = class_new(gensym("inlet"), 0, 0,
        sizeof(t_inlet), CLASS_PD, 0);
    class_addpointer(pointerinlet_class, pointerinlet_pointer);
    class_addanything(pointerinlet_class, inlet_wrong);
    
    floatinlet_class = class_new(gensym("inlet"), 0, 0,
        sizeof(t_inlet), CLASS_PD, 0);
    class_addfloat(floatinlet_class, (t_method)floatinlet_float);
    class_addanything(floatinlet_class, inlet_wrong);

    symbolinlet_class = class_new(gensym("inlet"), 0, 0,
        sizeof(t_inlet), CLASS_PD, 0);
    class_addsymbol(symbolinlet_class, symbolinlet_symbol);
    class_addanything(symbolinlet_class, inlet_wrong);

}
Пример #2
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);
}