aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/dyn/dyn_patchable.cpp
blob: a61930e70371592d9571525e1b51da904e799b33 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* 
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_patchable::dyn_patchable(dyn_id id,dyn_patcher *o,t_gobj *obj)
    : dyn_base(id)
    , pdobj(obj),owner(o)
{
    if(owner) owner->Add(this);
}

dyn_patchable::~dyn_patchable()
{
    if(owner) {
        // if no owner, it must be a "root" patcher, which is not connectable

        owner->Remove(this);

        t_glist *glist = owner->glist();

    //	canvas_setcurrent(glist); 

        // delete object itself
        glist_delete(glist,pdobj);

        // delete proxies
        for(Proxies::iterator iit = pxin.begin(); iit != pxin.end(); ++iit) {
            proxyin *px = (proxyin *)iit->second;
            glist_delete(glist,(t_gobj *)px);
        }

        for(Proxies::iterator oit = pxout.begin(); oit != pxout.end(); ++oit) {
            proxyout *px = (proxyout *)oit->second;
            glist_delete(glist,(t_gobj *)px);
        }

    //	canvas_unsetcurrent(glist); 

        // invalidate all associated connection objects
        // the connection objects will not be deleted here!
        Connections::iterator cit;
        for(cit = inconns.begin(); cit != inconns.end(); ++cit)
            Destroy(*cit);

        for(cit = outconns.begin(); cit != outconns.end(); ++cit)
            Destroy(*cit);
    }
    else {
        dyn_patcher *p = dynamic_cast<dyn_patcher *>(this);
        ASSERT(p);

        // delete "root"-patcher
        canvas_free(p->glist());
    }
}

void dyn_patchable::AddInlet(dyn_conn *o)
{
    ASSERT(inconns.find(o) == inconns.end());
    inconns.insert(o);
}

void dyn_patchable::RmvInlet(dyn_conn *o)
{
    ASSERT(inconns.find(o) != inconns.end());
    inconns.erase(o);
}

void dyn_patchable::AddOutlet(dyn_conn *o)
{
    ASSERT(outconns.find(o) == outconns.end());
    outconns.insert(o);
}

void dyn_patchable::RmvOutlet(dyn_conn *o)
{
    ASSERT(outconns.find(o) != outconns.end());
    outconns.erase(o);
}

void dyn_patchable::EnumInlet(int ix,dyn_enumfun fun,void *data)
{
    for(Connections::const_iterator it = inconns.begin(); it != inconns.end(); ++it) {
        const dyn_conn *c = *it;
        if(c->dlet == ix && !fun(c->ident,data)) break;
    }
}

void dyn_patchable::EnumOutlet(int ix,dyn_enumfun fun,void *data)
{
    for(Connections::const_iterator it = outconns.begin(); it != outconns.end(); ++it) {
        const dyn_conn *c = *it;
        if(c->slet == ix && !fun(c->ident,data)) break;
    }
}