Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21539
Modified Files:
sort.c
Log Message:
added a 2nd outlet to get the indices for sorting
Index: sort.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/sort.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** sort.c 22 Mar 2005 20:58:23 -0000 1.1
--- sort.c 4 Apr 2005 12:23:48 -0000 1.2
***************
*** 37,42 ****
--- 37,45 ----
int bufsize;
t_float *buffer;
+ t_int *indices;
int ascending;
+
+ t_outlet*indexOut, *sortedOut;
} t_sort;
***************
*** 50,65 ****
{
int n = argc;
! t_float *buf;
t_atom *atombuf = argv;
if (argc != x->bufsize) {
! if (x->buffer) freebytes(x->buffer, x->bufsize * sizeof(t_float));
x->bufsize = argc;
x->buffer = getbytes(x->bufsize * sizeof(t_float));
}
buf = x->buffer;
! while (n--)
*buf++ = atom_getfloat(atombuf++);
}
--- 53,73 ----
{
int n = argc;
! t_float *buf, *idx;
t_atom *atombuf = argv;
if (argc != x->bufsize) {
! if (x->buffer) freebytes(x->buffer, x->bufsize * sizeof(t_float));
! if (x->indices)freebytes(x->indices, x->bufsize * sizeof(t_int));
!
x->bufsize = argc;
x->buffer = getbytes(x->bufsize * sizeof(t_float));
+ x->indices = getbytes(x->bufsize * sizeof(t_int));
}
buf = x->buffer;
! while (n--){
*buf++ = atom_getfloat(atombuf++);
+ x->indices[n] = n;
+ }
}
***************
*** 69,72 ****
--- 77,81 ----
t_atom *atombuf = (t_atom *)getbytes(sizeof(t_atom) * argc);
t_float *buf;
+ t_int *idx;
int i, loops = 1;
***************
*** 74,77 ****
--- 83,87 ----
sort_buffer(x, argc, argv);
buf = x->buffer;
+ idx = x->indices;
while (step > 1) {
***************
*** 85,91 ****
for (n=0; n<(argc-step); n++) {
if (buf[n] > buf[n+step]) {
! t_float dummy = buf[n];
buf[n] = buf[n+step];
! buf[n+step] = dummy;
}
}
--- 95,104 ----
for (n=0; n<(argc-step); n++) {
if (buf[n] > buf[n+step]) {
! t_int i_tmp = idx[n];
! t_float f_tmp = buf[n];
buf[n] = buf[n+step];
! buf[n+step] = f_tmp;
! idx[n] = idx[n+step];
! idx[n+step] = i_tmp;
}
}
***************
*** 94,102 ****
if (x->ascending)
for (n = 0; n < argc; n++) SETFLOAT(&atombuf[n], buf[n]);
else
for (n = 0, i=argc-1; n < argc; n++, i--) SETFLOAT(&atombuf[n], buf[i]);
- outlet_list(x->x_obj.ob_outlet, &s_list, n, atombuf);
freebytes(atombuf, argc*sizeof(t_atom));
--- 107,122 ----
if (x->ascending)
+ for (n = 0; n < argc; n++) SETFLOAT(&atombuf[n], idx[n]);
+ else
+ for (n = 0, i=argc-1; n < argc; n++, i--) SETFLOAT(&atombuf[n], idx[i]);
+
+ outlet_list(x->indexOut , &s_list, n, atombuf);
+
+ if (x->ascending)
for (n = 0; n < argc; n++) SETFLOAT(&atombuf[n], buf[n]);
else
for (n = 0, i=argc-1; n < argc; n++, i--) SETFLOAT(&atombuf[n], buf[i]);
+ outlet_list(x->sortedOut, &s_list, n, atombuf);
freebytes(atombuf, argc*sizeof(t_atom));
***************
*** 108,112 ****
x->ascending = (f < 0.f)?0:1;
! outlet_new(&x->x_obj, &s_list);
x->bufsize = 0;
--- 128,133 ----
x->ascending = (f < 0.f)?0:1;
! x->sortedOut=outlet_new(&x->x_obj, &s_list);
! x->indexOut=outlet_new(&x->x_obj, &s_list);
x->bufsize = 0;