aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/dyn/dyn_send.cpp
blob: efd36849957653dcda24f8341a205e2d1ce70f95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* 
dyn - dynamical object management

Copyright (c)2003-2004 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.  
*/

#include "dyn_proto.h"

DYN_EXPORT int dyn_Send(int sched,dyn_id oid,int inlet,const t_symbol *sym,int argc,const t_atom *argv)
{
    ASSERT(oid);
    dyn_patchable *obj = oid->Patchable();

    if(obj) {
        /*
            It seems that we need connections (and proxy objects) for all inlets.
            Sending typed messages to the 0-inlet doesn't work for abstractions.
        */

        proxyin *px = obj->GetProxyIn(inlet);
        if(!px) {
            dyn_patcher *patcher = obj->owner;
            ASSERT(patcher);

            px = (proxyin *)NewPDObject(DYN_TYPE_OBJECT,patcher->glist(),sym_dynpxin);
            if(px) {
                px->init(obj);

//                    sys_lock();

//                    canvas_setcurrent(patcher->glist());
                //  connect to associated object
                if(obj_connect(&px->pdobj,0,(t_object *)obj->pdobj,inlet)) {
                    obj->AddProxyIn(inlet,px);
                }
                else {
                    glist_delete(patcher->glist(),(t_gobj *)px);
                    px = NULL;

                    // could not connect
                    post("Couldn't connect proxy object");
                }
//                    canvas_unsetcurrent(patcher->glist());
//                    sys_unlock();
            }
        }

        if(px) {
//                sys_lock();
            px->Message(sym,argc,argv);
//                sys_unlock();
            return DYN_ERROR_NONE;
        }
        else
            return DYN_ERROR_GENERAL;
    }
    else
        return DYN_ERROR_TYPEMISMATCH;
}

DYN_EXPORT int dyn_SendStr(int sched,dyn_id id,int inlet,const char *msg)
{
    t_binbuf *b = binbuf_new();
    binbuf_text(b,(char *)msg,strlen(msg));
    int argc = binbuf_getnatom(b);
    t_atom *argv = binbuf_getvec(b);
    int ret;
    if(argc) {
        t_symbol *sym;
        if(argv->a_type == A_SYMBOL) { sym = atom_getsymbol(argv); argc--,argv++; }
        else sym = &s_list;
        ret = dyn_Send(sched,id,inlet,sym,argc,argv);
    }
    else
        ret = DYN_ERROR_PARAMS;
    binbuf_free(b);
    return ret;
}