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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*
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_EnumObjects(dyn_id id,dyn_enumfun fun,void *data)
{
dyn_patcher *p;
if(id && (p = id->Patcher())) {
p->Enumerate(fun,data);
return DYN_ERROR_NONE;
}
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_NewPatcher(int sched,dyn_id *sid,dyn_callback cb,dyn_id psid /*,const char *name*/)
{
try {
ASSERT(sid);
*sid = NewObject(DYN_TYPE_PATCHER,cb,psid,NULL);
return *sid?DYN_ERROR_NONE:DYN_ERROR_GENERAL;
}
catch(int err) { return err; }
}
DYN_EXPORT int dyn_NewObject(int sched,dyn_id *oid,dyn_callback cb,dyn_id sid,const t_symbol *obj,int argc,const t_atom *argv)
{
try {
ASSERT(oid);
*oid = NewObject(DYN_TYPE_OBJECT,cb,sid,obj,argc,argv);
return *oid?DYN_ERROR_NONE:DYN_ERROR_GENERAL;
}
catch(int err) { return err; }
}
DYN_EXPORT int dyn_NewObjectStr(int sched,dyn_id *oid,dyn_callback cb,dyn_id sid,const char *args)
{
t_binbuf *b = binbuf_new();
binbuf_text(b,(char *)args,strlen(args));
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_NewObject(sched,oid,cb,sid,sym,argc,argv);
}
else
ret = DYN_ERROR_PARAMS;
binbuf_free(b);
return ret;
}
DYN_EXPORT int dyn_NewMessage(int sched,dyn_id *oid,dyn_callback cb,dyn_id sid,int argc,t_atom *argv)
{
try {
ASSERT(oid);
*oid = NewObject(DYN_TYPE_MESSAGE,cb,sid,NULL,argc,argv);
return *oid?DYN_ERROR_NONE:DYN_ERROR_GENERAL;
}
catch(int err) { return err; }
}
DYN_EXPORT int dyn_NewMessageStr(int sched,dyn_id *oid,dyn_callback cb,dyn_id sid,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 = dyn_NewMessage(sched,oid,cb,sid,argc,argv);
binbuf_free(b);
return ret;
}
DYN_EXPORT int dyn_NewConnection(int sched,dyn_id *cid,dyn_callback cb,dyn_id soid,int outlet,dyn_id doid,int inlet)
{
ASSERT(cid);
ASSERT(soid && inlet >= 0);
ASSERT(doid && outlet >= 0);
dyn_patchable *sobj = soid->Patchable();
dyn_patchable *dobj = doid->Patchable();
int ret = DYN_ERROR_NONE;
dyn_id conn = DYN_ID_NONE;
if(!sobj || !dobj) {
ret = DYN_ERROR_TYPEMISMATCH;
goto error;
}
if(sobj->owner != dobj->owner) {
ret = DYN_ERROR_CONN_PATCHER;
goto error;
}
{
dyn_patcher *patcher = sobj->owner;
ASSERT(patcher);
// sys_lock();
canvas_setcurrent(patcher->glist());
bool ok =
!canvas_isconnected(patcher->glist(),(t_text *)sobj->pdobj,outlet,(t_text *)dobj->pdobj,inlet) &&
obj_connect((t_object *)sobj->pdobj, outlet,(t_object *)dobj->pdobj,inlet);
canvas_unsetcurrent(patcher->glist());
// sys_unlock();
if(!ok) {
ret = DYN_ERROR_CONN_GENERAL;
goto error;
}
}
conn = new dyn_ident(DYN_TYPE_CONN,cb);
conn->Set(new dyn_conn(conn,soid,outlet,doid,inlet));
// add connection to object lists
sobj->AddOutlet(conn->Conn());
dobj->AddInlet(conn->Conn());
*cid = conn;
return ret;
error:
if(conn != DYN_ID_NONE) delete conn;
return ret;
}
DYN_EXPORT int dyn_Free(int sched,dyn_id oid)
{
try {
DelObject(oid);
return DYN_ERROR_NONE;
}
catch(int err) { return err; }
}
// NOT IMPLEMENTED
DYN_EXPORT int dyn_Reset()
{
return DYN_ERROR_GENERAL;
}
DYN_EXPORT int dyn_SetData(dyn_id oid,void *data)
{
if(oid) {
oid->userdata = data;
return DYN_ERROR_NONE;
}
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_GetData(dyn_id oid,void **data)
{
ASSERT(data);
if(oid) {
*data = oid->userdata;
return DYN_ERROR_NONE;
}
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_GetType(dyn_id oid)
{
if(oid)
return oid->type;
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_GetInletCount(dyn_id id)
{
dyn_patchable *p;
if(id && (p = id->Patchable()))
return p->GetInletCount();
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_GetOutletCount(dyn_id id)
{
dyn_patchable *p;
if(id && (p = id->Patchable()))
return p->GetOutletCount();
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_GetInletType(dyn_id id,int inlet)
{
dyn_patchable *p;
if(id && (p = id->Patchable()))
return p->GetInletType(inlet);
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_GetOutletType(dyn_id id,int outlet)
{
dyn_patchable *p;
if(id && (p = id->Patchable()))
return p->GetOutletType(outlet);
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_GetConnectionSource(dyn_id cid,dyn_id *soid,int *outlet)
{
ASSERT(soid && outlet);
dyn_conn *c;
if(cid && (c = cid->Conn())) {
*soid = c->src;
*outlet = c->slet;
return DYN_ERROR_NONE;
}
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_GetConnectionDrain(dyn_id cid,dyn_id *doid,int *inlet)
{
ASSERT(doid && inlet);
dyn_conn *c;
if(cid && (c = cid->Conn())) {
*doid = c->dst;
*inlet = c->dlet;
return DYN_ERROR_NONE;
}
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_EnumInletConnections(dyn_id id,int inlet,dyn_enumfun fun,void *data)
{
dyn_patchable *p;
if(id && (p = id->Patchable())) {
p->EnumInlet(inlet,fun,data);
return DYN_ERROR_NONE;
}
else
return DYN_ERROR_NOTFOUND;
}
DYN_EXPORT int dyn_EnumOutletConnections(dyn_id id,int outlet,dyn_enumfun fun,void *data)
{
dyn_patchable *p;
if(id && (p = id->Patchable())) {
p->EnumOutlet(outlet,fun,data);
return DYN_ERROR_NONE;
}
else
return DYN_ERROR_NOTFOUND;
}
|