Update of /cvsroot/pure-data/externals/grill/py/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7326/source
Modified Files: pybuffer.cpp pydsp.cpp Log Message: fixes for maxmsp added generic numpy support (not working)
Index: pydsp.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pydsp.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pydsp.cpp 14 Mar 2005 04:58:13 -0000 1.2 --- pydsp.cpp 25 Mar 2005 04:54:17 -0000 1.3 *************** *** 64,68 **** }
! PyObject *NAFromBuffer(PyObject *buf,int c,int n);
void pydsp::NewBuffers() --- 64,68 ---- }
! PyObject *arrayfrombuffer(PyObject *buf,int c,int n);
void pydsp::NewBuffers() *************** *** 83,87 **** Py_XDECREF(buffers[i]); PyObject *b = PyBuffer_FromReadWriteMemory(insigs[i],n*sizeof(t_sample)); ! buffers[i] = NAFromBuffer(b,1,n); Py_DECREF(b); } --- 83,87 ---- Py_XDECREF(buffers[i]); PyObject *b = PyBuffer_FromReadWriteMemory(insigs[i],n*sizeof(t_sample)); ! buffers[i] = arrayfrombuffer(b,1,n); Py_DECREF(b); } *************** *** 95,99 **** else { PyObject *b = PyBuffer_FromReadWriteMemory(outsigs[i],n*sizeof(t_sample)); ! buffers[ins+i] = NAFromBuffer(b,1,n); Py_DECREF(b); } --- 95,99 ---- else { PyObject *b = PyBuffer_FromReadWriteMemory(outsigs[i],n*sizeof(t_sample)); ! buffers[ins+i] = arrayfrombuffer(b,1,n); Py_DECREF(b); }
Index: pybuffer.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pybuffer.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pybuffer.cpp 14 Mar 2005 04:58:13 -0000 1.4 --- pybuffer.cpp 25 Mar 2005 04:54:16 -0000 1.5 *************** *** 11,24 **** #include "main.h"
! #ifdef PY_NUMARRAY ! #if FLEXT_OS == FLEXT_OS_MAC ! #include <Python/numarray/numarray.h> #else ! #include <numarray/numarray.h> #endif - static bool nasupport = false; - static NumarrayType numtype; #endif
// PD defines a T_OBJECT symbol #undef T_OBJECT --- 11,58 ---- #include "main.h"
! #undef PY_ARRAYS ! ! ! #if defined(PY_NUMERIC) ! #define PY_ARRAYS 1 ! ! #if FLEXT_OS == FLEXT_OS_MAC ! #include <Python/Numeric/arrayobject.h> ! #else ! #include <Numeric/arrayobject.h> ! #endif ! #elif defined(PY_NUMARRAY) ! #define PY_ARRAYS 1 ! #define NA ! ! #ifdef NA ! #if FLEXT_OS == FLEXT_OS_MAC ! #include <Python/numarray/numarray.h> ! #else ! #include <numarray/numarray.h> ! #endif #else ! #if FLEXT_OS == FLEXT_OS_MAC ! #include <Python/numarray/arrayobject.h> ! #else ! #include <numarray/arrayobject.h> ! #endif #endif #endif
+ + #ifdef PY_ARRAYS + + #ifdef NA + static NumarrayType numtype = tAny; + inline bool arrsupport() { return numtype != tAny; } + #else + static PyArray_TYPES numtype = PyArray_NOTYPE; + inline bool arrsupport() { return numtype != PyArray_NOTYPE; } + #endif + + #endif + + // PD defines a T_OBJECT symbol #undef T_OBJECT *************** *** 189,201 **** }
! PyObject *NAFromBuffer(PyObject *buf,int c,int n) { ! #ifdef PY_NUMARRAY ! if(nasupport) { ! maybelong shape[2]; shape[0] = n; shape[1] = c; ! PyArrayObject *na = NA_NewAllFromBuffer(c == 1?1:2,shape,numtype,buf,0,0,NA_ByteOrder(),1,1); ! return (PyObject *)na; } else --- 223,251 ---- }
! PyObject *arrayfrombuffer(PyObject *buf,int c,int n) { ! #ifdef PY_ARRAYS ! if(arrsupport()) { ! PyObject *arr; ! int shape[2]; shape[0] = n; shape[1] = c; ! #ifdef NA ! arr = (PyObject *)NA_NewAllFromBuffer(c == 1?1:2,shape,numtype,buf,0,0,NA_ByteOrder(),1,1); ! #else ! void *data; ! int len; ! int err = PyObject_AsWriteBuffer(buf,&data,&len); ! if(!err) { ! FLEXT_ASSERT(len <= n*c*sizeof(t_sample)); ! Py_INCREF(buf); ! arr = PyArray_FromDimsAndData(c == 1?1:2,shape,numtype,(char *)data); ! } ! else { ! // exception string is already set ! arr = NULL; ! } ! #endif ! return arr; } else *************** *** 207,212 **** { PyObject *ret; ! #ifdef PY_NUMARRAY ! if(nasupport) { if(self->buf) { const int n = self->buf->Frames(); --- 257,262 ---- { PyObject *ret; ! #ifdef PY_ARRAYS ! if(arrsupport()) { if(self->buf) { const int n = self->buf->Frames(); *************** *** 217,221 **** if(ihigh > n) ihigh = n;
! PyObject *nobj = NAFromBuffer((PyObject *)self,c,n); if(ilow != 0 || ihigh != n) { ret = PySequence_GetSlice(nobj,ilow,ihigh); --- 267,271 ---- if(ihigh > n) ihigh = n;
! PyObject *nobj = arrayfrombuffer((PyObject *)self,c,n); if(ilow != 0 || ihigh != n) { ret = PySequence_GetSlice(nobj,ilow,ihigh); *************** *** 272,277 **** { int ret; ! #ifdef PY_NUMARRAY ! if(nasupport) { if(!value) { PyErr_SetString(PyExc_TypeError,"Object doesn't support item deletion"); --- 322,327 ---- { int ret; ! #ifdef PY_ARRAYS ! if(arrsupport()) { if(!value) { PyErr_SetString(PyExc_TypeError,"Object doesn't support item deletion"); *************** *** 286,290 **** --- 336,344 ---- if(ihigh > n) ihigh = n;
+ #ifdef NA PyArrayObject *out = NA_InputArray(value,numtype,NUM_C_ARRAY); + #else + PyArrayObject *out = (PyArrayObject *)PyArray_ContiguousFromObject(value,numtype,0,0); + #endif if(!out) { PyErr_SetString(PyExc_TypeError,"Assigned object must be a numarray"); *************** *** 298,302 **** --- 352,360 ---- int dlen = ihigh-ilow; int slen = out->dimensions[0]; + #ifdef NA flext::CopySamples(self->buf->Data()+ilow,(t_sample *)NA_OFFSETDATA(out),slen < dlen?slen:dlen); + #else + flext::CopySamples(self->buf->Data()+ilow,(t_sample *)out->data,slen < dlen?slen:dlen); + #endif self->dirty = true; ret = 0; *************** *** 675,681 **** void initsamplebuffer() { - #ifdef PY_NUMARRAY PyErr_Clear(); import_libnumarray(); if(PyErr_Occurred()) // catch import error --- 733,744 ---- void initsamplebuffer() { PyErr_Clear(); + + #ifdef PY_ARRAYS + #ifdef NA import_libnumarray(); + #else + import_array(); + #endif if(PyErr_Occurred()) // catch import error *************** *** 683,692 **** else { // numarray support ok ! nasupport = true; post(""); ! post("Numarray support enabled"); } - - numtype = sizeof(t_sample) == 4?tFloat32:tFloat64; #endif
--- 746,757 ---- else { // numarray support ok ! #ifdef NA ! numtype = sizeof(t_sample) == 4?tFloat32:tFloat64; ! #else ! numtype = sizeof(t_sample) == 4?PyArray_FLOAT:PyArray_DOUBLE; ! #endif post(""); ! post("Python array support enabled"); } #endif
*************** *** 696,698 **** Py_INCREF(&pySamplebuffer_Type); } - --- 761,762 ----