comparison PyPluginObject.cpp @ 33:ef0cf1ba78a9

Start on plugin data members
author Chris Cannam
date Wed, 26 Nov 2014 12:12:36 +0000
parents d5aba4c3c229
children f0195e45351b
comparison
equal deleted inserted replaced
32:d5aba4c3c229 33:ef0cf1ba78a9
41 #define PY_ARRAY_UNIQUE_SYMBOL VAMPYHOST_ARRAY_API 41 #define PY_ARRAY_UNIQUE_SYMBOL VAMPYHOST_ARRAY_API
42 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 42 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
43 #define NO_IMPORT_ARRAY 43 #define NO_IMPORT_ARRAY
44 #include "numpy/arrayobject.h" 44 #include "numpy/arrayobject.h"
45 45
46 #include "structmember.h"
47
46 #include "VectorConversion.h" 48 #include "VectorConversion.h"
47 #include "PyRealTime.h" 49 #include "PyRealTime.h"
48 50
49 #include <string> 51 #include <string>
50 #include <vector> 52 #include <vector>
53 #include <cstddef>
51 54
52 using namespace std; 55 using namespace std;
53 using namespace Vamp; 56 using namespace Vamp;
54
55 static void
56 PyPluginObject_dealloc(PyPluginObject *self)
57 {
58 cerr << "PyPluginObject_dealloc" << endl;
59 delete self->plugin;
60 PyObject_Del(self);
61 }
62 57
63 PyDoc_STRVAR(xx_foo_doc, "Some description"); //!!! 58 PyDoc_STRVAR(xx_foo_doc, "Some description"); //!!!
64 59
65 //!!! todo: conv errors 60 //!!! todo: conv errors
66 61
91 pd->plugin = plugin; 86 pd->plugin = plugin;
92 pd->isInitialised = false; 87 pd->isInitialised = false;
93 pd->channels = 0; 88 pd->channels = 0;
94 pd->blockSize = 0; 89 pd->blockSize = 0;
95 pd->stepSize = 0; 90 pd->stepSize = 0;
91 pd->apiVersion = plugin->getVampApiVersion();
92 pd->identifier = strdup(plugin->getIdentifier().c_str());
96 return (PyObject *)pd; 93 return (PyObject *)pd;
94 }
95
96 static void
97 PyPluginObject_dealloc(PyPluginObject *self)
98 {
99 cerr << "PyPluginObject_dealloc" << endl;
100 delete self->plugin;
101 free(self->identifier);
102 PyObject_Del(self);
97 } 103 }
98 104
99 static PyObject * 105 static PyObject *
100 vampyhost_initialise(PyObject *self, PyObject *args) 106 vampyhost_initialise(PyObject *self, PyObject *args)
101 { 107 {
314 // blowing up if called repeatedly 320 // blowing up if called repeatedly
315 321
316 return Py_True; 322 return Py_True;
317 } 323 }
318 324
325 static PyMemberDef PyPluginObject_members[] =
326 {
327 {(char *)"apiVersion", T_INT, offsetof(PyPluginObject, apiVersion), READONLY,
328 xx_foo_doc}, //!!! fix all these!
329
330 {(char *)"identifier", T_STRING, offsetof(PyPluginObject, identifier), READONLY,
331 xx_foo_doc}, //!!! fix all these!
332
333 {0, 0}
334 };
335
319 static PyMethodDef PyPluginObject_methods[] = 336 static PyMethodDef PyPluginObject_methods[] =
320 { 337 {
321 {"getParameter", vampyhost_getParameter, METH_VARARGS, 338 {"getParameter", vampyhost_getParameter, METH_VARARGS,
322 xx_foo_doc}, //!!! fix all these! 339 xx_foo_doc}, //!!! fix all these!
323 340
324 {"setParameter", vampyhost_setParameter, METH_VARARGS, 341 {"setParameter", vampyhost_setParameter, METH_VARARGS,
325 xx_foo_doc}, 342 xx_foo_doc},
326 343
327 {"initialise", vampyhost_initialise, METH_VARARGS, 344 {"initialise", vampyhost_initialise, METH_VARARGS,
328 xx_foo_doc}, 345 xx_foo_doc},
329 346
330 {"reset", vampyhost_reset, METH_NOARGS, 347 {"reset", vampyhost_reset, METH_NOARGS,
331 xx_foo_doc}, 348 xx_foo_doc},
336 {"unload", vampyhost_unload, METH_NOARGS, 353 {"unload", vampyhost_unload, METH_NOARGS,
337 xx_foo_doc}, 354 xx_foo_doc},
338 355
339 {0, 0} 356 {0, 0}
340 }; 357 };
341
342 static int
343 PyPluginObject_setattr(PyPluginObject *self, char *name, PyObject *value)
344 {
345 return -1;
346 }
347
348 static PyObject *
349 PyPluginObject_getattr(PyPluginObject *self, char *name)
350 {
351 return Py_FindMethod(PyPluginObject_methods, (PyObject *)self, name);
352 }
353 358
354 /* Doc:: 10.3 Type Objects */ /* static */ 359 /* Doc:: 10.3 Type Objects */ /* static */
355 PyTypeObject Plugin_Type = 360 PyTypeObject Plugin_Type =
356 { 361 {
357 PyObject_HEAD_INIT(NULL) 362 PyObject_HEAD_INIT(NULL)
359 "vampyhost.Plugin", /*tp_name*/ 364 "vampyhost.Plugin", /*tp_name*/
360 sizeof(PyPluginObject), /*tp_basicsize*/ 365 sizeof(PyPluginObject), /*tp_basicsize*/
361 0, /*tp_itemsize*/ 366 0, /*tp_itemsize*/
362 (destructor)PyPluginObject_dealloc, /*tp_dealloc*/ 367 (destructor)PyPluginObject_dealloc, /*tp_dealloc*/
363 0, /*tp_print*/ 368 0, /*tp_print*/
364 (getattrfunc)PyPluginObject_getattr, /*tp_getattr*/ 369 0, /*tp_getattr*/
365 (setattrfunc)PyPluginObject_setattr, /*tp_setattr*/ 370 0, /*tp_setattr*/
366 0, /*tp_compare*/ 371 0, /*tp_compare*/
367 0, /*tp_repr*/ 372 0, /*tp_repr*/
368 0, /*tp_as_number*/ 373 0, /*tp_as_number*/
369 0, /*tp_as_sequence*/ 374 0, /*tp_as_sequence*/
370 0, /*tp_as_mapping*/ 375 0, /*tp_as_mapping*/
371 0, /*tp_hash*/ 376 0, /*tp_hash*/
372 0, /*tp_call*/ 377 0, /*tp_call*/
373 0, /*tp_str*/ 378 0, /*tp_str*/
374 0, /*tp_getattro*/ 379 PyObject_GenericGetAttr, /*tp_getattro*/
375 0, /*tp_setattro*/ 380 PyObject_GenericSetAttr, /*tp_setattro*/
376 0, /*tp_as_buffer*/ 381 0, /*tp_as_buffer*/
377 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 382 Py_TPFLAGS_DEFAULT, /*tp_flags*/
378 "Plugin Object", /*tp_doc*/ 383 "Plugin Object", /*tp_doc*/
379 0, /*tp_traverse*/ 384 0, /*tp_traverse*/
380 0, /*tp_clear*/ 385 0, /*tp_clear*/
381 0, /*tp_richcompare*/ 386 0, /*tp_richcompare*/
382 0, /*tp_weaklistoffset*/ 387 0, /*tp_weaklistoffset*/
383 0, /*tp_iter*/ 388 0, /*tp_iter*/
384 0, /*tp_iternext*/ 389 0, /*tp_iternext*/
385 PyPluginObject_methods, /*tp_methods*/ 390 PyPluginObject_methods, /*tp_methods*/
386 0, /*tp_members*/ 391 PyPluginObject_members, /*tp_members*/
387 0, /*tp_getset*/ 392 0, /*tp_getset*/
388 0, /*tp_base*/ 393 0, /*tp_base*/
389 0, /*tp_dict*/ 394 0, /*tp_dict*/
390 0, /*tp_descr_get*/ 395 0, /*tp_descr_get*/
391 0, /*tp_descr_set*/ 396 0, /*tp_descr_set*/