changeset 33:ef0cf1ba78a9

Start on plugin data members
author Chris Cannam
date Wed, 26 Nov 2014 12:12:36 +0000
parents d5aba4c3c229
children f0195e45351b
files PyPluginObject.cpp PyPluginObject.h
diffstat 2 files changed, 33 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/PyPluginObject.cpp	Wed Nov 26 11:50:15 2014 +0000
+++ b/PyPluginObject.cpp	Wed Nov 26 12:12:36 2014 +0000
@@ -43,23 +43,18 @@
 #define NO_IMPORT_ARRAY
 #include "numpy/arrayobject.h"
 
+#include "structmember.h"
+
 #include "VectorConversion.h"
 #include "PyRealTime.h"
 
 #include <string>
 #include <vector>
+#include <cstddef>
 
 using namespace std;
 using namespace Vamp;
 
-static void
-PyPluginObject_dealloc(PyPluginObject *self)
-{
-    cerr << "PyPluginObject_dealloc" << endl;
-    delete self->plugin;
-    PyObject_Del(self);
-}
-
 PyDoc_STRVAR(xx_foo_doc, "Some description"); //!!!
 
 //!!! todo: conv errors
@@ -93,9 +88,20 @@
     pd->channels = 0;
     pd->blockSize = 0;
     pd->stepSize = 0;
+    pd->apiVersion = plugin->getVampApiVersion();
+    pd->identifier = strdup(plugin->getIdentifier().c_str());
     return (PyObject *)pd;
 }
 
+static void
+PyPluginObject_dealloc(PyPluginObject *self)
+{
+    cerr << "PyPluginObject_dealloc" << endl;
+    delete self->plugin;
+    free(self->identifier);
+    PyObject_Del(self);
+}
+
 static PyObject *
 vampyhost_initialise(PyObject *self, PyObject *args)
 {
@@ -316,6 +322,17 @@
     return Py_True;
 }
 
+static PyMemberDef PyPluginObject_members[] =
+{
+    {(char *)"apiVersion", T_INT, offsetof(PyPluginObject, apiVersion), READONLY,
+     xx_foo_doc}, //!!! fix all these!
+     
+    {(char *)"identifier", T_STRING, offsetof(PyPluginObject, identifier), READONLY,
+     xx_foo_doc}, //!!! fix all these!
+    
+    {0, 0}
+};
+
 static PyMethodDef PyPluginObject_methods[] =
 {
     {"getParameter",	vampyhost_getParameter, METH_VARARGS,
@@ -323,7 +340,7 @@
 
     {"setParameter",	vampyhost_setParameter, METH_VARARGS,
      xx_foo_doc},
-
+    
     {"initialise",	vampyhost_initialise, METH_VARARGS,
      xx_foo_doc},
 
@@ -339,18 +356,6 @@
     {0, 0}
 };
 
-static int
-PyPluginObject_setattr(PyPluginObject *self, char *name, PyObject *value)
-{
-    return -1;
-}
-
-static PyObject *
-PyPluginObject_getattr(PyPluginObject *self, char *name)
-{
-    return Py_FindMethod(PyPluginObject_methods, (PyObject *)self, name);
-}
-
 /* Doc:: 10.3 Type Objects */ /* static */ 
 PyTypeObject Plugin_Type = 
 {
@@ -361,8 +366,8 @@
     0,		/*tp_itemsize*/
     (destructor)PyPluginObject_dealloc, /*tp_dealloc*/
     0,						/*tp_print*/
-    (getattrfunc)PyPluginObject_getattr, /*tp_getattr*/
-    (setattrfunc)PyPluginObject_setattr, /*tp_setattr*/
+    0, /*tp_getattr*/
+    0, /*tp_setattr*/
     0,						/*tp_compare*/
     0,			/*tp_repr*/
     0,	/*tp_as_number*/
@@ -371,8 +376,8 @@
     0,						/*tp_hash*/
     0,                      /*tp_call*/
     0,                      /*tp_str*/
-    0,                      /*tp_getattro*/
-    0,                      /*tp_setattro*/
+    PyObject_GenericGetAttr,                      /*tp_getattro*/
+    PyObject_GenericSetAttr,                      /*tp_setattro*/
     0,                      /*tp_as_buffer*/
     Py_TPFLAGS_DEFAULT,     /*tp_flags*/
     "Plugin Object",      /*tp_doc*/
@@ -383,7 +388,7 @@
     0,                      /*tp_iter*/
     0,                      /*tp_iternext*/
     PyPluginObject_methods,       /*tp_methods*/ 
-    0,                      /*tp_members*/
+    PyPluginObject_members,                      /*tp_members*/
     0,                      /*tp_getset*/
     0,                      /*tp_base*/
     0,                      /*tp_dict*/
--- a/PyPluginObject.h	Wed Nov 26 11:50:15 2014 +0000
+++ b/PyPluginObject.h	Wed Nov 26 12:12:36 2014 +0000
@@ -51,6 +51,8 @@
     size_t channels;
     size_t blockSize;
     size_t stepSize;
+    int apiVersion;
+    char *identifier;
 };
 
 PyAPI_DATA(PyTypeObject) Plugin_Type;