Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@26
|
3 /*
|
Chris@26
|
4 VampyHost
|
Chris@26
|
5
|
Chris@26
|
6 Use Vamp audio analysis plugins in Python
|
Chris@26
|
7
|
Chris@26
|
8 Gyorgy Fazekas and Chris Cannam
|
Chris@26
|
9 Centre for Digital Music, Queen Mary, University of London
|
Chris@117
|
10 Copyright 2008-2015 Queen Mary, University of London
|
Chris@26
|
11
|
Chris@26
|
12 Permission is hereby granted, free of charge, to any person
|
Chris@26
|
13 obtaining a copy of this software and associated documentation
|
Chris@26
|
14 files (the "Software"), to deal in the Software without
|
Chris@26
|
15 restriction, including without limitation the rights to use, copy,
|
Chris@26
|
16 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@26
|
17 of the Software, and to permit persons to whom the Software is
|
Chris@26
|
18 furnished to do so, subject to the following conditions:
|
Chris@26
|
19
|
Chris@26
|
20 The above copyright notice and this permission notice shall be
|
Chris@26
|
21 included in all copies or substantial portions of the Software.
|
Chris@26
|
22
|
Chris@26
|
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@26
|
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@26
|
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@26
|
26 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
Chris@26
|
27 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@26
|
28 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@26
|
29 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@26
|
30
|
Chris@26
|
31 Except as contained in this notice, the names of the Centre for
|
Chris@26
|
32 Digital Music; Queen Mary, University of London; and the authors
|
Chris@26
|
33 shall not be used in advertising or otherwise to promote the sale,
|
Chris@26
|
34 use or other dealings in this Software without prior written
|
Chris@26
|
35 authorization.
|
Chris@26
|
36 */
|
Chris@26
|
37
|
Chris@31
|
38 #include "PyPluginObject.h"
|
Chris@14
|
39
|
Chris@14
|
40 // define a unique API pointer
|
Chris@27
|
41 #define PY_ARRAY_UNIQUE_SYMBOL VAMPYHOST_ARRAY_API
|
Chris@14
|
42 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
|
Chris@31
|
43 #define NO_IMPORT_ARRAY
|
Chris@14
|
44 #include "numpy/arrayobject.h"
|
Chris@14
|
45
|
Chris@102
|
46 #if PY_MAJOR_VERSION < 3
|
Chris@102
|
47 #include "intobject.h"
|
Chris@102
|
48 #endif
|
Chris@102
|
49
|
Chris@33
|
50 #include "structmember.h"
|
Chris@33
|
51
|
Chris@48
|
52 #include "FloatConversion.h"
|
Chris@29
|
53 #include "VectorConversion.h"
|
Chris@112
|
54 #include "StringConversion.h"
|
Chris@16
|
55 #include "PyRealTime.h"
|
Chris@0
|
56
|
Chris@139
|
57 #include "vamp-hostsdk/PluginWrapper.h"
|
Chris@139
|
58 #include "vamp-hostsdk/PluginInputDomainAdapter.h"
|
Chris@139
|
59
|
Chris@0
|
60 #include <string>
|
Chris@31
|
61 #include <vector>
|
Chris@33
|
62 #include <cstddef>
|
Chris@49
|
63 #include <set>
|
Chris@0
|
64
|
Chris@0
|
65 using namespace std;
|
Chris@0
|
66 using namespace Vamp;
|
Chris@139
|
67 using namespace Vamp::HostExt;
|
Chris@0
|
68
|
Chris@31
|
69 static
|
Chris@21
|
70 PyPluginObject *
|
Chris@21
|
71 getPluginObject(PyObject *pyPluginHandle)
|
Chris@21
|
72 {
|
Chris@21
|
73 PyPluginObject *pd = 0;
|
Chris@21
|
74 if (PyPlugin_Check(pyPluginHandle)) {
|
Chris@21
|
75 pd = (PyPluginObject *)pyPluginHandle;
|
Chris@16
|
76 }
|
Chris@16
|
77 if (!pd || !pd->plugin) {
|
Chris@16
|
78 PyErr_SetString(PyExc_AttributeError,
|
Chris@39
|
79 "Invalid or already deleted plugin handle.");
|
Chris@16
|
80 return 0;
|
Chris@0
|
81 } else {
|
Chris@16
|
82 return pd;
|
Chris@0
|
83 }
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@134
|
86 static int
|
Chris@134
|
87 setint(PyObject *d, const char *name, int value)
|
Chris@134
|
88 {
|
Chris@134
|
89 PyObject *v;
|
Chris@134
|
90 int err;
|
Chris@134
|
91 #if (PY_MAJOR_VERSION >= 3)
|
Chris@134
|
92 v = PyLong_FromLong((long)value);
|
Chris@134
|
93 #else
|
Chris@134
|
94 v = PyInt_FromLong((long)value);
|
Chris@134
|
95 #endif
|
Chris@134
|
96 err = PyDict_SetItemString(d, name, v);
|
Chris@134
|
97 Py_XDECREF(v);
|
Chris@134
|
98 return err;
|
Chris@134
|
99 }
|
Chris@134
|
100
|
Chris@134
|
101 static int
|
Chris@134
|
102 setfloat(PyObject *d, const char *name, double value)
|
Chris@134
|
103 {
|
Chris@134
|
104 PyObject *v;
|
Chris@134
|
105 int err;
|
Chris@134
|
106 v = PyFloat_FromDouble(value);
|
Chris@134
|
107 err = PyDict_SetItemString(d, name, v);
|
Chris@134
|
108 Py_XDECREF(v);
|
Chris@134
|
109 return err;
|
Chris@134
|
110 }
|
Chris@134
|
111
|
Chris@134
|
112 static int
|
Chris@134
|
113 setstring(PyObject *d, const char *name, string value)
|
Chris@134
|
114 {
|
Chris@134
|
115 PyObject *v;
|
Chris@134
|
116 int err;
|
Chris@134
|
117 v = StringConversion().string2py(value);
|
Chris@134
|
118 err = PyDict_SetItemString(d, name, v);
|
Chris@134
|
119 Py_XDECREF(v);
|
Chris@134
|
120 return err;
|
Chris@134
|
121 }
|
Chris@134
|
122
|
Chris@31
|
123 PyObject *
|
Chris@31
|
124 PyPluginObject_From_Plugin(Plugin *plugin)
|
Chris@0
|
125 {
|
Chris@124
|
126 PyPluginObject *pd = PyObject_New(PyPluginObject, &Plugin_Type);
|
Chris@124
|
127 if (!pd) return 0;
|
Chris@124
|
128
|
Chris@21
|
129 pd->plugin = plugin;
|
Chris@21
|
130 pd->isInitialised = false;
|
Chris@21
|
131 pd->channels = 0;
|
Chris@21
|
132 pd->blockSize = 0;
|
Chris@21
|
133 pd->stepSize = 0;
|
Chris@134
|
134 pd->info = 0;
|
Chris@134
|
135 pd->parameters = 0;
|
Chris@134
|
136 pd->programs = 0;
|
Chris@34
|
137
|
Chris@112
|
138 StringConversion strconv;
|
Chris@112
|
139
|
Chris@34
|
140 PyObject *infodict = PyDict_New();
|
Chris@134
|
141 setint(infodict, "apiVersion", plugin->getVampApiVersion());
|
Chris@134
|
142 setint(infodict, "pluginVersion", plugin->getPluginVersion());
|
Chris@134
|
143 setstring(infodict, "identifier", plugin->getIdentifier());
|
Chris@134
|
144 setstring(infodict, "name", plugin->getName());
|
Chris@134
|
145 setstring(infodict, "description", plugin->getDescription());
|
Chris@134
|
146 setstring(infodict, "maker", plugin->getMaker());
|
Chris@134
|
147 setstring(infodict, "copyright", plugin->getCopyright());
|
Chris@34
|
148 pd->info = infodict;
|
Chris@34
|
149
|
Chris@82
|
150 pd->inputDomain = plugin->getInputDomain();
|
Chris@34
|
151
|
Chris@35
|
152 VectorConversion conv;
|
Chris@35
|
153
|
Chris@34
|
154 Plugin::ParameterList pl = plugin->getParameterDescriptors();
|
Chris@34
|
155 PyObject *params = PyList_New(pl.size());
|
Chris@34
|
156
|
Chris@34
|
157 for (int i = 0; i < (int)pl.size(); ++i) {
|
Chris@34
|
158 PyObject *paramdict = PyDict_New();
|
Chris@134
|
159 setstring(paramdict, "identifier", pl[i].identifier);
|
Chris@134
|
160 setstring(paramdict, "name", pl[i].name);
|
Chris@134
|
161 setstring(paramdict, "description", pl[i].description);
|
Chris@134
|
162 setstring(paramdict, "unit", pl[i].unit);
|
Chris@134
|
163 setfloat(paramdict, "minValue", pl[i].minValue);
|
Chris@134
|
164 setfloat(paramdict, "maxValue", pl[i].maxValue);
|
Chris@134
|
165 setfloat(paramdict, "defaultValue", pl[i].defaultValue);
|
Chris@34
|
166 if (pl[i].isQuantized) {
|
Chris@134
|
167 PyDict_SetItemString(paramdict, "isQuantized", Py_True);
|
Chris@134
|
168 setfloat(paramdict, "quantizeStep", pl[i].quantizeStep);
|
Chris@34
|
169 if (!pl[i].valueNames.empty()) {
|
Chris@134
|
170 PyObject *vv = conv.PyValue_From_StringVector(pl[i].valueNames);
|
Chris@134
|
171 PyDict_SetItemString(paramdict, "valueNames", vv);
|
Chris@134
|
172 Py_DECREF(vv);
|
Chris@34
|
173 }
|
Chris@34
|
174 } else {
|
Chris@134
|
175 PyDict_SetItemString(paramdict, "isQuantized", Py_False);
|
Chris@34
|
176 }
|
Chris@34
|
177
|
Chris@34
|
178 PyList_SET_ITEM(params, i, paramdict);
|
Chris@34
|
179 }
|
Chris@34
|
180
|
Chris@34
|
181 pd->parameters = params;
|
Chris@39
|
182
|
Chris@39
|
183 Plugin::ProgramList prl = plugin->getPrograms();
|
Chris@39
|
184 PyObject *progs = PyList_New(prl.size());
|
Chris@39
|
185
|
Chris@39
|
186 for (int i = 0; i < (int)prl.size(); ++i) {
|
Chris@112
|
187 PyList_SET_ITEM(progs, i, strconv.string2py(prl[i]));
|
Chris@39
|
188 }
|
Chris@39
|
189
|
Chris@39
|
190 pd->programs = progs;
|
Chris@37
|
191
|
Chris@37
|
192 return (PyObject *)pd;
|
Chris@37
|
193 }
|
Chris@35
|
194
|
Chris@37
|
195 static void
|
Chris@37
|
196 PyPluginObject_dealloc(PyPluginObject *self)
|
Chris@37
|
197 {
|
Chris@115
|
198 // cerr << "PyPluginObject_dealloc: plugin object " << self << ", plugin " << self->plugin << endl;
|
Chris@115
|
199
|
Chris@37
|
200 delete self->plugin;
|
Chris@134
|
201 Py_XDECREF(self->info);
|
Chris@134
|
202 Py_XDECREF(self->parameters);
|
Chris@134
|
203 Py_XDECREF(self->programs);
|
Chris@37
|
204 PyObject_Del(self);
|
Chris@37
|
205 }
|
Chris@37
|
206
|
Chris@37
|
207 static PyObject *
|
Chris@87
|
208 convertOutput(const Plugin::OutputDescriptor &desc, int ix)
|
Chris@86
|
209 {
|
Chris@93
|
210 VectorConversion conv;
|
Chris@112
|
211 StringConversion strconv;
|
Chris@93
|
212
|
Chris@86
|
213 PyObject *outdict = PyDict_New();
|
Chris@134
|
214 setstring(outdict, "identifier", desc.identifier);
|
Chris@134
|
215 setstring(outdict, "name", desc.name);
|
Chris@134
|
216 setstring(outdict, "description", desc.description);
|
Chris@134
|
217 setstring(outdict, "unit", desc.unit);
|
Chris@93
|
218 if (desc.hasFixedBinCount) {
|
Chris@134
|
219 PyDict_SetItemString(outdict, "hasFixedBinCount", Py_True);
|
Chris@134
|
220 setint(outdict, "binCount", desc.binCount);
|
Chris@93
|
221 if (!desc.binNames.empty()) {
|
Chris@134
|
222 PyObject *vv = conv.PyValue_From_StringVector(desc.binNames);
|
Chris@134
|
223 PyDict_SetItemString(outdict, "binNames", vv);
|
Chris@134
|
224 Py_DECREF(vv);
|
Chris@93
|
225 }
|
Chris@134
|
226 } else {
|
Chris@134
|
227 PyDict_SetItemString(outdict, "hasFixedBinCount", Py_False);
|
Chris@93
|
228 }
|
Chris@93
|
229 if (!desc.hasFixedBinCount ||
|
Chris@93
|
230 (desc.hasFixedBinCount && (desc.binCount > 0))) {
|
Chris@86
|
231 if (desc.hasKnownExtents) {
|
Chris@134
|
232 PyDict_SetItemString(outdict, "hasKnownExtents", Py_True);
|
Chris@134
|
233 setfloat(outdict, "minValue", desc.minValue);
|
Chris@134
|
234 setfloat(outdict, "maxValue", desc.maxValue);
|
Chris@86
|
235 } else {
|
Chris@134
|
236 PyDict_SetItemString(outdict, "hasKnownExtents", Py_False);
|
Chris@86
|
237 }
|
Chris@86
|
238 if (desc.isQuantized) {
|
Chris@134
|
239 PyDict_SetItemString(outdict, "isQuantized", Py_True);
|
Chris@134
|
240 setfloat(outdict, "quantizeStep", desc.quantizeStep);
|
Chris@86
|
241 } else {
|
Chris@134
|
242 PyDict_SetItemString(outdict, "isQuantized", Py_False);
|
Chris@86
|
243 }
|
Chris@86
|
244 }
|
Chris@134
|
245 setint(outdict, "sampleType", (int)desc.sampleType);
|
Chris@134
|
246 setfloat(outdict, "sampleRate", desc.sampleRate);
|
Chris@86
|
247 PyDict_SetItemString
|
Chris@109
|
248 (outdict, "hasDuration", desc.hasDuration ? Py_True : Py_False);
|
Chris@134
|
249 setint(outdict, "output_index", ix);
|
Chris@86
|
250 return outdict;
|
Chris@86
|
251 }
|
Chris@86
|
252
|
Chris@86
|
253 static PyObject *
|
Chris@86
|
254 get_output(PyObject *self, PyObject *args)
|
Chris@86
|
255 {
|
Chris@86
|
256 PyPluginObject *pd = getPluginObject(self);
|
Chris@86
|
257 if (!pd) return 0;
|
Chris@86
|
258
|
Chris@112
|
259 ssize_t n = -1;
|
Chris@86
|
260 PyObject *pyId = 0;
|
Chris@86
|
261
|
Chris@86
|
262 if (!PyArg_ParseTuple(args, "n", &n) &&
|
Chris@112
|
263 !PyArg_ParseTuple(args,
|
Chris@112
|
264 #if (PY_MAJOR_VERSION >= 3)
|
Chris@112
|
265 "U",
|
Chris@112
|
266 #else
|
Chris@112
|
267 "S",
|
Chris@112
|
268 #endif
|
Chris@112
|
269 &pyId)) {
|
Chris@86
|
270 PyErr_SetString(PyExc_TypeError,
|
Chris@86
|
271 "get_output takes either output id (string) or output index (int) argument");
|
Chris@86
|
272 return 0;
|
Chris@86
|
273 }
|
Chris@86
|
274
|
Chris@87
|
275 PyErr_Clear();
|
Chris@87
|
276
|
Chris@86
|
277 Plugin::OutputList ol = pd->plugin->getOutputDescriptors();
|
Chris@86
|
278
|
Chris@112
|
279 StringConversion strconv;
|
Chris@112
|
280
|
Chris@86
|
281 if (pyId) {
|
Chris@112
|
282 string id = strconv.py2string(pyId);
|
Chris@86
|
283 for (int i = 0; i < int(ol.size()); ++i) {
|
Chris@86
|
284 if (ol[i].identifier == id) {
|
Chris@87
|
285 return convertOutput(ol[i], i);
|
Chris@86
|
286 }
|
Chris@86
|
287 }
|
Chris@86
|
288 } else {
|
Chris@86
|
289 if (n >= 0 && n < int(ol.size())) {
|
Chris@87
|
290 return convertOutput(ol[n], n);
|
Chris@86
|
291 }
|
Chris@86
|
292 }
|
Chris@86
|
293
|
Chris@102
|
294 PyErr_SetString(PyExc_Exception,
|
Chris@86
|
295 "unknown output id or output index out of range");
|
Chris@86
|
296 return 0;
|
Chris@86
|
297 }
|
Chris@86
|
298
|
Chris@86
|
299 static PyObject *
|
Chris@80
|
300 get_outputs(PyObject *self, PyObject *args)
|
Chris@37
|
301 {
|
Chris@37
|
302 PyPluginObject *pd = getPluginObject(self);
|
Chris@37
|
303 if (!pd) return 0;
|
Chris@37
|
304 Plugin::OutputList ol = pd->plugin->getOutputDescriptors();
|
Chris@35
|
305 PyObject *outputs = PyList_New(ol.size());
|
Chris@35
|
306
|
Chris@35
|
307 for (int i = 0; i < (int)ol.size(); ++i) {
|
Chris@87
|
308 PyObject *outdict = convertOutput(ol[i], i);
|
Chris@35
|
309 PyList_SET_ITEM(outputs, i, outdict);
|
Chris@35
|
310 }
|
Chris@35
|
311
|
Chris@37
|
312 return outputs;
|
Chris@33
|
313 }
|
Chris@33
|
314
|
Chris@0
|
315 static PyObject *
|
Chris@139
|
316 set_process_timestamp_method(PyObject *self, PyObject *args)
|
Chris@139
|
317 {
|
Chris@139
|
318 ssize_t method;
|
Chris@139
|
319
|
Chris@139
|
320 if (!PyArg_ParseTuple(args,
|
Chris@139
|
321 "n",
|
Chris@139
|
322 &method)) {
|
Chris@139
|
323 PyErr_SetString(PyExc_TypeError,
|
Chris@139
|
324 "set_process_timestamp_method() takes method (int) argument");
|
Chris@139
|
325 return 0; }
|
Chris@139
|
326
|
Chris@139
|
327 PyPluginObject *pd = getPluginObject(self);
|
Chris@139
|
328 if (!pd) return 0;
|
Chris@139
|
329
|
Chris@139
|
330 PluginWrapper *wrapper = dynamic_cast<PluginWrapper *>(pd->plugin);
|
Chris@139
|
331 if (!wrapper) {
|
Chris@139
|
332 PyErr_SetString(PyExc_Exception,
|
Chris@139
|
333 "Plugin was not loaded with ADAPT_INPUT_DOMAIN flag (no wrapper present)");
|
Chris@139
|
334 return 0;
|
Chris@139
|
335 }
|
Chris@139
|
336
|
Chris@139
|
337 PluginInputDomainAdapter *adapter = wrapper->getWrapper<PluginInputDomainAdapter>();
|
Chris@139
|
338 if (!adapter) {
|
Chris@139
|
339 Py_RETURN_FALSE;
|
Chris@139
|
340 }
|
Chris@139
|
341
|
Chris@139
|
342 adapter->setProcessTimestampMethod
|
Chris@139
|
343 (PluginInputDomainAdapter::ProcessTimestampMethod(method));
|
Chris@139
|
344 Py_RETURN_TRUE;
|
Chris@139
|
345 }
|
Chris@139
|
346
|
Chris@139
|
347 static PyObject *
|
Chris@39
|
348 initialise(PyObject *self, PyObject *args)
|
Chris@0
|
349 {
|
Chris@112
|
350 ssize_t channels, blockSize, stepSize;
|
Chris@0
|
351
|
Chris@23
|
352 if (!PyArg_ParseTuple (args, "nnn",
|
Chris@112
|
353 &channels,
|
Chris@112
|
354 &stepSize,
|
Chris@112
|
355 &blockSize)) {
|
Chris@39
|
356 PyErr_SetString(PyExc_TypeError,
|
Chris@147
|
357 "initialise() takes channel count (int), step size (int), and block size (int) arguments");
|
Chris@39
|
358 return 0;
|
Chris@0
|
359 }
|
Chris@0
|
360
|
Chris@23
|
361 PyPluginObject *pd = getPluginObject(self);
|
Chris@16
|
362 if (!pd) return 0;
|
Chris@0
|
363
|
Chris@16
|
364 pd->channels = channels;
|
Chris@16
|
365 pd->stepSize = stepSize;
|
Chris@16
|
366 pd->blockSize = blockSize;
|
Chris@0
|
367
|
Chris@16
|
368 if (!pd->plugin->initialise(channels, stepSize, blockSize)) {
|
Chris@39
|
369 cerr << "Failed to initialise native plugin adapter with channels = " << channels << ", stepSize = " << stepSize << ", blockSize = " << blockSize << endl;
|
Chris@39
|
370 PyErr_SetString(PyExc_TypeError,
|
Chris@39
|
371 "Plugin initialization failed");
|
Chris@39
|
372 return 0;
|
Chris@6
|
373 }
|
Chris@0
|
374
|
Chris@16
|
375 pd->isInitialised = true;
|
luis@7
|
376
|
Chris@134
|
377 Py_RETURN_TRUE;
|
Chris@0
|
378 }
|
Chris@0
|
379
|
Chris@0
|
380 static PyObject *
|
Chris@39
|
381 reset(PyObject *self, PyObject *)
|
Chris@18
|
382 {
|
Chris@23
|
383 PyPluginObject *pd = getPluginObject(self);
|
Chris@18
|
384 if (!pd) return 0;
|
Chris@18
|
385
|
Chris@134
|
386 if (!pd->isInitialised || !pd->plugin) {
|
Chris@102
|
387 PyErr_SetString(PyExc_Exception,
|
Chris@18
|
388 "Plugin has not been initialised");
|
Chris@18
|
389 return 0;
|
Chris@18
|
390 }
|
Chris@18
|
391
|
Chris@18
|
392 pd->plugin->reset();
|
Chris@134
|
393 Py_RETURN_TRUE;
|
Chris@18
|
394 }
|
Chris@18
|
395
|
Chris@49
|
396 static bool
|
Chris@49
|
397 hasParameter(PyPluginObject *pd, string id)
|
Chris@49
|
398 {
|
Chris@49
|
399 PluginBase::ParameterList pl = pd->plugin->getParameterDescriptors();
|
Chris@49
|
400 for (int i = 0; i < (int)pl.size(); ++i) {
|
Chris@49
|
401 if (pl[i].identifier == id) {
|
Chris@49
|
402 return true;
|
Chris@49
|
403 }
|
Chris@49
|
404 }
|
Chris@49
|
405 return false;
|
Chris@49
|
406 }
|
Chris@49
|
407
|
Chris@18
|
408 static PyObject *
|
Chris@80
|
409 get_parameter_value(PyObject *self, PyObject *args)
|
Chris@20
|
410 {
|
Chris@20
|
411 PyObject *pyParam;
|
Chris@20
|
412
|
Chris@112
|
413 if (!PyArg_ParseTuple(args,
|
Chris@112
|
414 #if (PY_MAJOR_VERSION >= 3)
|
Chris@112
|
415 "U",
|
Chris@112
|
416 #else
|
Chris@112
|
417 "S",
|
Chris@112
|
418 #endif
|
Chris@112
|
419 &pyParam)) {
|
Chris@39
|
420 PyErr_SetString(PyExc_TypeError,
|
Chris@80
|
421 "get_parameter_value() takes parameter id (string) argument");
|
Chris@39
|
422 return 0; }
|
Chris@20
|
423
|
Chris@23
|
424 PyPluginObject *pd = getPluginObject(self);
|
Chris@20
|
425 if (!pd) return 0;
|
Chris@20
|
426
|
Chris@112
|
427 StringConversion strconv;
|
Chris@112
|
428
|
Chris@112
|
429 string param = strconv.py2string(pyParam);
|
Chris@49
|
430
|
Chris@49
|
431 if (!hasParameter(pd, param)) {
|
Chris@102
|
432 PyErr_SetString(PyExc_Exception,
|
Chris@49
|
433 (string("Unknown parameter id \"") + param + "\"").c_str());
|
Chris@49
|
434 return 0;
|
Chris@49
|
435 }
|
Chris@49
|
436
|
Chris@49
|
437 float value = pd->plugin->getParameter(param);
|
Chris@20
|
438 return PyFloat_FromDouble(double(value));
|
Chris@20
|
439 }
|
Chris@20
|
440
|
Chris@20
|
441 static PyObject *
|
Chris@80
|
442 set_parameter_value(PyObject *self, PyObject *args)
|
Chris@20
|
443 {
|
Chris@20
|
444 PyObject *pyParam;
|
Chris@20
|
445 float value;
|
Chris@20
|
446
|
Chris@112
|
447 if (!PyArg_ParseTuple(args,
|
Chris@112
|
448 #if (PY_MAJOR_VERSION >= 3)
|
Chris@112
|
449 "Uf",
|
Chris@112
|
450 #else
|
Chris@112
|
451 "Sf",
|
Chris@112
|
452 #endif
|
Chris@112
|
453 &pyParam, &value)) {
|
Chris@39
|
454 PyErr_SetString(PyExc_TypeError,
|
Chris@80
|
455 "set_parameter_value() takes parameter id (string), and value (float) arguments");
|
Chris@39
|
456 return 0; }
|
Chris@20
|
457
|
Chris@23
|
458 PyPluginObject *pd = getPluginObject(self);
|
Chris@20
|
459 if (!pd) return 0;
|
Chris@20
|
460
|
Chris@112
|
461 StringConversion strconv;
|
Chris@112
|
462
|
Chris@112
|
463 string param = strconv.py2string(pyParam);
|
Chris@49
|
464
|
Chris@49
|
465 if (!hasParameter(pd, param)) {
|
Chris@102
|
466 PyErr_SetString(PyExc_Exception,
|
Chris@49
|
467 (string("Unknown parameter id \"") + param + "\"").c_str());
|
Chris@49
|
468 return 0;
|
Chris@49
|
469 }
|
Chris@49
|
470
|
Chris@49
|
471 pd->plugin->setParameter(param, value);
|
Chris@134
|
472 Py_RETURN_TRUE;
|
Chris@20
|
473 }
|
Chris@20
|
474
|
Chris@39
|
475 static PyObject *
|
Chris@80
|
476 set_parameter_values(PyObject *self, PyObject *args)
|
Chris@48
|
477 {
|
Chris@48
|
478 PyObject *dict;
|
Chris@48
|
479
|
Chris@48
|
480 if (!PyArg_ParseTuple(args, "O", &dict)) {
|
Chris@48
|
481 PyErr_SetString(PyExc_TypeError,
|
Chris@80
|
482 "set_parameter_values() takes dict argument");
|
Chris@134
|
483 return 0;
|
Chris@134
|
484 }
|
Chris@48
|
485
|
Chris@48
|
486 if (!PyDict_Check(dict)) {
|
Chris@48
|
487 PyErr_SetString(PyExc_TypeError,
|
Chris@80
|
488 "set_parameter_values() takes dict argument");
|
Chris@134
|
489 return 0;
|
Chris@134
|
490 }
|
Chris@48
|
491
|
Chris@48
|
492 PyPluginObject *pd = getPluginObject(self);
|
Chris@48
|
493 if (!pd) return 0;
|
Chris@48
|
494
|
Chris@49
|
495 PluginBase::ParameterList pl = pd->plugin->getParameterDescriptors();
|
Chris@49
|
496 set<string> paramIds;
|
Chris@49
|
497 for (int i = 0; i < (int)pl.size(); ++i) {
|
Chris@49
|
498 paramIds.insert(pl[i].identifier);
|
Chris@49
|
499 }
|
Chris@49
|
500
|
Chris@48
|
501 Py_ssize_t pos = 0;
|
Chris@48
|
502 PyObject *key, *value;
|
Chris@48
|
503 while (PyDict_Next(dict, &pos, &key, &value)) {
|
Chris@102
|
504 #if PY_MAJOR_VERSION >= 3
|
Chris@102
|
505 if (!key || !PyUnicode_CheckExact(key)) {
|
Chris@102
|
506 #else
|
Chris@48
|
507 if (!key || !PyString_CheckExact(key)) {
|
Chris@102
|
508 #endif
|
Chris@48
|
509 PyErr_SetString(PyExc_TypeError,
|
Chris@48
|
510 "Parameter dict keys must all have string type");
|
Chris@48
|
511 return 0;
|
Chris@48
|
512 }
|
Chris@48
|
513 if (!value || !FloatConversion::check(value)) {
|
Chris@48
|
514 PyErr_SetString(PyExc_TypeError,
|
Chris@48
|
515 "Parameter dict values must be convertible to float");
|
Chris@48
|
516 return 0;
|
Chris@48
|
517 }
|
Chris@112
|
518 StringConversion strconv;
|
Chris@112
|
519 string param = strconv.py2string(key);
|
Chris@49
|
520 if (paramIds.find(param) == paramIds.end()) {
|
Chris@102
|
521 PyErr_SetString(PyExc_Exception,
|
Chris@49
|
522 (string("Unknown parameter id \"") + param + "\"").c_str());
|
Chris@49
|
523 return 0;
|
Chris@49
|
524 }
|
Chris@49
|
525 pd->plugin->setParameter(param, FloatConversion::convert(value));
|
Chris@48
|
526 }
|
Chris@134
|
527
|
Chris@134
|
528 Py_RETURN_TRUE;
|
Chris@48
|
529 }
|
Chris@48
|
530
|
Chris@48
|
531 static PyObject *
|
Chris@80
|
532 select_program(PyObject *self, PyObject *args)
|
Chris@39
|
533 {
|
Chris@39
|
534 PyObject *pyParam;
|
Chris@39
|
535
|
Chris@112
|
536 if (!PyArg_ParseTuple(args,
|
Chris@112
|
537 #if (PY_MAJOR_VERSION >= 3)
|
Chris@112
|
538 "U",
|
Chris@112
|
539 #else
|
Chris@112
|
540 "S",
|
Chris@112
|
541 #endif
|
Chris@112
|
542 &pyParam)) {
|
Chris@39
|
543 PyErr_SetString(PyExc_TypeError,
|
Chris@80
|
544 "select_program() takes parameter id (string) argument");
|
Chris@134
|
545 return 0;
|
Chris@134
|
546 }
|
Chris@39
|
547
|
Chris@39
|
548 PyPluginObject *pd = getPluginObject(self);
|
Chris@39
|
549 if (!pd) return 0;
|
Chris@39
|
550
|
Chris@112
|
551 StringConversion strconv;
|
Chris@112
|
552
|
Chris@112
|
553 pd->plugin->selectProgram(strconv.py2string(pyParam));
|
Chris@134
|
554 Py_RETURN_TRUE;
|
Chris@39
|
555 }
|
Chris@39
|
556
|
Chris@35
|
557 static
|
Chris@35
|
558 PyObject *
|
Chris@35
|
559 convertFeatureSet(const Plugin::FeatureSet &fs)
|
Chris@35
|
560 {
|
Chris@35
|
561 VectorConversion conv;
|
Chris@35
|
562
|
Chris@35
|
563 PyObject *pyFs = PyDict_New();
|
Chris@35
|
564
|
Chris@35
|
565 for (Plugin::FeatureSet::const_iterator fsi = fs.begin();
|
Chris@35
|
566 fsi != fs.end(); ++fsi) {
|
Chris@35
|
567
|
Chris@35
|
568 int fno = fsi->first;
|
Chris@35
|
569 const Plugin::FeatureList &fl = fsi->second;
|
Chris@35
|
570
|
Chris@35
|
571 if (!fl.empty()) {
|
Chris@35
|
572
|
Chris@35
|
573 PyObject *pyFl = PyList_New(fl.size());
|
Chris@35
|
574
|
Chris@35
|
575 for (int fli = 0; fli < (int)fl.size(); ++fli) {
|
Chris@35
|
576
|
Chris@35
|
577 const Plugin::Feature &f = fl[fli];
|
Chris@35
|
578 PyObject *pyF = PyDict_New();
|
Chris@35
|
579
|
Chris@35
|
580 if (f.hasTimestamp) {
|
Chris@134
|
581 PyObject *rt = PyRealTime_FromRealTime(f.timestamp);
|
Chris@134
|
582 PyDict_SetItemString(pyF, "timestamp", rt);
|
Chris@134
|
583 Py_DECREF(rt);
|
Chris@35
|
584 }
|
Chris@35
|
585 if (f.hasDuration) {
|
Chris@134
|
586 PyObject *rt = PyRealTime_FromRealTime(f.duration);
|
Chris@134
|
587 PyDict_SetItemString(pyF, "duration", rt);
|
Chris@134
|
588 Py_DECREF(rt);
|
Chris@35
|
589 }
|
Chris@35
|
590
|
Chris@112
|
591 StringConversion strconv;
|
Chris@134
|
592
|
Chris@134
|
593 setstring(pyF, "label", f.label);
|
Chris@35
|
594
|
Chris@35
|
595 if (!f.values.empty()) {
|
Chris@134
|
596 PyObject *vv = conv.PyArray_From_FloatVector(f.values);
|
Chris@134
|
597 PyDict_SetItemString(pyF, "values", vv);
|
Chris@134
|
598 Py_DECREF(vv);
|
Chris@35
|
599 }
|
Chris@35
|
600
|
Chris@35
|
601 PyList_SET_ITEM(pyFl, fli, pyF);
|
Chris@35
|
602 }
|
Chris@35
|
603
|
Chris@102
|
604 PyObject *pyN = PyLong_FromLong(fno);
|
Chris@35
|
605 PyDict_SetItem(pyFs, pyN, pyFl);
|
Chris@134
|
606 Py_DECREF(pyN);
|
Chris@134
|
607 Py_DECREF(pyFl);
|
Chris@35
|
608 }
|
Chris@35
|
609 }
|
Chris@35
|
610
|
Chris@35
|
611 return pyFs;
|
Chris@35
|
612 }
|
Chris@35
|
613
|
Chris@40
|
614 static vector<vector<float> >
|
Chris@40
|
615 convertPluginInput(PyObject *pyBuffer, int channels, int blockSize)
|
Chris@40
|
616 {
|
Chris@40
|
617 vector<vector<float> > data;
|
Chris@40
|
618
|
Chris@40
|
619 VectorConversion conv;
|
Chris@40
|
620
|
Chris@40
|
621 if (PyArray_CheckExact(pyBuffer)) {
|
Chris@40
|
622
|
Chris@40
|
623 data = conv.Py2DArray_To_FloatVector(pyBuffer);
|
Chris@40
|
624
|
Chris@40
|
625 if (conv.error) {
|
Chris@40
|
626 PyErr_SetString(PyExc_TypeError, conv.getError().str().c_str());
|
Chris@40
|
627 return data;
|
Chris@40
|
628 }
|
Chris@40
|
629
|
Chris@41
|
630 if ((int)data.size() != channels) {
|
Chris@41
|
631 // cerr << "Wrong number of channels: got " << data.size() << ", expected " << channels << endl;
|
Chris@41
|
632 PyErr_SetString(PyExc_TypeError, "Wrong number of channels");
|
Chris@41
|
633 return vector<vector<float> >();
|
Chris@41
|
634 }
|
Chris@41
|
635
|
Chris@40
|
636 } else {
|
Chris@40
|
637
|
Chris@40
|
638 if (!PyList_Check(pyBuffer)) {
|
Chris@43
|
639 PyErr_SetString(PyExc_TypeError, "List of NumPy arrays or lists of numbers required for process input");
|
Chris@40
|
640 return data;
|
Chris@40
|
641 }
|
Chris@43
|
642
|
Chris@40
|
643 if (PyList_GET_SIZE(pyBuffer) != channels) {
|
Chris@41
|
644 // cerr << "Wrong number of channels: got " << PyList_GET_SIZE(pyBuffer) << ", expected " << channels << endl;
|
Chris@40
|
645 PyErr_SetString(PyExc_TypeError, "Wrong number of channels");
|
Chris@40
|
646 return data;
|
Chris@40
|
647 }
|
Chris@40
|
648
|
Chris@40
|
649 for (int c = 0; c < channels; ++c) {
|
Chris@40
|
650 PyObject *cbuf = PyList_GET_ITEM(pyBuffer, c);
|
Chris@40
|
651 data.push_back(conv.PyValue_To_FloatVector(cbuf));
|
Chris@43
|
652 if (conv.error) {
|
Chris@43
|
653 PyErr_SetString(PyExc_TypeError, conv.getError().str().c_str());
|
Chris@43
|
654 return vector<vector<float> >();
|
Chris@43
|
655 }
|
Chris@40
|
656 }
|
Chris@41
|
657 }
|
Chris@40
|
658
|
Chris@41
|
659 for (int c = 0; c < channels; ++c) {
|
Chris@41
|
660 if ((int)data[c].size() != blockSize) {
|
Chris@41
|
661 // cerr << "Wrong number of samples on channel " << c << ": expected " << blockSize << " (plugin's block size), got " << data[c].size() << endl;
|
Chris@46
|
662 PyErr_SetString(PyExc_TypeError, "Wrong number of samples for process block");
|
Chris@41
|
663 return vector<vector<float> >();
|
Chris@40
|
664 }
|
Chris@40
|
665 }
|
Chris@40
|
666
|
Chris@40
|
667 return data;
|
Chris@40
|
668 }
|
Chris@40
|
669
|
Chris@20
|
670 static PyObject *
|
Chris@80
|
671 process_block(PyObject *self, PyObject *args)
|
Chris@0
|
672 {
|
Chris@0
|
673 PyObject *pyBuffer;
|
Chris@0
|
674 PyObject *pyRealTime;
|
Chris@0
|
675
|
Chris@23
|
676 if (!PyArg_ParseTuple(args, "OO",
|
Chris@39
|
677 &pyBuffer, // Audio data
|
Chris@39
|
678 &pyRealTime)) { // TimeStamp
|
Chris@39
|
679 PyErr_SetString(PyExc_TypeError,
|
Chris@80
|
680 "process_block() takes buffer (2D array or list of arrays, one row per channel) and timestamp (RealTime) arguments");
|
Chris@39
|
681 return 0; }
|
Chris@0
|
682
|
Chris@0
|
683 if (!PyRealTime_Check(pyRealTime)) {
|
Chris@40
|
684 PyErr_SetString(PyExc_TypeError, "Valid timestamp required.");
|
Chris@39
|
685 return 0; }
|
Chris@0
|
686
|
Chris@23
|
687 PyPluginObject *pd = getPluginObject(self);
|
Chris@16
|
688 if (!pd) return 0;
|
Chris@0
|
689
|
Chris@0
|
690 if (!pd->isInitialised) {
|
Chris@102
|
691 PyErr_SetString(PyExc_Exception,
|
Chris@39
|
692 "Plugin has not been initialised.");
|
Chris@39
|
693 return 0;
|
Chris@16
|
694 }
|
Chris@0
|
695
|
Chris@40
|
696 int channels = pd->channels;
|
Chris@40
|
697 vector<vector<float> > data =
|
Chris@40
|
698 convertPluginInput(pyBuffer, channels, pd->blockSize);
|
Chris@40
|
699 if (data.empty()) return 0;
|
Chris@0
|
700
|
Chris@4
|
701 float **inbuf = new float *[channels];
|
Chris@4
|
702 for (int c = 0; c < channels; ++c) {
|
Chris@12
|
703 inbuf[c] = &data[c][0];
|
Chris@4
|
704 }
|
Chris@12
|
705 RealTime timeStamp = *PyRealTime_AsRealTime(pyRealTime);
|
Chris@18
|
706 Plugin::FeatureSet fs = pd->plugin->process(inbuf, timeStamp);
|
Chris@4
|
707 delete[] inbuf;
|
Chris@0
|
708
|
Chris@35
|
709 return convertFeatureSet(fs);
|
Chris@35
|
710 }
|
Chris@0
|
711
|
Chris@35
|
712 static PyObject *
|
Chris@80
|
713 get_remaining_features(PyObject *self, PyObject *)
|
Chris@35
|
714 {
|
Chris@35
|
715 PyPluginObject *pd = getPluginObject(self);
|
Chris@35
|
716 if (!pd) return 0;
|
Chris@18
|
717
|
Chris@35
|
718 if (!pd->isInitialised) {
|
Chris@102
|
719 PyErr_SetString(PyExc_Exception,
|
Chris@39
|
720 "Plugin has not been initialised.");
|
Chris@39
|
721 return 0;
|
Chris@35
|
722 }
|
Chris@18
|
723
|
Chris@35
|
724 Plugin::FeatureSet fs = pd->plugin->getRemainingFeatures();
|
Chris@18
|
725
|
Chris@35
|
726 return convertFeatureSet(fs);
|
Chris@0
|
727 }
|
Chris@0
|
728
|
Chris@23
|
729 static PyObject *
|
Chris@80
|
730 get_preferred_block_size(PyObject *self, PyObject *)
|
Chris@37
|
731 {
|
Chris@37
|
732 PyPluginObject *pd = getPluginObject(self);
|
Chris@37
|
733 if (!pd) return 0;
|
Chris@102
|
734 return PyLong_FromLong(pd->plugin->getPreferredBlockSize());
|
Chris@37
|
735 }
|
Chris@37
|
736
|
Chris@37
|
737 static PyObject *
|
Chris@80
|
738 get_preferred_step_size(PyObject *self, PyObject *)
|
Chris@37
|
739 {
|
Chris@37
|
740 PyPluginObject *pd = getPluginObject(self);
|
Chris@37
|
741 if (!pd) return 0;
|
Chris@102
|
742 return PyLong_FromLong(pd->plugin->getPreferredStepSize());
|
Chris@37
|
743 }
|
Chris@37
|
744
|
Chris@37
|
745 static PyObject *
|
Chris@80
|
746 get_min_channel_count(PyObject *self, PyObject *)
|
Chris@37
|
747 {
|
Chris@37
|
748 PyPluginObject *pd = getPluginObject(self);
|
Chris@37
|
749 if (!pd) return 0;
|
Chris@102
|
750 return PyLong_FromLong(pd->plugin->getMinChannelCount());
|
Chris@37
|
751 }
|
Chris@37
|
752
|
Chris@37
|
753 static PyObject *
|
Chris@80
|
754 get_max_channel_count(PyObject *self, PyObject *)
|
Chris@37
|
755 {
|
Chris@37
|
756 PyPluginObject *pd = getPluginObject(self);
|
Chris@37
|
757 if (!pd) return 0;
|
Chris@102
|
758 return PyLong_FromLong(pd->plugin->getMaxChannelCount());
|
Chris@37
|
759 }
|
Chris@37
|
760
|
Chris@37
|
761 static PyObject *
|
Chris@39
|
762 unload(PyObject *self, PyObject *)
|
Chris@23
|
763 {
|
Chris@23
|
764 PyPluginObject *pd = getPluginObject(self);
|
Chris@23
|
765 if (!pd) return 0;
|
Chris@23
|
766
|
Chris@115
|
767 // cerr << "unload: unloading plugin object " << pd << ", plugin " << pd->plugin << endl;
|
Chris@115
|
768
|
Chris@23
|
769 delete pd->plugin;
|
Chris@32
|
770 pd->plugin = 0; // This is checked by getPluginObject, so we avoid
|
Chris@32
|
771 // blowing up if called repeatedly
|
Chris@23
|
772
|
Chris@134
|
773 Py_RETURN_TRUE;
|
Chris@23
|
774 }
|
Chris@23
|
775
|
Chris@33
|
776 static PyMemberDef PyPluginObject_members[] =
|
Chris@33
|
777 {
|
Chris@34
|
778 {(char *)"info", T_OBJECT, offsetof(PyPluginObject, info), READONLY,
|
Chris@39
|
779 (char *)"info -> A read-only dictionary of plugin metadata."},
|
Chris@34
|
780
|
Chris@110
|
781 {(char *)"inputDomain", T_INT, offsetof(PyPluginObject, inputDomain), READONLY,
|
Chris@110
|
782 (char *)"inputDomain -> The format of input audio required by the plugin, either vampyhost.TIME_DOMAIN or vampyhost.FREQUENCY_DOMAIN."},
|
Chris@34
|
783
|
Chris@34
|
784 {(char *)"parameters", T_OBJECT, offsetof(PyPluginObject, parameters), READONLY,
|
Chris@39
|
785 (char *)"parameters -> A list of metadata dictionaries describing the plugin's configurable parameters."},
|
Chris@39
|
786
|
Chris@39
|
787 {(char *)"programs", T_OBJECT, offsetof(PyPluginObject, programs), READONLY,
|
Chris@39
|
788 (char *)"programs -> A list of the programs available for this plugin, if any."},
|
Chris@33
|
789
|
Chris@33
|
790 {0, 0}
|
Chris@33
|
791 };
|
Chris@33
|
792
|
Chris@21
|
793 static PyMethodDef PyPluginObject_methods[] =
|
Chris@21
|
794 {
|
Chris@80
|
795 {"get_outputs", get_outputs, METH_NOARGS,
|
Chris@80
|
796 "get_outputs() -> Obtain the output descriptors for all of the plugin's outputs."},
|
Chris@37
|
797
|
Chris@86
|
798 {"get_output", get_output, METH_VARARGS,
|
Chris@86
|
799 "get_output(out) -> Obtain the output descriptor for a single output, by either id (string) or index (int)."},
|
Chris@86
|
800
|
Chris@80
|
801 {"get_parameter_value", get_parameter_value, METH_VARARGS,
|
Chris@80
|
802 "get_parameter_value(identifier) -> Return the value of the parameter with the given identifier."},
|
Chris@23
|
803
|
Chris@80
|
804 {"set_parameter_value", set_parameter_value, METH_VARARGS,
|
Chris@80
|
805 "set_parameter_value(identifier, value) -> Set the parameter with the given identifier to the given value."},
|
Chris@37
|
806
|
Chris@80
|
807 {"set_parameter_values", set_parameter_values, METH_VARARGS,
|
Chris@80
|
808 "set_parameter_values(dict) -> Set multiple parameters to values corresponding to the key/value pairs in the dict. Any parameters not mentioned in the dict are unchanged."},
|
Chris@139
|
809
|
Chris@80
|
810 {"select_program", select_program, METH_VARARGS,
|
Chris@80
|
811 "select_program(name) -> Select the processing program with the given name."},
|
Chris@39
|
812
|
Chris@80
|
813 {"get_preferred_block_size", get_preferred_block_size, METH_VARARGS,
|
Chris@80
|
814 "get_preferred_block_size() -> Return the plugin's preferred processing block size, or 0 if the plugin accepts any block size."},
|
Chris@37
|
815
|
Chris@80
|
816 {"get_preferred_step_size", get_preferred_step_size, METH_VARARGS,
|
Chris@80
|
817 "get_preferred_step_size() -> Return the plugin's preferred processing step size, or 0 if the plugin allows the host to select. If this is 0, the host should normally choose the same step as block size for time-domain plugins, or half the block size for frequency-domain plugins."},
|
Chris@37
|
818
|
Chris@80
|
819 {"get_min_channel_count", get_min_channel_count, METH_VARARGS,
|
Chris@80
|
820 "get_min_channel_count() -> Return the minimum number of channels of audio data the plugin accepts as input."},
|
Chris@37
|
821
|
Chris@80
|
822 {"get_max_channel_count", get_max_channel_count, METH_VARARGS,
|
Chris@80
|
823 "get_max_channel_count() -> Return the maximum number of channels of audio data the plugin accepts as input."},
|
Chris@139
|
824
|
Chris@139
|
825 {"set_process_timestamp_method", set_process_timestamp_method, METH_VARARGS,
|
Chris@139
|
826 "set_process_timestamp_method(method) -> Set the method used for timestamp adjustment in plugins using frequency-domain input, where that input is being automatically converted for a plugin loaded with the ADAPT_INPUT_DOMAIN flag set (or one of ADAPT_ALL_SAFE or ADAPT_ALL). The method must be one of SHIFT_TIMESTAMP, SHIFT_DATA, or NO_SHIFT. The default is SHIFT_TIMESTAMP."},
|
Chris@33
|
827
|
Chris@39
|
828 {"initialise", initialise, METH_VARARGS,
|
Chris@80
|
829 "initialise(channels, stepSize, blockSize) -> Initialise the plugin for the given number of channels and processing frame sizes. This must be called before process_block() can be used."},
|
Chris@23
|
830
|
Chris@39
|
831 {"reset", reset, METH_NOARGS,
|
Chris@39
|
832 "reset() -> Reset the plugin after processing, to prepare for another processing run with the same parameters."},
|
Chris@23
|
833
|
Chris@80
|
834 {"process_block", process_block, METH_VARARGS,
|
Chris@80
|
835 "process_block(block, timestamp) -> Provide one processing frame to the plugin, with its timestamp, and obtain any features that were extracted immediately from this frame."},
|
Chris@23
|
836
|
Chris@80
|
837 {"get_remaining_features", get_remaining_features, METH_NOARGS,
|
Chris@80
|
838 "get_remaining_features() -> Obtain any features extracted at the end of processing."},
|
Chris@35
|
839
|
Chris@39
|
840 {"unload", unload, METH_NOARGS,
|
Chris@39
|
841 "unload() -> Dispose of the plugin. You cannot use the plugin object again after calling this. Note that unloading also happens automatically when the plugin object's reference count reaches zero; this function is only necessary if you wish to ensure the native part of the plugin is disposed of before then."},
|
Chris@23
|
842
|
Chris@21
|
843 {0, 0}
|
Chris@21
|
844 };
|
Chris@21
|
845
|
Chris@21
|
846 /* Doc:: 10.3 Type Objects */ /* static */
|
Chris@21
|
847 PyTypeObject Plugin_Type =
|
Chris@21
|
848 {
|
Chris@112
|
849 PyVarObject_HEAD_INIT(NULL, 0)
|
Chris@39
|
850 "vampyhost.Plugin", /*tp_name*/
|
Chris@39
|
851 sizeof(PyPluginObject), /*tp_basicsize*/
|
Chris@39
|
852 0, /*tp_itemsize*/
|
Chris@21
|
853 (destructor)PyPluginObject_dealloc, /*tp_dealloc*/
|
Chris@39
|
854 0, /*tp_print*/
|
Chris@39
|
855 0, /*tp_getattr*/
|
Chris@39
|
856 0, /*tp_setattr*/
|
Chris@39
|
857 0, /*tp_compare*/
|
Chris@39
|
858 0, /*tp_repr*/
|
Chris@39
|
859 0, /*tp_as_number*/
|
Chris@39
|
860 0, /*tp_as_sequence*/
|
Chris@39
|
861 0, /*tp_as_mapping*/
|
Chris@39
|
862 0, /*tp_hash*/
|
Chris@39
|
863 0, /*tp_call*/
|
Chris@39
|
864 0, /*tp_str*/
|
Chris@39
|
865 PyObject_GenericGetAttr, /*tp_getattro*/
|
Chris@39
|
866 PyObject_GenericSetAttr, /*tp_setattro*/
|
Chris@39
|
867 0, /*tp_as_buffer*/
|
Chris@39
|
868 Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
Chris@40
|
869 "Plugin object, providing a low-level API for running a Vamp plugin.", /*tp_doc*/
|
Chris@39
|
870 0, /*tp_traverse*/
|
Chris@39
|
871 0, /*tp_clear*/
|
Chris@39
|
872 0, /*tp_richcompare*/
|
Chris@39
|
873 0, /*tp_weaklistoffset*/
|
Chris@39
|
874 0, /*tp_iter*/
|
Chris@39
|
875 0, /*tp_iternext*/
|
Chris@39
|
876 PyPluginObject_methods, /*tp_methods*/
|
Chris@39
|
877 PyPluginObject_members, /*tp_members*/
|
Chris@39
|
878 0, /*tp_getset*/
|
Chris@39
|
879 0, /*tp_base*/
|
Chris@39
|
880 0, /*tp_dict*/
|
Chris@39
|
881 0, /*tp_descr_get*/
|
Chris@39
|
882 0, /*tp_descr_set*/
|
Chris@39
|
883 0, /*tp_dictoffset*/
|
Chris@39
|
884 0, /*tp_init*/
|
Chris@124
|
885 0, /*tp_alloc*/
|
Chris@39
|
886 0, /*tp_new*/
|
Chris@124
|
887 0, /*tp_free*/
|
Chris@39
|
888 0, /*tp_is_gc*/
|
Chris@21
|
889 };
|
Chris@0
|
890
|