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
******************************************************/
18
/* 3108:forum::f�r::uml�ute:2000 */
20
/* ------------------------- packel ------------------------------- */
23
get the nth element of a package
28
static t_class *packel_class;
30
typedef struct _packel
43
static void packel_outelement(t_packel*x, int id, t_symbol*s,int argc, t_atom*argv)
45
t_outlet*out=x->x_outlet[id];
46
int index= x->position[id];
50
int pos = (index < 0)?(argc+index):(index-1);
53
if (pos==0||pos==-1)outlet_bang(out);
57
if (pos < 0 || pos >= argc)return;
59
current = &(argv[pos]);
61
switch (current->a_type) {
65
outlet_list(out, gensym("list"), 1, current);
67
} else outlet_list(out, s, argc, argv);
70
static void packel_list(t_packel *x, t_symbol *s, int argc, t_atom *argv)
74
packel_outelement(x, c, s, argc, argv);
78
static void packel_anything(t_packel *x, t_symbol *s, int argc, t_atom *argv)
80
t_atom *av2 = (t_atom *)getbytes((argc + 1) * sizeof(t_atom));
84
pd_error(x, "deprecation warning: you should only use lists for list data");
88
for (i = 0; i < argc; i++)
91
packel_list(x, gensym("list"), argc+1, av2);
92
freebytes(av2, (argc + 1) * sizeof(t_atom));
96
static void packel_free(t_packel *x)
100
for(i=0; i<x->count; i++) {
101
if(x->x_inlet &&x->x_inlet [i])inlet_free (x->x_inlet [i]);
102
if(x->x_outlet&&x->x_outlet[i])outlet_free(x->x_outlet[i]);
105
if(x->position)freebytes(x->position, x->count*sizeof(t_float));
106
if(x->x_inlet) freebytes(x->x_inlet, x->count*sizeof(t_inlet*));
107
if(x->x_outlet)freebytes(x->x_outlet, x->count*sizeof(t_outlet*));
112
static void *packel_new(t_symbol*s, int argc, t_atom*argv)
114
t_packel *x = (t_packel *)pd_new(packel_class);
116
x->count=(argc>0)?argc:1;
118
x->position=(t_float*)getbytes(x->count*sizeof(t_float));
119
x->x_inlet=(t_inlet**)getbytes(x->count*sizeof(t_inlet*));
120
x->x_outlet=(t_outlet**)getbytes(x->count*sizeof(t_outlet*));
124
x->x_inlet[0]=floatinlet_new(&x->x_obj, x->position);
125
x->x_outlet[0]=outlet_new(&x->x_obj, 0);
128
for(i=0; i<x->count; i++) {
129
x->position[i]=atom_getfloat(argv+i);
130
x->x_inlet [i]=floatinlet_new(&x->x_obj, x->position+i);
131
x->x_outlet [i]=outlet_new(&x->x_obj, 0);
140
void packel_setup(void)
142
packel_class = class_new(gensym("packel"),
143
(t_newmethod)packel_new, (t_method)packel_free,
147
class_addlist (packel_class, packel_list);
148
class_addanything(packel_class, packel_anything);
150
zexy_register("packel");