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
******************************************************/
17
/* 2305:forum::f�r::uml�ute:2001 */
26
/* ------------------------- list ------------------------------- */
28
/* this is for packages, what "float" is for floats */
30
#define LIST_NGETBYTE 100 /* bigger that this we use alloc, not alloca */
33
static t_class *mypdlist_class;
36
# define ATOMS_ALLOCA(x, n) ((x) = (t_atom *)((n) < LIST_NGETBYTE ? \
37
alloca((n) * sizeof(t_atom)) : getbytes((n) * sizeof(t_atom))))
38
# define ATOMS_FREEA(x, n) ( \
39
((n) < LIST_NGETBYTE || (freebytes((x), (n) * sizeof(t_atom)), 0)))
41
# define ATOMS_ALLOCA(x, n) ((x) = (t_atom *)getbytes((n) * sizeof(t_atom)))
42
# define ATOMS_FREEA(x, n) (freebytes((x), (n) * sizeof(t_atom)))
45
static void atoms_copy(int argc, t_atom *from, t_atom *to)
48
for (i = 0; i < argc; i++)
53
static void mypdlist_storelist(t_mypdlist *x, int argc, t_atom *argv)
55
if(x->x_list)freebytes(x->x_list, x->x_n*sizeof(t_atom));
57
x->x_list=(t_atom*)getbytes(x->x_n*sizeof(t_atom));
59
atoms_copy(argc, argv, x->x_list);
61
static void mypdlist_secondlist(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv)
63
mypdlist_storelist(x, argc, argv);
66
static void mypdlist_bang(t_mypdlist *x)
70
ATOMS_ALLOCA(outv, outc);
71
atoms_copy(x->x_n, x->x_list, outv);
72
outlet_list(x->x_obj.ob_outlet, gensym("list"), outc, outv);
73
ATOMS_FREEA(outv, outc);
77
static void mypdlist_list(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv)
79
mypdlist_secondlist(x, s, argc, argv);
84
static void mypdlist_free(t_mypdlist *x)
85
{ freebytes(x->x_list, x->x_n * sizeof(t_atom)); }
87
static void *mypdlist_new(t_symbol *s, int argc, t_atom *argv)
89
t_mypdlist *x = (t_mypdlist *)pd_new(mypdlist_class);
91
outlet_new(&x->x_obj, 0);
92
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("lst2"));
98
mypdlist_secondlist(x, gensym("list"), argc, argv);
104
static void mypdlist_help(t_mypdlist*x)
106
post("\n%c lister\t\t:: basic list storage (use pd>=0.39 for real [list] objects)", HEARTSYMBOL);
109
void lister_setup(void)
111
mypdlist_class = class_new(gensym("lister"), (t_newmethod)mypdlist_new,
112
(t_method)mypdlist_free, sizeof(t_mypdlist), 0, A_GIMME, 0);
113
/* i don't know how to get this work with name=="list" !!! */
115
class_addcreator((t_newmethod)mypdlist_new, gensym("l"), A_GIMME, 0);
117
class_addbang (mypdlist_class, mypdlist_bang);
118
class_addlist (mypdlist_class, mypdlist_list);
119
class_addmethod (mypdlist_class, (t_method)mypdlist_secondlist, gensym("lst2"), A_GIMME, 0);
121
class_addmethod(mypdlist_class, (t_method)mypdlist_help, gensym("help"), A_NULL);
122
zexy_register("lister");