From 21859fabaa92215068d7176e504ac0d59d4301a5 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Sat, 19 Nov 2005 23:14:18 +0000 Subject: added Buffer.resize example add Buffer.resize method svn path=/trunk/; revision=3980 --- externals/grill/py/pd/buffer-1.pd | 10 ++++----- externals/grill/py/pd/buffer-2.pd | 37 ++++++++++++++++++++++++++++++++++ externals/grill/py/readme.txt | 1 + externals/grill/py/source/pybuffer.cpp | 21 +++++++++++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 externals/grill/py/pd/buffer-2.pd (limited to 'externals/grill/py') diff --git a/externals/grill/py/pd/buffer-1.pd b/externals/grill/py/pd/buffer-1.pd index ca799385..0314d3fe 100644 --- a/externals/grill/py/pd/buffer-1.pd +++ b/externals/grill/py/pd/buffer-1.pd @@ -1,4 +1,4 @@ -#N canvas 123 58 712 492 12; +#N canvas 123 58 716 496 12; #X obj 37 240 print; #X obj 107 241 print A; #X msg 30 139 reload; @@ -42,16 +42,16 @@ #X coords 0 1 99 -1 200 140 1; #X restore 65 301 graph; #X obj 36 199 py buffer @detach 1; -#X msg 192 127 mul array3 array1 array2; -#X msg 192 149 add array3 array1 array2; +#X msg 200 123 mul array3 array1 array2; +#X msg 200 145 add array3 array1 array2; #X obj 16 13 cnv 15 650 40 empty empty py/pyext 10 22 0 24 -260818 -1 0; #X text 235 16 Python script objects \, (C)2003-2005 Thomas Grill; #X text 235 32 http://grrrr.org/ext; #X text 17 67 This demonstrates the usage of buffers. See the buffer.py script.; -#X msg 193 176 fadein array1; -#X msg 191 200 neg array2; +#X msg 201 172 fadein array1; +#X msg 199 196 neg array2; #X connect 2 0 6 0; #X connect 6 0 0 0; #X connect 6 1 1 0; diff --git a/externals/grill/py/pd/buffer-2.pd b/externals/grill/py/pd/buffer-2.pd new file mode 100644 index 00000000..fe066805 --- /dev/null +++ b/externals/grill/py/pd/buffer-2.pd @@ -0,0 +1,37 @@ +#N canvas 608 159 694 442 12; +#X obj 16 13 cnv 15 650 40 empty empty py/pyext 10 22 0 24 -260818 +-1 0; +#X text 235 16 Python script objects \, (C)2003-2005 Thomas Grill; +#X text 235 32 http://grrrr.org/ext; +#X text 17 67 This demonstrates how to resize buffers; +#N canvas 0 0 450 300 graph1 0; +#X array array1 42 float 3; +#A 0 0 0 0 0 0.0285715 0.0857145 0.128572 0.171429 0.257144 0.314287 +0.385715 0.385715 0.385715 0.385715 0.385715 0.37143 0.342858 0.314287 +0.228572 0.128572 0.0428573 -0.0857145 -0.200001 -0.285715 -0.328572 +-0.357144 -0.400001 -0.428573 -0.428573 -0.457144 -0.457144 -0.457144 +-0.457144 -0.457144 -0.457144 -0.457144 -0.457144 -0.457144 -0.414287 +-0.342858 -0.314287 1.02445e-007; +#X coords 0 1 42 -1 200 140 1; +#X restore 413 259 graph; +#X msg 40 148 symbol array1; +#X obj 40 194 py pyext.Buffer @py 1; +#X obj 143 238 nbx 5 14 0 100 0 1 empty empty empty 0 -6 0 10 -260818 +-1 -1 42 256; +#X obj 143 260 t b f; +#X obj 39 287 pym 2 resize @py 1; +#X obj 40 120 loadbang; +#X text 37 310 returns buffer object; +#X obj 41 361 py .len; +#X text 111 361 call __builtin__.len; +#X text 222 192 create Buffer object; +#X obj 41 394 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0 +10 -261681 -1 -1 0 256; +#X connect 5 0 6 1; +#X connect 6 0 9 1; +#X connect 7 0 8 0; +#X connect 8 0 9 0; +#X connect 8 1 9 2; +#X connect 9 0 12 1; +#X connect 10 0 5 0; +#X connect 12 0 15 0; diff --git a/externals/grill/py/readme.txt b/externals/grill/py/readme.txt index 805b1d35..5ca1876e 100644 --- a/externals/grill/py/readme.txt +++ b/externals/grill/py/readme.txt @@ -113,6 +113,7 @@ Version history: - FIX: more safety for calls where association python-pd has already been removed - ADD: __str__ method for pyext, to enable print self calls - ADD: enable symbol binding for all callables (not only functions and methods) +- ADD: Buffer.resize(frames,keep=1,zero=1) method 0.2.0: - ADD: handling of Python threads diff --git a/externals/grill/py/source/pybuffer.cpp b/externals/grill/py/source/pybuffer.cpp index 13d428c4..afc35e45 100644 --- a/externals/grill/py/source/pybuffer.cpp +++ b/externals/grill/py/source/pybuffer.cpp @@ -156,8 +156,29 @@ static PyObject *buffer_dirty(PyObject *obj) return Py_None; } +static PyObject *buffer_resize(PyObject *obj,PyObject *args,PyObject *kwds) +{ + flext::buffer *b = ((pySamplebuffer *)obj)->buf; + if(b) { + int frames,keep = 1,zero = 1; + static char *kwlist[] = {"frames", "keep", "zero", NULL}; + if(!PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwlist, &frames, &keep, &zero)) + return NULL; + + b->Frames(frames,keep != 0,zero != 0); + + Py_INCREF(obj); + return obj; + } + else { + PyErr_SetString(PyExc_RuntimeError,"Invalid buffer"); + return NULL; + } +} + static PyMethodDef buffer_methods[] = { {"dirty", (PyCFunction)buffer_dirty,METH_NOARGS,"Mark buffer as dirty"}, + {"resize", (PyCFunction)buffer_resize,METH_VARARGS|METH_KEYWORDS,"Resize buffer"}, {NULL} /* Sentinel */ }; -- cgit v1.2.1