diff options
-rw-r--r-- | shmem.c | 76 |
1 files changed, 43 insertions, 33 deletions
@@ -20,48 +20,58 @@ static inline t_float min(t_float x1,t_float x2) } } -void shmem_set(t_shmem *x, t_symbol *unused, int argc, t_atom *argv) +int shmem_set_tab(t_shmem *x, t_symbol *table, int src_offset, int dest_offset) { - - t_garray *a; - int npoints; - int array_offset; + int npoints, i, index_max; + t_garray *a; t_word *vec; - int i, index_max, shmem_offset; - if ((argc <= 1) || (argv[0].a_type != A_FLOAT) ){ - pd_error(x, "shmem usage : [memset offset data [offset_data]( (data can be a float, a list, or a table name)"); + i=0; + t_symbol *s = table; + if (!(a = (t_garray *)pd_findbyclass(s, garray_class))) + pd_error(x, "%s: no such array", s->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabread", s->s_name); + else { + index_max = min(x->segment_size-dest_offset, npoints-src_offset); + for (i=0; i < index_max; i++) + x->share_memory[i+dest_offset] = vec[i+src_offset].w_float; + } + post("copiƩ=%d", i); + return(i); +} + +void shmem_set(t_shmem *x, t_symbol *unused, int argc, t_atom *argv) +{ + int i, j, index_max, shmem_offset, array_offset; + + if (argc <= 1) { + pd_error(x, "shmem usage : [memset table_name [table_name []]< or [memset src_offset data [dest_offset]< (data can be a float, a list, or a table name)"); return; } - shmem_offset = atom_getfloatarg(0,argc,argv); - if (shmem_offset < 0) shmem_offset=0; - - if (argv[1].a_type == A_SYMBOL) { // argument is an arrayname - t_symbol *s = atom_getsymbolarg(1,argc,argv); - if (!(a = (t_garray *)pd_findbyclass(s, garray_class))) - pd_error(x, "%s: no such array", s->s_name); - else if (!garray_getfloatwords(a, &npoints, &vec)) - pd_error(x, "%s: bad template for tabread", s->s_name); - else { - if (argc == 2) { // memset index_mem arrayname - index_max = min(x->segment_size-shmem_offset,npoints); - // post("i=%d", index_max); - for (i=0; i<index_max; i++) - x->share_memory[i+shmem_offset] = vec[i].w_float; - } - else if (argc == 3) { // memset index_mem arrayname array_offset + if (argv[0].a_type == A_SYMBOL) { + i = 0; + j = 0; + while (argv[i].a_type == A_SYMBOL) { + j += shmem_set_tab(x, atom_getsymbolarg(i,argc,argv), 0, j); + } + } + else if ((argc > 1) && (argv[0].a_type == A_FLOAT) ) { + shmem_offset = atom_getfloatarg(0,argc,argv); + if (shmem_offset < 0) shmem_offset=0; + + if (argv[1].a_type == A_SYMBOL) { // argument is an arrayname + array_offset = 0; + if ((argc > 2) && (argv[2].a_type == A_FLOAT)) array_offset = atom_getfloatarg(2,argc,argv); - index_max = min(x->segment_size-shmem_offset,npoints-array_offset); - //post("i=%d", x->segment_size-shmem_offset); - //post("i=%d", npoints); - //post("i=%d", index_max); - for (i=0; i<index_max; i++) - x->share_memory[i+shmem_offset] = vec[i+array_offset].w_float; - } + if (array_offset < 0) array_offset=0; + + shmem_set_tab(x, atom_getsymbolarg(1,argc,argv), array_offset, shmem_offset); } } - else if (argv[1].a_type == A_FLOAT) { // argument is a float + else if ((argc > 1) && (argv[1].a_type == A_FLOAT)) { // argument is a float + shmem_offset = atom_getfloatarg(0,argc,argv); index_max = x->segment_size - shmem_offset; if (index_max > argc-1) index_max = argc-1; for (i=0; i<index_max ; i++) |