forked from vamp-plugins/vampy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyFeatureSet.cpp
63 lines (51 loc) · 1.81 KB
/
PyFeatureSet.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
/*
* 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 "PyFeatureSet.h"
#include "vamp-sdk/Plugin.h"
using namespace std;
static int
FeatureSet_init(FeatureSetObject *self, PyObject *args, PyObject *kwds)
{
if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0)
return -1;
return 0;
}
static int
FeatureSetObject_ass_sub(FeatureSetObject *mp, PyObject *v, PyObject *w)
{
if (!PyInt_CheckExact(v)) {
PyErr_SetString(PyExc_ValueError,
"Output index must be positive integer.");
return 0;
}
if (w == NULL)
return PyDict_DelItem((PyObject *)mp, v);
else
return PyDict_SetItem((PyObject *)mp, v, w);
}
#define FeatureSet_alloc PyType_GenericAlloc
#define FeatureSet_free PyObject_Del
//#define FeatureSet_as_mapping PyDict_Type.tp_as_mapping
static PyMappingMethods FeatureSet_as_mapping = *(PyDict_Type.tp_as_mapping);
PyTypeObject FeatureSet_Type = PyDict_Type;
void
initFeatureSetType(void)
{
/*This type is derived from PyDict. We just override some slots here.*/
/*The typical use case is index based assignment as opposed to object memeber access.*/
FeatureSet_Type.ob_type = &PyType_Type;
FeatureSet_Type.tp_base = &PyDict_Type;
FeatureSet_Type.tp_bases = PyTuple_Pack(1, FeatureSet_Type.tp_base);
FeatureSet_Type.tp_name = "vampy.FeatureSet";
// FeatureSet_Type.tp_new = FeatureSet_new;
FeatureSet_Type.tp_init = (initproc)FeatureSet_init;
FeatureSet_Type.tp_basicsize = sizeof(FeatureSetObject);
FeatureSet_as_mapping.mp_ass_subscript = (objobjargproc)FeatureSetObject_ass_sub;
FeatureSet_Type.tp_as_mapping = &FeatureSet_as_mapping;
}