diff options
Diffstat (limited to 'externals')
-rwxr-xr-x | externals/grill/py/maxmsp/py-objectmappings.txt | 6 | ||||
-rw-r--r-- | externals/grill/py/py.vcproj | 10 | ||||
-rw-r--r-- | externals/grill/py/readme.txt | 15 | ||||
-rw-r--r-- | externals/grill/py/scripts/buffer.py | 16 | ||||
-rw-r--r-- | externals/grill/py/scripts/sig.py | 4 | ||||
-rw-r--r-- | externals/grill/py/source/pybuffer.cpp | 110 | ||||
-rw-r--r-- | externals/grill/py/source/pydsp.cpp | 6 |
7 files changed, 125 insertions, 42 deletions
diff --git a/externals/grill/py/maxmsp/py-objectmappings.txt b/externals/grill/py/maxmsp/py-objectmappings.txt index e7616537..70b84768 100755 --- a/externals/grill/py/maxmsp/py-objectmappings.txt +++ b/externals/grill/py/maxmsp/py-objectmappings.txt @@ -4,8 +4,14 @@ max objectfile pyext py; max objectfile pyext. py;
max objectfile pyx py;
max objectfile pyx. py;
+max objectfile pyext~ py;
+max objectfile pyext.~ py;
+max objectfile pyx~ py;
+max objectfile pyx.~ py;
max oblist python py;
max oblist python py.;
max oblist python pyext;
max oblist python pyext.;
+max oblist python pyext~;
+max oblist python pyext.~;
diff --git a/externals/grill/py/py.vcproj b/externals/grill/py/py.vcproj index 328c89f0..50663729 100644 --- a/externals/grill/py/py.vcproj +++ b/externals/grill/py/py.vcproj @@ -85,7 +85,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories=""c:\data\prog\pd\pd-cvs\src";..\flext\source;c:\programme\prog\Python24\include" + AdditionalIncludeDirectories=""c:\data\pd\pd-cvs\src";..\flext\source;c:\programme\prog\Python24\include" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PY_EXPORTS;FLEXT_SYS=2;FLEXT_THREADS;PY_NUMARRAY" BasicRuntimeChecks="3" RuntimeLibrary="1" @@ -506,9 +506,7 @@ TypeLibraryName=".\pd-msvc\td/py.tlb" HeaderFileName=""/> <Tool - Name="VCPostBuildEventTool" - Description="copy" - CommandLine="copy $(outdir)\py.mxe "C:\Programme\Gemeinsame Dateien\Cycling '74\externals""/> + Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool @@ -530,8 +528,8 @@ </Configuration> <Configuration Name="Max Threaded Release|Win32" - OutputDirectory="$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" + OutputDirectory=".\max-msvc\tr" + IntermediateDirectory=".\max-msvc\tr" ConfigurationType="2" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="FALSE" diff --git a/externals/grill/py/readme.txt b/externals/grill/py/readme.txt index 671be6cf..45248f34 100644 --- a/externals/grill/py/readme.txt +++ b/externals/grill/py/readme.txt @@ -34,6 +34,21 @@ From a shell run bash ../flext/build.sh (you would have to substitute ../flext with the respective path to the flext package) + +---------------------------------------------------------------------------- + +Python array support for py/pyext@Max/MSP: + +In the Max/MSP SDK change the file +4.5 headers\c74support\max-includes\ext_types.h, line 45 +from + typedef unsigned long UInt32; + typedef signed long SInt32; +to + typedef unsigned int UInt32; + typedef signed int SInt32; +to avoid a compile-time type definition clash. + ---------------------------------------------------------------------------- Goals/features of the package: diff --git a/externals/grill/py/scripts/buffer.py b/externals/grill/py/scripts/buffer.py index 19b6f5d3..2bd36203 100644 --- a/externals/grill/py/scripts/buffer.py +++ b/externals/grill/py/scripts/buffer.py @@ -7,9 +7,9 @@ """This is an example script for the py/pyext object's buffer support.
-PD/Max buffers can be mapped to numarray arrays.
-For numarray see http://numeric.scipy.org
-It will probably once be replaced by Numeric(3)
+PD/Max buffers can be mapped to Python arrays.
+Currently, there are three implementations:
+Numeric, numarray and Numeric3 (for all of them see http://numeric.scipy.org)
"""
import sys
@@ -19,7 +19,7 @@ try: except:
print "ERROR: This script must be loaded by the PD/Max py/pyext external"
-try:
+try:
from numarray import *
except:
print "Failed importing numarray module:",sys.exc_value
@@ -31,7 +31,7 @@ def mul(*args): a = pyext.Buffer(args[1])
b = pyext.Buffer(args[2])
- # slicing causes numarrays (mapped to buffers) to be created
+ # slicing causes Python arrays (mapped to buffers) to be created
# note the c[:] - to assign contents you must assign to a slice of the buffer
c[:] = a[:]*b[:]
@@ -41,8 +41,8 @@ def add(*args): b = pyext.Buffer(args[2])
# this is also possible, but is probably slower
- # the + converts a into a numarray, the argument b is taken as a sequence
- # depending on the implementation in numarray this may be as fast
+ # the + converts a into a Python array, the argument b is taken as a sequence
+ # depending on the implementation this may be as fast
# as above or not
c[:] = a+b
@@ -53,7 +53,7 @@ def fadein(target): def neg(target):
a = pyext.Buffer(target)
- # in place transformation (see numarray ufuncs)
+ # in place transformation (see Python array ufuncs)
negative(a[:],a[:])
# must mark buffer content as dirty to update graph
# (no explicit assignment occurred)
diff --git a/externals/grill/py/scripts/sig.py b/externals/grill/py/scripts/sig.py index 0eac237a..23fc4c60 100644 --- a/externals/grill/py/scripts/sig.py +++ b/externals/grill/py/scripts/sig.py @@ -48,8 +48,8 @@ class gain2(pyext._class): gain = 0
def _dsp(self):
- # cache vectors
- self.invec =self._invec(0)
+ # cache vectors in this scope
+ self.invec = self._invec(0)
self.outvec = self._outvec(0)
# initialize _signal method here for optimized version
if self.invec is self.outvec:
diff --git a/externals/grill/py/source/pybuffer.cpp b/externals/grill/py/source/pybuffer.cpp index f95c4bc6..8f22acf1 100644 --- a/externals/grill/py/source/pybuffer.cpp +++ b/externals/grill/py/source/pybuffer.cpp @@ -10,16 +10,50 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "main.h"
-#ifdef PY_NUMARRAY
-#if FLEXT_OS == FLEXT_OS_MAC
-#include <Python/numarray/numarray.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
-#include <numarray/numarray.h>
+ #if FLEXT_OS == FLEXT_OS_MAC
+ #include <Python/numarray/arrayobject.h>
+ #else
+ #include <numarray/arrayobject.h>
+ #endif
#endif
-static bool nasupport = false;
-static NumarrayType numtype;
#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
@@ -188,15 +222,31 @@ static PyObject *buffer_item(pySamplebuffer *self, int i) return ret;
}
-PyObject *NAFromBuffer(PyObject *buf,int c,int n)
+PyObject *arrayfrombuffer(PyObject *buf,int c,int n)
{
-#ifdef PY_NUMARRAY
- if(nasupport) {
- maybelong shape[2];
+#ifdef PY_ARRAYS
+ if(arrsupport()) {
+ PyObject *arr;
+ int 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;
+#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
#endif
@@ -206,8 +256,8 @@ PyObject *NAFromBuffer(PyObject *buf,int c,int n) static PyObject *buffer_slice(pySamplebuffer *self,int ilow = 0,int ihigh = 1<<(sizeof(int)*8-2))
{
PyObject *ret;
-#ifdef PY_NUMARRAY
- if(nasupport) {
+#ifdef PY_ARRAYS
+ if(arrsupport()) {
if(self->buf) {
const int n = self->buf->Frames();
const int c = self->buf->Channels();
@@ -216,7 +266,7 @@ static PyObject *buffer_slice(pySamplebuffer *self,int ilow = 0,int ihigh = 1<<( if(ihigh < 0) ihigh += n;
if(ihigh > n) ihigh = n;
- PyObject *nobj = NAFromBuffer((PyObject *)self,c,n);
+ PyObject *nobj = arrayfrombuffer((PyObject *)self,c,n);
if(ilow != 0 || ihigh != n) {
ret = PySequence_GetSlice(nobj,ilow,ihigh);
Py_DECREF(nobj);
@@ -271,8 +321,8 @@ static int buffer_ass_item(pySamplebuffer *self,int i,PyObject *v) static int buffer_ass_slice(pySamplebuffer *self,int ilow,int ihigh,PyObject *value)
{
int ret;
-#ifdef PY_NUMARRAY
- if(nasupport) {
+#ifdef PY_ARRAYS
+ if(arrsupport()) {
if(!value) {
PyErr_SetString(PyExc_TypeError,"Object doesn't support item deletion");
ret = -1;
@@ -285,7 +335,11 @@ static int buffer_ass_slice(pySamplebuffer *self,int ilow,int ihigh,PyObject *va if(ihigh < 0) ihigh += n;
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");
ret = -1;
@@ -297,7 +351,11 @@ static int buffer_ass_slice(pySamplebuffer *self,int ilow,int ihigh,PyObject *va else {
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;
}
@@ -674,20 +732,27 @@ PyTypeObject pySamplebuffer_Type = { void initsamplebuffer()
{
-#ifdef PY_NUMARRAY
PyErr_Clear();
+
+#ifdef PY_ARRAYS
+#ifdef NA
import_libnumarray();
+#else
+ import_array();
+#endif
if(PyErr_Occurred())
// catch import error
PyErr_Clear();
else {
// numarray support ok
- nasupport = true;
+#ifdef NA
+ numtype = sizeof(t_sample) == 4?tFloat32:tFloat64;
+#else
+ numtype = sizeof(t_sample) == 4?PyArray_FLOAT:PyArray_DOUBLE;
+#endif
post("");
- post("Numarray support enabled");
+ post("Python array support enabled");
}
-
- numtype = sizeof(t_sample) == 4?tFloat32:tFloat64;
#endif
if(PyType_Ready(&pySamplebuffer_Type) < 0)
@@ -695,4 +760,3 @@ void initsamplebuffer() else
Py_INCREF(&pySamplebuffer_Type);
}
-
diff --git a/externals/grill/py/source/pydsp.cpp b/externals/grill/py/source/pydsp.cpp index 4c9eea5c..28d7d49b 100644 --- a/externals/grill/py/source/pydsp.cpp +++ b/externals/grill/py/source/pydsp.cpp @@ -63,7 +63,7 @@ void pydsp::DoExit() FreeBuffers();
}
-PyObject *NAFromBuffer(PyObject *buf,int c,int n);
+PyObject *arrayfrombuffer(PyObject *buf,int c,int n);
void pydsp::NewBuffers()
{
@@ -82,7 +82,7 @@ void pydsp::NewBuffers() for(i = 0; i < ins; ++i) {
Py_XDECREF(buffers[i]);
PyObject *b = PyBuffer_FromReadWriteMemory(insigs[i],n*sizeof(t_sample));
- buffers[i] = NAFromBuffer(b,1,n);
+ buffers[i] = arrayfrombuffer(b,1,n);
Py_DECREF(b);
}
for(i = 0; i < outs; ++i) {
@@ -94,7 +94,7 @@ void pydsp::NewBuffers() }
else {
PyObject *b = PyBuffer_FromReadWriteMemory(outsigs[i],n*sizeof(t_sample));
- buffers[ins+i] = NAFromBuffer(b,1,n);
+ buffers[ins+i] = arrayfrombuffer(b,1,n);
Py_DECREF(b);
}
}
|