From de6aef19694a14a0b5dce0ea6ab9be54ab4d1239 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Thu, 1 Nov 2012 11:28:48 +0000 Subject: shmem : adding memread message svn path=/trunk/externals/share_mem/; revision=16505 --- shmem-help.pd | 38 +++++++++++++++++++------------------- shmem.c | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/shmem-help.pd b/shmem-help.pd index 34f2101..a48e6aa 100644 --- a/shmem-help.pd +++ b/shmem-help.pd @@ -1,20 +1,20 @@ #N canvas 122 50 1009 468 10; #N canvas 1 89 450 300 (subpatch) 0; #X array array2 100 float 3; -#A 0 0.257142 0.285713 0.314285 0.357142 0.371428 0.385714 0.4 0.414285 -0.428571 0.442857 0.457143 0.457143 0.471429 0.485714 0.5 0.514286 -0.514286 0.528572 0.542858 0.557143 0.557143 0.557143 0.571429 0.571429 -0.585715 0.585715 0.585715 0.585715 0.585715 0.585715 0.585715 0.585715 -0.557143 0.557143 0.542858 0.528572 0.514286 0.5 0.485714 0.485714 -0.457143 0.457143 0.442857 0.414285 0.4 0.385714 0.371428 0.357142 -0.328571 0.328571 0.314285 0.285713 0.257142 0.242856 0.22857 0.214284 -0.185713 0.171427 0.157141 0.142855 0.114284 0.0999978 0.0714262 0.0428545 -0.0428545 0.0142829 -0.0142887 -0.0285745 -0.0571461 -0.0857177 -0.100003 --0.128575 -0.171432 -0.171432 -0.21429 -0.242862 -0.257147 -0.300005 --0.314291 -0.328576 -0.357148 -0.371434 -0.38572 -0.400005 -0.428577 --0.442863 -0.471434 -0.471434 -0.514292 -0.528578 -0.542863 -0.557149 --0.571435 -0.600007 -0.614292 -0.628578 -0.628578 -0.628578 -0.642864 --0.642864; +#A 0 -0.692856 -0.614285 -0.535714 -0.464285 -0.392857 -0.321428 -0.264286 +-0.207143 -0.15 -0.0785718 -0.00714337 0.0309518 0.0690469 0.164285 +0.207142 0.22857 0.249999 0.307142 0.32857 0.349999 0.385713 0.421427 +0.449998 0.464284 0.492856 0.521427 0.535713 0.557141 0.57857 0.592855 +0.607141 0.635712 0.635712 0.649998 0.657141 0.664284 0.692855 0.699998 +0.707141 0.721426 0.721426 0.721426 0.728569 0.735712 0.749998 0.749998 +0.749998 0.749998 0.749998 0.749998 0.749998 0.749998 0.749998 0.735712 +0.735712 0.721426 0.707141 0.692855 0.685712 0.678569 0.671427 0.664284 +0.649998 0.635712 0.614284 0.592855 0.564284 0.535713 0.521427 0.507141 +0.485713 0.464284 0.449998 0.435713 0.37857 0.349999 0.321427 0.299999 +0.235713 0.207142 0.149999 0.121428 0.0928564 0.0357137 -0.00714338 +-0.0357147 -0.0642861 -0.107143 -0.135715 -0.164286 -0.192857 -0.25 +-0.307143 -0.364285 -0.407143 -0.464285 -0.535714 -0.607142 -0.735713 +-0.992856; #X coords 0 1 99 -1 200 140 1; #X restore 680 26 graph; #X msg 53 288 memset 0 1 1 1 1 1; @@ -54,7 +54,6 @@ is identified by its Id.; #X text 21 95 When you create a shmem object \, it checks its Id. If the id is not used \, it allows a new segment \, otherwise it address the exisiting segment.; -#X msg 584 343 memdump \$1; #X floatatom 584 318 5 0 0 0 - - -; #X obj 568 371 shmem 1214 250; #X text 655 343 read one float of the table send value to the outlet @@ -67,11 +66,12 @@ the exisiting segment.; #X text 21 146 Work only on Linux / and Unix.; #X text 132 391 2nd argument : size of the segment (number of float) ; +#X msg 584 343 memread \$1; #X connect 1 0 9 0; #X connect 3 0 9 0; #X connect 5 0 9 0; #X connect 7 0 9 0; -#X connect 14 0 16 0; -#X connect 15 0 14 0; -#X connect 16 0 21 0; -#X connect 18 0 16 0; +#X connect 14 0 24 0; +#X connect 15 0 20 0; +#X connect 17 0 15 0; +#X connect 24 0 15 0; diff --git a/shmem.c b/shmem.c index 404d795..f3e1bc2 100644 --- a/shmem.c +++ b/shmem.c @@ -114,6 +114,19 @@ void shmem_dump(t_shmem *x, t_symbol *unused, int argc, t_atom *argv) } } +void shmem_read(t_shmem *x, t_float index) +{ + int i, vecsize, index_max, shmem_offset; + t_garray *a; + t_word *vec; + + shmem_offset = index; + if (shmem_offset < 0) shmem_offset = 0; + if (shmem_offset > x->segment_size-1) i = x->segment_size-1; + // post("i=%d", offset); + outlet_float(x->x_obj.ob_outlet, x->share_memory[shmem_offset]); +} + t_class *shmem_class; void *shmem_new( t_floatarg id, t_floatarg size) @@ -167,5 +180,6 @@ void shmem_setup(void) class_addmethod(shmem_class, (t_method)shmem_set, gensym("memset"), A_GIMME, 0); class_addmethod(shmem_class, (t_method)shmem_dump, gensym("memdump"), A_GIMME, 0); class_addmethod(shmem_class, (t_method)shmem_clear, gensym("memclear"), 0); + class_addmethod(shmem_class, (t_method)shmem_read, gensym("memread"),A_DEFFLOAT, 0); } -- cgit v1.2.1