1
/******************************************************
3
* zexy - implementation file
5
* copyleft (c) IOhannes m zm�lnig
7
* 1999:forum::f�r::uml�ute:2004
9
* institute of electronic music and acoustics (iem)
11
******************************************************
13
* license: GNU General Public License v.2
15
******************************************************/
22
/* ------------------------- glue ------------------------------- */
24
/* glue 2 lists together (append) */
26
static t_class *glue_class;
38
static void glue_lst2(t_glue *x, t_symbol *s, int argc, t_atom *argv)
43
freebytes(x->ap2, x->n2 * sizeof(t_atom));
45
x->ap2 = copybytes(argv, argc * sizeof(t_atom));
46
} else memcpy(x->ap2, argv, argc * sizeof(t_atom));
49
static void glue_lst(t_glue *x, t_symbol *s, int argc, t_atom *argv)
52
if (x->n != x->n2+argc) {
53
freebytes(x->ap, x->n * sizeof(t_atom));
56
x->ap = (t_atom *)getbytes(sizeof(t_atom)*x->n);
57
memcpy(x->ap+argc, x->ap2, x->n2*sizeof(t_atom));
58
} else if ((x->n1 != argc)||x->changed)memcpy(x->ap+argc, x->ap2, x->n2*sizeof(t_atom));
61
memcpy(x->ap, argv, x->n1*sizeof(t_atom));
65
outlet_list(x->x_obj.ob_outlet, gensym("list"), x->n, x->ap);
68
static void glue_bang(t_glue *x)
71
if (x->n1+x->n2 != x->n){
72
t_atom *ap = (t_atom*)getbytes(sizeof(t_atom)*(x->n1+x->n2));
73
memcpy(ap, x->ap, x->n1*sizeof(t_atom));
74
freebytes(x->ap, sizeof(t_atom)*x->n);
78
memcpy(x->ap+x->n1, x->ap2, x->n2*sizeof(t_atom));
82
outlet_list(x->x_obj.ob_outlet, gensym("list"), x->n, x->ap);
85
static void glue_free(t_glue *x)
87
freebytes(x->ap, sizeof(t_atom)*x->n);
88
freebytes(x->ap2, sizeof(t_atom)*x->n2);
91
static void *glue_new(t_symbol *s, int argc, t_atom *argv)
93
t_glue *x = (t_glue *)pd_new(glue_class);
96
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym(""));
97
outlet_new(&x->x_obj, 0);
102
if (argc)glue_lst2(x, gensym("list"), argc, argv);
107
static void glue_help(t_glue*x)
109
post("\n%c glue\t\t:: glue together 2 lists (like [list append])", HEARTSYMBOL);
112
void glue_setup(void)
114
glue_class = class_new(gensym("glue"), (t_newmethod)glue_new,
115
(t_method)glue_free, sizeof(t_glue), 0, A_GIMME, 0);
116
class_addlist(glue_class, glue_lst);
117
class_addmethod (glue_class, (t_method)glue_lst2, gensym(""), A_GIMME, 0);
118
class_addbang(glue_class, glue_bang);
119
class_addmethod (glue_class, (t_method)glue_help, gensym("help"), 0);
121
zexy_register("glue");