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