Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2234
Modified Files:
Tag: devel_0_37
d_soundfile.c
Log Message:
added const command to soundfiler to work in the backgroud
Index: d_soundfile.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/d_soundfile.c,v
retrieving revision 1.1.1.2.2.7
retrieving revision 1.1.1.2.2.8
diff -C2 -d -r1.1.1.2.2.7 -r1.1.1.2.2.8
*** d_soundfile.c 31 May 2004 12:02:21 -0000 1.1.1.2.2.7
--- d_soundfile.c 3 Jun 2004 08:02:14 -0000 1.1.1.2.2.8
***************
*** 1584,1594 ****
! int was, elemsize; /* array contains was elements of size elemsize */
! t_float * vec = (t_float*) x->x_array.a_vec; /* old array */
t_glist *gl;
int dspwas;
! int n; /* resize of n elements */
! char *nvec; /* new array */
!
if ((argv+1)->a_type == A_FLOAT)
{
--- 1584,1597 ----
! int was, elemsize; /* array contains was elements of size elemsize */
! t_float * vec; /* old array */
t_glist *gl;
int dspwas;
! int n; /* resize of n elements */
! char *nvec; /* new array */
!
! vec = (t_float*) x->x_array.a_vec;
! was = x->x_array.a_vec;
!
if ((argv+1)->a_type == A_FLOAT)
{
***************
*** 1600,1605 ****
}
- garray_getfloatarray(x, &was, &vec);
-
if (n == was)
{
--- 1603,1606 ----
***************
*** 1677,1680 ****
--- 1678,1786 ----
+ static void soundfiler_t_const(t_soundfiler *x, t_symbol *s,
+ int argc, t_atom *argv);
+
+ static void soundfiler_t_const_addq(t_soundfiler *x, t_symbol *s,
+ int argc, t_atom *argv)
+ {
+ soundfiler_queue_add(soundfiler_t_const,(void *)x,argc, argv);
+ }
+
+
+ /* TB: soundfiler_t_const ...
+ usage: const table value
+ */
+ static void soundfiler_t_const(t_soundfiler *y, t_symbol *s,
+ int argc, t_atom *argv)
+ {
+
+ t_garray * x = (t_garray *)pd_findbyclass(argv[0].a_w.w_symbol, garray_class);
+
+ if (!(x))
+ {
+ pd_error(y, "%s: no such table", argv[0].a_w.w_symbol->s_name);
+ goto usage;
+ }
+
+
+ int size, elemsize; /* array contains was elements of size elemsize */
+ t_float * vec; /* old array */
+ t_glist *gl;
+ int dspwas;
+ int val; /* value */
+ char *nvec; /* new array */
+
+ vec = (t_float*) x->x_array.a_vec;
+ size = x->x_array.a_n;
+
+ if ((argv+1)->a_type == A_FLOAT)
+ {
+ val = (int) (argv+1)->a_w.w_float;
+ }
+ else
+ {
+ goto usage;
+ }
+
+ elemsize = template_findbyname(x->x_array.a_templatesym)->t_n * sizeof(t_word);
+
+
+ /* allocating memory */
+ #ifdef _POSIX_MEMLOCK
+ munlockall();
+ #endif
+ nvec = getbytes(size * elemsize);
+ #ifdef _POSIX_MEMLOCK
+ mlockall(MCL_FUTURE);
+ #endif
+
+ if (!nvec)
+ {
+ pd_error(x, "array resize failed: out of memory");
+ return;
+ }
+
+ /* setting array */
+ int i;
+ for (i=0; i!=size; ++i)
+ {
+ nvec[i]=val;
+ }
+
+
+ /* TB: we'll have to be sure that no one is accessing the array */
+ sys_lock();
+ #ifdef GARRAY_THREAD_LOCK
+ garray_lock(x);
+ #endif
+ x->x_array.a_vec = nvec;
+ #ifdef GARRAY_THREAD_LOCK
+ garray_unlock(x);
+ #endif
+ if (x->x_usedindsp) canvas_update_dsp();
+ sys_unlock();
+
+
+ /* if this is the only array in the graph,
+ reset the graph's coordinates */
+ gl = x->x_glist;
+ if (gl->gl_list == &x->x_gobj && !x->x_gobj.g_next)
+ {
+ vmess(&gl->gl_pd, gensym("bounds"), "ffff",
+ 0., gl->gl_y1, (double)(size > 1 ? size-1 : 1), gl->gl_y2);
+ /* close any dialogs that might have the wrong info now... */
+ gfxstub_deleteforkey(gl);
+ }
+ else garray_redraw(x);
+
+ freebytes (vec, size * elemsize);
+ outlet_float(y->x_obj.ob_outlet, size);
+ return;
+
+ usage:
+ pd_error(x, "usage: const tablename value");
+ }
+
+
#endif /* THREADED_SF */
***************
*** 2032,2035 ****
--- 2138,2143 ----
class_addmethod(soundfiler_class, (t_method)soundfiler_t_resize_addq,
gensym("resize"), A_GIMME, 0);
+ class_addmethod(soundfiler_class, (t_method)soundfiler_t_const_addq,
+ gensym("const"), A_GIMME, 0);
#else
class_addmethod(soundfiler_class, (t_method)soundfiler_read, gensym("read"),