annotate PyOutputDescriptor.cpp @ 67:146d14ab15e7

Debug output: off by default, on with VAMPY_VERBOSE environment variable
author Chris Cannam
date Mon, 17 Nov 2014 10:03:44 +0000
parents c1e4f706ca9a
children
rev   line source
fazekasgy@37 1 /*
fazekasgy@37 2
fazekasgy@37 3 * Vampy : This plugin is a wrapper around the Vamp plugin API.
fazekasgy@37 4 * It allows for writing Vamp plugins in Python.
fazekasgy@37 5
fazekasgy@37 6 * Centre for Digital Music, Queen Mary University of London.
fazekasgy@37 7 * Copyright (C) 2008-2009 Gyorgy Fazekas, QMUL. (See Vamp sources
fazekasgy@37 8 * for licence information.)
fazekasgy@37 9
fazekasgy@37 10 */
fazekasgy@37 11
fazekasgy@37 12 #include <Python.h>
fazekasgy@37 13 #include "PyOutputDescriptor.h"
fazekasgy@37 14 #include "vamp-sdk/Plugin.h"
fazekasgy@37 15 #include <string>
fazekasgy@37 16 #include "PyTypeInterface.h"
fazekasgy@37 17
fazekasgy@37 18 using namespace std;
fazekasgy@37 19 using namespace Vamp;
fazekasgy@37 20 using Vamp::Plugin;
fazekasgy@37 21
fazekasgy@37 22 /* OutputDescriptor Object's Methods */
fazekasgy@37 23 //these objects have no callable methods
fazekasgy@37 24
fazekasgy@37 25 /* PyOutputDescriptor methods implementing protocols */
fazekasgy@37 26 // these functions are called by the interpreter automatically
fazekasgy@37 27
fazekasgy@37 28 /* New OutputDescriptor object */
fazekasgy@37 29 static PyObject *
fazekasgy@37 30 OutputDescriptor_new(PyTypeObject *type, PyObject *args, PyObject *kw)
fazekasgy@37 31 {
fazekasgy@37 32 OutputDescriptorObject *self =
fazekasgy@37 33 (OutputDescriptorObject*)type->tp_alloc(type, 0);
fazekasgy@37 34
fazekasgy@37 35 if (self == NULL) return NULL;
fazekasgy@37 36 self->dict = PyDict_New();
fazekasgy@37 37 if (self->dict == NULL) return NULL;
fazekasgy@37 38
fazekasgy@37 39 /// allow copying objects
cannam@46 40 if (args && PyTuple_Size(args) == 1) {
fazekasgy@37 41 PyObject* arg = PyTuple_GET_ITEM(args,0);
fazekasgy@37 42 if (PyOutputDescriptor_CheckExact(arg))
fazekasgy@37 43 PyDict_Merge(self->dict,PyOutputDescriptor_AS_DICT(arg),0);
fazekasgy@37 44 else if (PyDict_CheckExact(arg))
fazekasgy@37 45 PyDict_Merge(self->dict,arg,0);
fazekasgy@37 46 else {
fazekasgy@37 47 PyErr_SetString(PyExc_TypeError,
fazekasgy@37 48 "OutputDescriptor takes zero or one PyOutputDescriptor or dictionary arguments.");
fazekasgy@37 49 return NULL;
fazekasgy@37 50 }
fazekasgy@37 51 }
fazekasgy@37 52 return (PyObject *) self;
fazekasgy@37 53 }
fazekasgy@37 54
fazekasgy@37 55
fazekasgy@37 56 /* DESTRUCTOR: delete type object */
fazekasgy@37 57 static void
fazekasgy@37 58 OutputDescriptorObject_dealloc(OutputDescriptorObject *self)
fazekasgy@37 59 {
fazekasgy@37 60 Py_XDECREF(self->dict);
fazekasgy@37 61 PyObject_Del(self);
fazekasgy@37 62 }
fazekasgy@37 63
fazekasgy@37 64
fazekasgy@37 65 /* Set attributes */
fazekasgy@37 66 static int
fazekasgy@37 67 OutputDescriptor_setattr(OutputDescriptorObject *self, char *name, PyObject *v)
fazekasgy@37 68 {
fazekasgy@37 69 if (v == NULL) {
fazekasgy@37 70 int rv = PyDict_DelItemString(self->dict, name);
fazekasgy@37 71 if (rv < 0)
fazekasgy@37 72 PyErr_SetString(PyExc_AttributeError,"non-existing OutputDescriptor attribute");
fazekasgy@37 73 return rv;
fazekasgy@37 74 }
fazekasgy@37 75 else
fazekasgy@37 76 return PyDict_SetItemString(self->dict, name, v);
fazekasgy@37 77 }
fazekasgy@37 78
fazekasgy@37 79
fazekasgy@37 80 /* Get attributes */
fazekasgy@37 81 static PyObject *
fazekasgy@37 82 OutputDescriptor_getattr(OutputDescriptorObject *self, char *name)
fazekasgy@37 83 {
fazekasgy@37 84 if (self->dict != NULL) {
fazekasgy@37 85 PyObject *v = PyDict_GetItemString(self->dict, name);
fazekasgy@37 86 if (v != NULL)
fazekasgy@37 87 {
fazekasgy@37 88 Py_INCREF(v);
fazekasgy@37 89 return v;
fazekasgy@37 90 }
fazekasgy@51 91 PyErr_SetString(PyExc_AttributeError,"non-existing OutputDescriptor attribute");
fazekasgy@37 92 }
fazekasgy@37 93 return NULL;
fazekasgy@37 94 }
fazekasgy@37 95
fazekasgy@37 96
fazekasgy@37 97 /* String representation */
fazekasgy@37 98 static PyObject *
fazekasgy@37 99 OutputDescriptor_repr(PyObject *self)
fazekasgy@37 100 {
fazekasgy@37 101 OutputDescriptorObject* v = (OutputDescriptorObject*)self;
fazekasgy@37 102 if (v->dict) return PyDict_Type.tp_repr((PyObject *)v->dict);
fazekasgy@37 103 else return PyString_FromString("OutputDescriptor()");
fazekasgy@37 104 }
fazekasgy@37 105
fazekasgy@37 106 #define OutputDescriptor_alloc PyType_GenericAlloc
fazekasgy@37 107 #define OutputDescriptor_free PyObject_Del
fazekasgy@37 108
fazekasgy@37 109
fazekasgy@37 110 /* REAL-TIME TYPE OBJECT */
fazekasgy@37 111
fazekasgy@37 112 PyTypeObject OutputDescriptor_Type = {
fazekasgy@37 113 PyObject_HEAD_INIT(NULL)
fazekasgy@37 114 0, /*ob_size*/
fazekasgy@37 115 "vampy.OutputDescriptor",/*tp_name*/
fazekasgy@37 116 sizeof(OutputDescriptorObject), /*tp_basicsize*/
fazekasgy@37 117 0, /*tp_itemsize*/
fazekasgy@37 118 (destructor)OutputDescriptorObject_dealloc, /*tp_dealloc*/
fazekasgy@37 119 0, /*tp_print*/
fazekasgy@37 120 (getattrfunc)OutputDescriptor_getattr, /*tp_getattr*/
fazekasgy@37 121 (setattrfunc)OutputDescriptor_setattr, /*tp_setattr*/
fazekasgy@37 122 0, /*tp_compare*/
fazekasgy@37 123 OutputDescriptor_repr, /*tp_repr*/
fazekasgy@37 124 0, /*tp_as_number*/
fazekasgy@37 125 0, /*tp_as_sequence*/
fazekasgy@37 126 0, /*tp_as_mapping*/
fazekasgy@37 127 0, /*tp_hash*/
fazekasgy@37 128 0, /*tp_call*/
fazekasgy@37 129 0, /*tp_str*/
fazekasgy@37 130 0, /*tp_getattro*/
fazekasgy@37 131 0, /*tp_setattro*/
fazekasgy@37 132 0, /*tp_as_buffer*/
fazekasgy@37 133 Py_TPFLAGS_DEFAULT, /*tp_flags*/
fazekasgy@37 134 0, /*tp_doc*/
fazekasgy@37 135 0, /*tp_traverse*/
fazekasgy@37 136 0, /*tp_clear*/
fazekasgy@37 137 0, /*tp_richcompare*/
fazekasgy@37 138 0, /*tp_weaklistoffset*/
fazekasgy@37 139 0, /*tp_iter*/
fazekasgy@37 140 0, /*tp_iternext*/
fazekasgy@37 141 0, /*tp_methods*/ //TypeObject Methods
fazekasgy@37 142 0, /*tp_members*/
fazekasgy@37 143 0, /*tp_getset*/
fazekasgy@37 144 0, /*tp_base*/
fazekasgy@37 145 0, /*tp_dict*/
fazekasgy@37 146 0, /*tp_descr_get*/
fazekasgy@37 147 0, /*tp_descr_set*/
fazekasgy@37 148 0, /*tp_dictoffset*/
fazekasgy@37 149 0, /*tp_init*/
fazekasgy@37 150 OutputDescriptor_alloc, /*tp_alloc*/
fazekasgy@37 151 OutputDescriptor_new, /*tp_new*/
fazekasgy@37 152 OutputDescriptor_free, /*tp_free*/
fazekasgy@37 153 0, /*tp_is_gc*/
fazekasgy@37 154 };
fazekasgy@37 155
fazekasgy@37 156 /* PyOutputDescriptor C++ API */
fazekasgy@37 157