From bcd306745a6bc273ab9ac188af1b99b2c83fd3c5 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Fri, 2 Nov 2012 08:18:53 +0000 Subject: share_mem : expanding syntax of [memdump( svn path=/trunk/externals/share_mem/; revision=16517 --- shmem-help.pd | 24 ++++++++++++++---------- shmem.c | 34 ++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/shmem-help.pd b/shmem-help.pd index a6dac85..d8d3572 100644 --- a/shmem-help.pd +++ b/shmem-help.pd @@ -1,4 +1,4 @@ -#N canvas 122 50 1009 468 10; +#N canvas 122 50 1064 468 10; #N canvas 1 89 450 300 (subpatch) 0; #X array array2 100 float 3; #A 0 -0.857141 -0.799998 -0.72857 -0.657141 -0.585713 -0.542856 -0.499999 @@ -57,11 +57,10 @@ the exisiting segment.; #X obj 568 371 shmem 1214 250; #X text 655 343 read one float of the table send value to the outlet ; -#X msg 568 292 memdump 0 array2; -#X text 21 192 WRINTING INTO MEMORY; -#X text 567 254 READING MEMORY; +#X msg 568 252 memdump 0 array2; +#X text 567 214 READING MEMORY; #X floatatom 568 395 5 0 0 0 - - -; -#X text 688 292 dump shared memory from index 0 to array2; +#X text 688 252 dump shared memory from index 0 to array2; #X text 21 146 Work only on Linux / and Unix.; #X text 132 421 2nd argument : size of the segment (number of float) ; @@ -70,12 +69,17 @@ the exisiting segment.; #X text 139 367 reset memory to 0; #X text 475 168 array1 and array 2 are size 100; #X msg 69 318 memset 50 5 5 5 1 1 0.1 0.2 0.3 0.4 0.5 0.6 0.7; +#X text 21 192 WRITING INTO MEMORY; +#X msg 588 282 memdump 0 array2 50; +#X text 708 282 dump shared memory from index 0 to array2 from index +50; #X connect 1 0 8 0; #X connect 3 0 8 0; #X connect 6 0 8 0; -#X connect 13 0 23 0; -#X connect 14 0 19 0; +#X connect 13 0 22 0; +#X connect 14 0 18 0; #X connect 16 0 14 0; -#X connect 23 0 14 0; -#X connect 24 0 8 0; -#X connect 27 0 8 0; +#X connect 22 0 14 0; +#X connect 23 0 8 0; +#X connect 26 0 8 0; +#X connect 28 0 14 0; diff --git a/shmem.c b/shmem.c index f3e1bc2..53dd11c 100644 --- a/shmem.c +++ b/shmem.c @@ -30,11 +30,11 @@ void shmem_set(t_shmem *x, t_symbol *unused, int argc, t_atom *argv) int i, index_max, shmem_offset; if (argc <= 1) { - pd_error(x, "shmem usage : memset offset data (data can be a float, a list, or a table name)"); + pd_error(x, "shmem usage : [memset offset data [offset_data]( (data can be a float, a list, or a table name)"); return; } if (argv[0].a_type != A_FLOAT) { - pd_error(x, "shmem usage : memset offset data (data can be a float, a list, or a table name)"); + pd_error(x, "shmem usage : [memset offset data [offset_data]( (data can be a float, a list, or a table name)"); return; } @@ -75,16 +75,16 @@ void shmem_set(t_shmem *x, t_symbol *unused, int argc, t_atom *argv) void shmem_dump(t_shmem *x, t_symbol *unused, int argc, t_atom *argv) { - int i, vecsize, index_max, shmem_offset; + int i, vecsize, index_max, shmem_offset, dest_offset; t_garray *a; t_word *vec; - if (argc == 0) { - pd_error(x, "shmem usage : memdump offset dest (dest can be nothing (outlet), or a table name)"); + if (argc < 2) { + pd_error(x, "shmem usage : [memdump offset dest [offset_dest]( "); return; } if (argv[0].a_type != A_FLOAT) { - pd_error(x, "shmem usage : memdump offset dest (dest can be nothing (outlet), or a table name)"); + pd_error(x, "shmem usage : [memdump offset dest [offset_dest]( "); return; } shmem_offset = atom_getfloatarg(0,argc,argv); @@ -92,26 +92,36 @@ void shmem_dump(t_shmem *x, t_symbol *unused, int argc, t_atom *argv) if (shmem_offset > x->segment_size-1) i = x->segment_size-1; // post("i=%d", offset); - if (argc == 1) - outlet_float(x->x_obj.ob_outlet, x->share_memory[shmem_offset]); - else if (argv[1].a_type == A_SYMBOL) { // argument is an arrayname + if (argv[1].a_type == A_SYMBOL) { // [memdump offset dest 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, &vecsize, &vec)) + else if (!garray_getfloatwords(a, &vecsize, &vec)) pd_error(x, "%s: bad template for tabwrite", s->s_name); - else { + else { + if (argc == 2) { index_max = x->segment_size-shmem_offset; if (index_max > vecsize) index_max = vecsize; // post("i=%d", index_max); for (i=0; ishare_memory[i+shmem_offset]; + } + else if (argc == 3) { + dest_offset = atom_getfloatarg(2,argc,argv); + index_max = min(x->segment_size-shmem_offset,vecsize-dest_offset); + // post("i=%d", index_max); + for (i=0; ishare_memory[i+shmem_offset]; } garray_redraw(a); } } + else { + pd_error(x, "shmem usage : [memdump offset dest [offset_dest]( "); + return; + } + } void shmem_read(t_shmem *x, t_float index) -- cgit v1.2.1