aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/dyn/dyn_proxy.cpp
blob: f2b85a91d8bdee3f9f9a5e0c7bbeceb478e23348 (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
/* 
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"

// proxy

void proxy::px_exit(proxy *px) 
{ 
    if(px->buf) FreeAligned(px->buf); 
}


// proxyin

void proxyin::init(dyn_patchable *obj,bool s)
{
    proxy::init(obj);
    outlet = outlet_new(&pdobj,s?&s_signal:&s_anything); 
}

void proxyin::px_method(proxyin *th,const t_symbol *s,int argc,const t_atom *argv)
{
    // send to connected object
	outlet_anything(th->outlet,(t_symbol *)s,argc,(t_atom *)argv);
}

void proxyin::dsp(proxyin *x, t_signal **sp) 
{
	int n = sp[0]->s_n;
	if(n != x->n) {
		// if vector size has changed make new buffer
		if(x->buf) FreeAligned(x->buf);
		x->buf = (t_sample *)NewAligned(sizeof(t_sample)*(x->n = n));
	}
	dsp_add_copy(x->buf,sp[0]->s_vec,n);
}


// proxyout

void proxyout::init(dyn_patchable *obj,int o,bool s)
{
    proxy::init(obj);
    listeners = new Listeners;
    outlet = o;
    if(s) outlet_new(&pdobj,&s_signal); 
}

void proxyout::exit()
{
    // invalidate all listeners
    for(Listeners::const_iterator it = listeners->begin(); it != listeners->end(); ++it)
        Destroy(*it);
    // delete container
    delete listeners;
}

void proxyout::Rmv(proxyout *px,dyn_listen *l) 
{ 
    px->listeners->erase(l);

    // if there are no more listeners we can delete the object!
    if(px->listeners->empty()) {
        dyn_patcher *p = px->object->owner;

        // remove reference
        px->object->RmvProxyOut(px->outlet);

        // delete PD object
        glist_delete(p->glist(),(t_gobj *)px);
    }
}

void proxyout::px_method(proxyout *th,const t_symbol *s,int argc,const t_atom *argv)
{
    // call attached responders
    for(Listeners::const_iterator it = th->listeners->begin(); it != th->listeners->end(); ++it)
        (*it)->Callback(th->outlet,s,argc,argv);
}

void proxyout::dsp(proxyout *x, t_signal **sp)
{
	int n = sp[0]->s_n;
	if(n != x->n) {
		// if vector size has changed make new buffer
		if(x->buf) FreeAligned(x->buf);
		x->buf = (t_sample *)NewAligned(sizeof(t_sample)*(x->n = n));
	}
	dsp_add_copy(sp[0]->s_vec,x->buf,n);
}