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
/* 3108:forum::f�r::uml�ute:2000 */
19
/* objects for manipulating packages*/
22
repack : (re)pack floats/symbols/pointers to fixed-length packages
28
/* -------------------- repack ------------------------------ */
31
(re)pack a sequence of (packages of) atoms into a package of given length
33
"bang" gives out the current package immediately
34
the second inlet lets you change the default package size
37
static t_class *repack_class;
39
typedef struct _repack
50
static void repack_set(t_repack *x, t_float f)
52
/* set the new default size */
57
/* flush all the newsized packages that are in the buffer */
58
t_atom *dumbuf = x->buffer;
59
int dumcur = x->current;
62
outlet_list(x->x_obj.ob_outlet, gensym("list"), n, dumbuf);
67
if (dumcur < 0) error("this should never happen :: dumcur = %d < 0", dumcur);
69
memcpy(x->buffer, dumbuf, dumcur * sizeof(t_atom));
74
dumbuf = (t_atom *)getbytes(n * sizeof(t_atom));
75
memcpy(dumbuf, x->buffer, x->current * sizeof(t_atom));
76
freebytes(x->buffer, x->bufsize * sizeof(t_atom));
85
static void repack_bang(t_repack *x)
87
/* output the list as far as we are now */
88
outlet_list(x->x_obj.ob_outlet, gensym("list"), x->current, x->buffer);
92
static void repack_float(t_repack *x, t_float f)
94
/* add a float-atom to the list */
95
SETFLOAT(&x->buffer[x->current], f);
97
if (x->current >= x->outputsize) repack_bang(x);
100
static void repack_symbol(t_repack *x, t_symbol *s)
102
/* add a sym-atom to the list */
103
SETSYMBOL(&x->buffer[x->current], s);
105
if (x->current >= x->outputsize) repack_bang(x);
107
static void repack_pointer(t_repack *x, t_gpointer *p)
109
/* add a pointer-atom to the list */
110
SETPOINTER(&x->buffer[x->current], p);
112
if (x->current >= x->outputsize) repack_bang(x);
114
static void repack_list(t_repack *x, t_symbol *s, int argc, t_atom *argv)
116
int remain = x->outputsize - x->current;
120
if (argc >= remain) {
121
memcpy(x->buffer+x->current, ap, remain * sizeof(t_atom));
124
outlet_list(x->x_obj.ob_outlet, gensym("list"), x->outputsize, x->buffer);
128
while (argc >= x->outputsize) {
129
outlet_list(x->x_obj.ob_outlet, gensym("list"), x->outputsize, ap);
131
argc -= x->outputsize;
134
memcpy(x->buffer + x->current, ap, argc * sizeof(t_atom));
137
static void repack_anything(t_repack *x, t_symbol *s, int argc, t_atom *argv)
139
SETSYMBOL(&x->buffer[x->current], s);
142
if (x->current >= x->outputsize) {
145
repack_list(x, gensym("list"), argc, argv);
148
static void *repack_new(t_floatarg f)
150
t_repack *x = (t_repack *)pd_new(repack_class);
154
x->outputsize = x->bufsize = (f>0.f)?f:2 ;
158
x->buffer = (t_atom *)getbytes(x->bufsize * sizeof(t_atom));
160
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym(""));
161
outlet_new(&x->x_obj, 0);
166
void repack_setup(void)
168
repack_class = class_new(gensym("repack"), (t_newmethod)repack_new,
169
0, sizeof(t_repack), 0, A_DEFFLOAT, 0);
171
class_addbang (repack_class, repack_bang);
172
class_addfloat (repack_class, repack_float);
173
class_addsymbol (repack_class, repack_symbol);
174
class_addpointer (repack_class, repack_pointer);
175
class_addlist (repack_class, repack_list);
176
class_addanything(repack_class, repack_anything);
177
class_addmethod (repack_class, (t_method)repack_set, gensym(""), A_DEFFLOAT, 0);
179
zexy_register("repack");