python/aubiowraphell.h: sprinkle some cpp magic
authorPaul Brossier <piem@piem.org>
Sun, 15 Nov 2009 14:00:04 +0000 (15:00 +0100)
committerPaul Brossier <piem@piem.org>
Sun, 15 Nov 2009 14:00:04 +0000 (15:00 +0100)
interfaces/python/aubiowraphell.h [new file with mode: 0644]

diff --git a/interfaces/python/aubiowraphell.h b/interfaces/python/aubiowraphell.h
new file mode 100644 (file)
index 0000000..c8fc222
--- /dev/null
@@ -0,0 +1,99 @@
+#include "aubio-types.h"
+
+#define AUBIO_DECLARE(NAME, PARAMS...) \
+typedef struct { \
+  PyObject_HEAD \
+  aubio_ ## NAME ## _t * o; \
+  PARAMS; \
+} Py_## NAME;
+
+#define AUBIO_NEW(NAME) \
+static PyObject * \
+Py_ ## NAME ## _new (PyTypeObject * type, PyObject * args, PyObject * kwds) \
+{ \
+  Py_ ## NAME * self; \
+  self = (Py_ ## NAME *) type->tp_alloc (type, 0); \
+  return (PyObject *)self; \
+}
+
+#define AUBIO_INIT(NAME, PARAMS... ) \
+static int \
+Py_ ## NAME ## _init (Py_ ## NAME * self, PyObject * args, PyObject * kwds) \
+{ \
+  self->o = new_aubio_## NAME ( PARAMS ); \
+  if (self->o == NULL) { \
+    return -1; \
+  } \
+\
+  return 0; \
+}
+
+#define AUBIO_DEL(NAME) \
+static void \
+Py_ ## NAME ## _del ( Py_ ## NAME * self) \
+{ \
+  del_aubio_ ## NAME (self->o); \
+  self->ob_type->tp_free ((PyObject *) self); \
+}
+
+#define AUBIO_MEMBERS_START(NAME) \
+static PyMemberDef Py_ ## NAME ## _members[] = {
+
+#define AUBIO_MEMBERS_STOP(NAME) \
+  {NULL} \
+};
+
+#define AUBIO_METHODS(NAME) \
+static PyMethodDef Py_ ## NAME ## _methods[] = { \
+  {NULL} \
+};
+
+
+#define AUBIO_TYPEOBJECT(NAME, PYNAME) \
+PyTypeObject Py_ ## NAME ## Type = { \
+  PyObject_HEAD_INIT (NULL)    \
+  0,                           \
+  PYNAME,                      \
+  sizeof (Py_ ## NAME),          \
+  0,                           \
+  (destructor) Py_ ## NAME ## _del,  \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  (ternaryfunc)Py_ ## NAME ## _do,   \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  Py_TPFLAGS_DEFAULT,          \
+  Py_ ## NAME ## _doc,               \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  Py_ ## NAME ## _methods,           \
+  Py_ ## NAME ## _members,           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  0,                           \
+  (initproc) Py_ ## NAME ## _init,   \
+  0,                           \
+  Py_ ## NAME ## _new,               \
+};
+
+// some more helpers
+#define AUBIO_NEW_VEC(name, type, lengthval, channelsval) \
+  name = (type *) PyObject_New (type, & type ## Type); \
+  name->channels = channelsval; \
+  name->length = lengthval;