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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
/* ----------------------- iem_append -------------------------- */
/* -- concatenates message from hot (left) inlet with message -- */
/* ------ from cold (right) inlet and outputs it; initial ----- */
/* -- arguments (appendix) are eqal to message of cold inlet --- */
struct _iem_append_proxy;
static t_class *iem_append_class;
static t_class *iem_append_proxy_class;
typedef struct _iem_append
{
t_object x_obj;
struct _iem_append_proxy *x_proxy_inlet;
int x_size12;
int x_size2;
int x_ac1;
int x_ac2;
t_atom *x_at12;
t_atom *x_at2;
t_symbol *x_selector_sym1;
t_symbol *x_selector_sym2;
t_atomtype x_type1;
t_atomtype x_type2;
} t_iem_append;
typedef struct _iem_append_proxy
{
t_object p_obj;
t_iem_append *p_owner;
} t_iem_append_proxy;
static void iem_append_atcopy(t_atom *src, t_atom *dst, int n)
{
while(n--)
*dst++ = *src++;
}
static void iem_append_merge(t_iem_append *x, int off)
{
if((x->x_ac1+x->x_ac2+1) > x->x_size12)
{
x->x_at12 = (t_atom *)resizebytes(x->x_at12, x->x_size12*sizeof(t_atom), 2*(x->x_ac1+x->x_ac2+1)*sizeof(t_atom));
x->x_size12 = 2*(x->x_ac1+x->x_ac2+1);
}
if(off)
SETSYMBOL(x->x_at12 + x->x_ac1, x->x_selector_sym2);
iem_append_atcopy(x->x_at2, x->x_at12 + x->x_ac1 + off, x->x_ac2);
}
static void iem_append_out(t_iem_append *x)
{
int off=0;
if(x->x_type1 == A_GIMME)
{
if(x->x_type2 == A_COMMA)
off = 1;
else
off = 0;
iem_append_merge(x, off);
outlet_list(x->x_obj.ob_outlet, &s_list, x->x_ac1+x->x_ac2+off, x->x_at12);
}
else if(x->x_type1 == A_COMMA)
{
if(x->x_type2 == A_COMMA)
off = 1;
else
off = 0;
iem_append_merge(x, off);
outlet_anything(x->x_obj.ob_outlet, x->x_selector_sym1, x->x_ac1+x->x_ac2+off, x->x_at12);
}
else if(x->x_type1 == A_NULL)/*depends on 2.part*/
{
iem_append_merge(x, 0);
if(x->x_type2 == A_GIMME)
outlet_list(x->x_obj.ob_outlet, &s_list, x->x_ac2, x->x_at12);
else if(x->x_type2 == A_COMMA)
outlet_anything(x->x_obj.ob_outlet, x->x_selector_sym2, x->x_ac2, x->x_at12);
else if(x->x_type2 == A_FLOAT)
outlet_float(x->x_obj.ob_outlet, atom_getfloat(x->x_at12));
else if(x->x_type2 == A_SYMBOL)
outlet_symbol(x->x_obj.ob_outlet, atom_getsymbol(x->x_at12));
else if(x->x_type2 == A_NULL)
outlet_bang(x->x_obj.ob_outlet);
else if(x->x_type2 == A_POINTER)
outlet_pointer(x->x_obj.ob_outlet, (t_gpointer *)x->x_at12->a_w.w_gpointer);
}
else
{
if(x->x_type2 == A_COMMA)
off = 1;
else
off = 0;
iem_append_merge(x, off);
if(x->x_type2 == A_NULL)
{
if(x->x_type1 == A_FLOAT)
outlet_float(x->x_obj.ob_outlet, atom_getfloat(x->x_at12));
else if(x->x_type1 == A_SYMBOL)
outlet_symbol(x->x_obj.ob_outlet, atom_getsymbol(x->x_at12));
else if(x->x_type1 == A_POINTER)
outlet_pointer(x->x_obj.ob_outlet, (t_gpointer *)x->x_at12->a_w.w_gpointer);
}
else
outlet_list(x->x_obj.ob_outlet, &s_list, x->x_ac1+x->x_ac2+off, x->x_at12);
}
}
static void iem_append_bang(t_iem_append *x)
{
x->x_ac1 = 0;
x->x_type1 = A_NULL;
iem_append_out(x);
}
static void iem_append_float(t_iem_append *x, t_float f)
{
x->x_ac1 = 1;
x->x_type1 = A_FLOAT;
SETFLOAT(x->x_at12, f);
iem_append_out(x);
}
static void iem_append_symbol(t_iem_append *x, t_symbol *s)
{
x->x_ac1 = 1;
x->x_type1 = A_SYMBOL;
SETSYMBOL(x->x_at12, s);
iem_append_out(x);
}
static void iem_append_pointer(t_iem_append *x, t_gpointer *gp)
{
x->x_ac1 = 1;
x->x_type1 = A_POINTER;
SETPOINTER(x->x_at12, gp);
iem_append_out(x);
}
static void iem_append_list(t_iem_append *x, t_symbol *s, int ac, t_atom *av)
{
if((x->x_size2+ac+1) > x->x_size12)
{
x->x_at12 = (t_atom *)resizebytes(x->x_at12, x->x_size12*sizeof(t_atom), (x->x_size2+ac+11)*sizeof(t_atom));
x->x_size12 = x->x_size2+ac+11;
}
x->x_ac1 = ac;
x->x_type1 = A_GIMME;
iem_append_atcopy(av, x->x_at12, ac);
x->x_selector_sym1 = &s_list;
iem_append_out(x);
}
static void iem_append_anything(t_iem_append *x, t_symbol *s, int ac, t_atom *av)
{
if((x->x_size2+ac+2) > x->x_size12)
{
x->x_at12 = (t_atom *)resizebytes(x->x_at12, x->x_size12*sizeof(t_atom), (x->x_size2+ac+12)*sizeof(t_atom));
x->x_size12 = x->x_size2+ac+12;
}
x->x_ac1 = ac;
x->x_type1 = A_COMMA;
iem_append_atcopy(av, x->x_at12, ac);
x->x_selector_sym1 = s;
iem_append_out(x);
}
/* begin of proxy methods (anything inlets) */
static void iem_append_proxy_bang(t_iem_append_proxy *p)
{
t_iem_append *x = p->p_owner;
x->x_ac2 = 0;
x->x_type2 = A_NULL;
x->x_selector_sym2 = &s_list;
}
static void iem_append_proxy_float(t_iem_append_proxy *p, t_float f)
{
t_iem_append *x = p->p_owner;
x->x_ac2 = 1;
x->x_type2 = A_FLOAT;
SETFLOAT(x->x_at2, f);
x->x_selector_sym2 = &s_list;
}
static void iem_append_proxy_symbol(t_iem_append_proxy *p, t_symbol *s)
{
t_iem_append *x = p->p_owner;
x->x_ac2 = 1;
x->x_type2 = A_SYMBOL;
SETSYMBOL(x->x_at2, s);
x->x_selector_sym2 = &s_list;
}
static void iem_append_proxy_pointer(t_iem_append_proxy *p, t_gpointer *gp)
{
t_iem_append *x = p->p_owner;
x->x_ac2 = 1;
x->x_type2 = A_POINTER;
SETPOINTER(x->x_at2, gp);
x->x_selector_sym2 = &s_list;
}
static void iem_append_proxy_list(t_iem_append_proxy *p, t_symbol *s, int ac, t_atom *av)
{
t_iem_append *x = p->p_owner;
if(ac > x->x_size2)
{
x->x_at2 = (t_atom *)resizebytes(x->x_at2, x->x_size2*sizeof(t_atom), (ac+10)*sizeof(t_atom));
x->x_size2 = (ac+10);
}
x->x_ac2 = ac;
x->x_type2 = A_GIMME;
x->x_selector_sym2 = &s_list;
iem_append_atcopy(av, x->x_at2, ac);
}
static void iem_append_proxy_anything(t_iem_append_proxy *p, t_symbol *s, int ac, t_atom *av)
{
t_iem_append *x = p->p_owner;
if((ac+1) > x->x_size2)
{
x->x_at2 = (t_atom *)resizebytes(x->x_at2, x->x_size2*sizeof(t_atom), (ac+11)*sizeof(t_atom));
x->x_size2 = ac+11;
}
x->x_ac2 = ac;
x->x_type2 = A_COMMA;
x->x_selector_sym2 = s;
iem_append_atcopy(av, x->x_at2, ac);
}
/* end of proxy methods (anything inlets) */
static void iem_append_free(t_iem_append *x)
{
if(x->x_at12)
freebytes(x->x_at12, x->x_size12 * sizeof(t_atom));
if(x->x_at2)
freebytes(x->x_at2, x->x_size2 * sizeof(t_atom));
if(x->x_proxy_inlet)
pd_free((t_pd *)x->x_proxy_inlet);
}
static void *iem_append_new(t_symbol *s, int ac, t_atom *av)
{
t_iem_append *x = (t_iem_append *)pd_new(iem_append_class);
t_iem_append_proxy *p = (t_iem_append_proxy *)pd_new(iem_append_proxy_class);
x->x_proxy_inlet = p;
p->p_owner = x;
x->x_type1 = A_NULL;
x->x_selector_sym1 = &s_list;
x->x_size2 = 10;
if(ac > 5)
x->x_size2 = 2*ac;
x->x_at2 = (t_atom *)getbytes(x->x_size2 * sizeof(t_atom));
x->x_size12 = x->x_size2 + 10;
x->x_at12 = (t_atom *)getbytes(x->x_size12 * sizeof(t_atom));
x->x_ac1 = 0;
if(ac <= 0)
{
x->x_type2 = A_NULL;
x->x_ac2 = 0;
x->x_selector_sym2 = &s_list;
}
else
{
if(IS_A_FLOAT(av, 0))
{
if(ac == 1)
iem_append_proxy_float(p, atom_getfloat(av));
else
iem_append_proxy_list(p, &s_list, ac, av);
}
else if(IS_A_SYMBOL(av, 0))
{
t_symbol *xsym=atom_getsymbol(av);
if(xsym == &s_symbol)
{
if(ac > 1)
iem_append_proxy_symbol(p, atom_getsymbol(av+1));
else
iem_append_proxy_symbol(p, gensym(""));
}
else if(xsym == &s_float)
{
if(ac > 1)
{
if(IS_A_FLOAT(av, 1))
iem_append_proxy_float(p, atom_getfloat(av+1));
else
iem_append_proxy_float(p, 0.0f);
}
else
iem_append_proxy_float(p, 0.0f);
}
else if(xsym == &s_list)
{
iem_append_proxy_list(p, &s_list, ac-1, av+1);
}
else
{
iem_append_proxy_anything(p, xsym, ac-1, av+1);
}
}
}
inlet_new((t_object *)x, (t_pd *)p, 0, 0);
outlet_new(&x->x_obj, &s_list);
return (x);
}
void iem_append_setup(void)
{
iem_append_class = class_new(gensym("iem_append"),
(t_newmethod)iem_append_new, (t_method)iem_append_free,
sizeof(t_iem_append), 0, A_GIMME, 0);
class_addcreator((t_newmethod)iem_append_new, gensym("merge_any"), A_GIMME, 0);
class_addbang(iem_append_class, (t_method)iem_append_bang);
class_addpointer(iem_append_class, iem_append_pointer);
class_addfloat(iem_append_class, (t_method)iem_append_float);
class_addsymbol(iem_append_class, iem_append_symbol);
class_addlist(iem_append_class, iem_append_list);
class_addanything(iem_append_class, iem_append_anything);
// class_sethelpsymbol(iem_append_class, gensym("iemhelp/help-iem_append"));
iem_append_proxy_class = class_new(gensym("_iem_append_proxy"),
0, 0, sizeof(t_iem_append_proxy), CLASS_PD | CLASS_NOINLET, 0);
class_addbang(iem_append_proxy_class, (t_method)iem_append_proxy_bang);
class_addpointer(iem_append_proxy_class, iem_append_proxy_pointer);
class_addfloat(iem_append_proxy_class, (t_method)iem_append_proxy_float);
class_addsymbol(iem_append_proxy_class, iem_append_proxy_symbol);
class_addlist(iem_append_proxy_class, iem_append_proxy_list);
class_addanything(iem_append_proxy_class, iem_append_proxy_anything);
}
|