Esempio n. 1
0
File: m_class.c Progetto: toto/ipd
    /* this routine is called when a new "object" is requested whose class Pd
    doesn't know.  Pd tries to load it as an extern, then as an abstraction. */
void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
    t_pd *current;
    int fd;
    char dirbuf[MAXPDSTRING], *nameptr;
    if (tryingalready) return;
    newest = 0;
    class_loadsym = s;
    if (sys_load_lib(canvas_getcurrent(), s->s_name))
    {
        tryingalready = 1;
        typedmess(dummy, s, argc, argv);
        tryingalready = 0;
        return;
    }
    class_loadsym = 0;
    current = s__X.s_thing;
    if ((fd = canvas_open(canvas_getcurrent(), s->s_name, ".pd",
        dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
            (fd = canvas_open(canvas_getcurrent(), s->s_name, ".pat",
                dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
    {
        close (fd);
        if (!pd_setloadingabstraction(s))
        {
            canvas_setargs(argc, argv);
            binbuf_evalfile(gensym(nameptr), gensym(dirbuf));
            if (s__X.s_thing != current)
                canvas_popabstraction((t_canvas *)(s__X.s_thing));
            canvas_setargs(0, 0);
        }
        else error("%s: can't load abstraction within itself\n", s->s_name);
    }
    else newest = 0;
}
Esempio n. 2
0
    /* this routine is called when a new "object" is requested whose class Pd
    doesn't know.  Pd tries to load it as an extern, then as an abstraction. */
void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
    t_pd *current;
    int fd;
    char dirbuf[MAXPDSTRING], classslashclass[MAXPDSTRING], *nameptr;
    if (tryingalready>MAXOBJDEPTH){
      error("maximum object loading depth %d reached", MAXOBJDEPTH);
      return;
    }
    newest = 0;
    class_loadsym = s;
    if (sys_load_lib(canvas_getcurrent(), s->s_name))
    {
        tryingalready++;
        typedmess(dummy, s, argc, argv);
        tryingalready--;
        return;
    }
    class_loadsym = 0;
    current = s__X.s_thing;
    /* for class/class.pd support, to match class/class.pd_linux  */
    snprintf(classslashclass, MAXPDSTRING, "%s/%s", s->s_name, s->s_name);
    if ((fd = canvas_open(canvas_getcurrent(), s->s_name, ".pd",
        dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
            (fd = canvas_open(canvas_getcurrent(), s->s_name, ".pat",
                dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
               (fd = canvas_open(canvas_getcurrent(), classslashclass, ".pd",
                    dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
    {
        close (fd);
        if (!pd_setloadingabstraction(s))
        {
            canvas_setargs(argc, argv);
            binbuf_evalfile(gensym(nameptr), gensym(dirbuf));
            canvas_initbang((t_canvas *)(s__X.s_thing));/* JMZ*/
            if (s__X.s_thing != current)
                canvas_popabstraction((t_canvas *)(s__X.s_thing));
            canvas_setargs(0, 0);
        }
        else error("%s: can't load abstraction within itself\n", s->s_name);
    }
    else newest = 0;
}
Esempio n. 3
0
static t_pd *do_create_abstraction(t_symbol*s, int argc, t_atom *argv)
{
    /*
     * TODO: check if the there is a binbuf cached for <canvas::symbol>
        and use that instead.  We'll have to invalidate the cache once we
        are done (either with a clock_delay(0) or something else)
     */
    if (!pd_setloadingabstraction(s))
    {
        const char *objectname = s->s_name;
        char dirbuf[MAXPDSTRING], classslashclass[MAXPDSTRING], *nameptr;
        t_glist *glist = (t_glist *)canvas_getcurrent();
        t_canvas *canvas = (t_canvas*)glist_getcanvas(glist);
        int fd = -1;

        t_pd *was = s__X.s_thing;
        snprintf(classslashclass, MAXPDSTRING, "%s/%s", objectname, objectname);
        if ((fd = canvas_open(canvas, objectname, ".pd",
                  dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
            (fd = canvas_open(canvas, objectname, ".pat",
                  dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
            (fd = canvas_open(canvas, classslashclass, ".pd",
                  dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
        {
            close(fd);
            canvas_setargs(argc, argv);

            binbuf_evalfile(gensym(nameptr), gensym(dirbuf));
            if (s__X.s_thing && was != s__X.s_thing)
                canvas_popabstraction((t_canvas *)(s__X.s_thing));
            else s__X.s_thing = was;
            canvas_setargs(0, 0);
            return (pd_this->pd_newest);
        }
            /* otherwise we couldn't do it; just return 0 */
    }
    else error("%s: can't load abstraction within itself\n", s->s_name);
    pd_this->pd_newest = 0;
    return (0);
}