Mercurial > hg > vampy-host
comparison PyPluginObject.cpp @ 48:0e0e18629917
Set parameters in bulk
author | Chris Cannam |
---|---|
date | Tue, 13 Jan 2015 11:57:06 +0000 |
parents | 1cb0ed230b71 |
children | d4a3cd9dcf2c |
comparison
equal
deleted
inserted
replaced
47:1cb0ed230b71 | 48:0e0e18629917 |
---|---|
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" | 46 #include "structmember.h" |
47 | 47 |
48 #include "FloatConversion.h" | |
48 #include "VectorConversion.h" | 49 #include "VectorConversion.h" |
49 #include "PyRealTime.h" | 50 #include "PyRealTime.h" |
50 | 51 |
51 #include <string> | 52 #include <string> |
52 #include <vector> | 53 #include <vector> |
270 pd->plugin->reset(); | 271 pd->plugin->reset(); |
271 return Py_True; | 272 return Py_True; |
272 } | 273 } |
273 | 274 |
274 static PyObject * | 275 static PyObject * |
275 getParameter(PyObject *self, PyObject *args) | 276 getParameterValue(PyObject *self, PyObject *args) |
276 { | 277 { |
277 PyObject *pyParam; | 278 PyObject *pyParam; |
278 | 279 |
279 if (!PyArg_ParseTuple(args, "S", &pyParam)) { | 280 if (!PyArg_ParseTuple(args, "S", &pyParam)) { |
280 PyErr_SetString(PyExc_TypeError, | 281 PyErr_SetString(PyExc_TypeError, |
281 "getParameter() takes parameter id (string) argument"); | 282 "getParameterValue() takes parameter id (string) argument"); |
282 return 0; } | 283 return 0; } |
283 | 284 |
284 PyPluginObject *pd = getPluginObject(self); | 285 PyPluginObject *pd = getPluginObject(self); |
285 if (!pd) return 0; | 286 if (!pd) return 0; |
286 | 287 |
287 float value = pd->plugin->getParameter(PyString_AS_STRING(pyParam)); | 288 float value = pd->plugin->getParameter(PyString_AS_STRING(pyParam)); |
288 return PyFloat_FromDouble(double(value)); | 289 return PyFloat_FromDouble(double(value)); |
289 } | 290 } |
290 | 291 |
291 static PyObject * | 292 static PyObject * |
292 setParameter(PyObject *self, PyObject *args) | 293 setParameterValue(PyObject *self, PyObject *args) |
293 { | 294 { |
294 PyObject *pyParam; | 295 PyObject *pyParam; |
295 float value; | 296 float value; |
296 | 297 |
297 if (!PyArg_ParseTuple(args, "Sf", &pyParam, &value)) { | 298 if (!PyArg_ParseTuple(args, "Sf", &pyParam, &value)) { |
298 PyErr_SetString(PyExc_TypeError, | 299 PyErr_SetString(PyExc_TypeError, |
299 "setParameter() takes parameter id (string), and value (float) arguments"); | 300 "setParameterValue() takes parameter id (string), and value (float) arguments"); |
300 return 0; } | 301 return 0; } |
301 | 302 |
302 PyPluginObject *pd = getPluginObject(self); | 303 PyPluginObject *pd = getPluginObject(self); |
303 if (!pd) return 0; | 304 if (!pd) return 0; |
304 | 305 |
305 pd->plugin->setParameter(PyString_AS_STRING(pyParam), value); | 306 pd->plugin->setParameter(PyString_AS_STRING(pyParam), value); |
307 return Py_True; | |
308 } | |
309 | |
310 static PyObject * | |
311 setParameterValues(PyObject *self, PyObject *args) | |
312 { | |
313 PyObject *dict; | |
314 | |
315 if (!PyArg_ParseTuple(args, "O", &dict)) { | |
316 PyErr_SetString(PyExc_TypeError, | |
317 "setParameterValues() takes dict argument"); | |
318 return 0; } | |
319 | |
320 if (!PyDict_Check(dict)) { | |
321 PyErr_SetString(PyExc_TypeError, | |
322 "setParameterValues() takes dict argument"); | |
323 return 0; } | |
324 | |
325 PyPluginObject *pd = getPluginObject(self); | |
326 if (!pd) return 0; | |
327 | |
328 Py_ssize_t pos = 0; | |
329 PyObject *key, *value; | |
330 while (PyDict_Next(dict, &pos, &key, &value)) { | |
331 if (!key || !PyString_CheckExact(key)) { | |
332 PyErr_SetString(PyExc_TypeError, | |
333 "Parameter dict keys must all have string type"); | |
334 return 0; | |
335 } | |
336 if (!value || !FloatConversion::check(value)) { | |
337 PyErr_SetString(PyExc_TypeError, | |
338 "Parameter dict values must be convertible to float"); | |
339 return 0; | |
340 } | |
341 pd->plugin->setParameter(PyString_AS_STRING(key), | |
342 FloatConversion::convert(value)); | |
343 } | |
344 | |
306 return Py_True; | 345 return Py_True; |
307 } | 346 } |
308 | 347 |
309 static PyObject * | 348 static PyObject * |
310 selectProgram(PyObject *self, PyObject *args) | 349 selectProgram(PyObject *self, PyObject *args) |
554 static PyMethodDef PyPluginObject_methods[] = | 593 static PyMethodDef PyPluginObject_methods[] = |
555 { | 594 { |
556 {"getOutputs", getOutputs, METH_NOARGS, | 595 {"getOutputs", getOutputs, METH_NOARGS, |
557 "getOutputs() -> Obtain the output descriptors for all of the plugin's outputs."}, | 596 "getOutputs() -> Obtain the output descriptors for all of the plugin's outputs."}, |
558 | 597 |
559 {"getParameterValue", getParameter, METH_VARARGS, | 598 {"getParameterValue", getParameterValue, METH_VARARGS, |
560 "getParameterValue(identifier) -> Return the value of the parameter with the given identifier."}, | 599 "getParameterValue(identifier) -> Return the value of the parameter with the given identifier."}, |
561 | 600 |
562 {"setParameterValue", setParameter, METH_VARARGS, | 601 {"setParameterValue", setParameterValue, METH_VARARGS, |
563 "setParameterValue(identifier, value) -> Set the parameter with the given identifier to the given value."}, | 602 "setParameterValue(identifier, value) -> Set the parameter with the given identifier to the given value."}, |
603 | |
604 {"setParameterValues", setParameterValues, METH_VARARGS, | |
605 "setParameterValues(dict) -> Set multiple parameters to values corresponding to the key/value pairs in the dict. Any parameters not mentioned in the dict are unchanged."}, | |
564 | 606 |
565 {"selectProgram", selectProgram, METH_VARARGS, | 607 {"selectProgram", selectProgram, METH_VARARGS, |
566 "selectProgram(name) -> Select the processing program with the given name."}, | 608 "selectProgram(name) -> Select the processing program with the given name."}, |
567 | 609 |
568 {"getPreferredBlockSize", getPreferredBlockSize, METH_VARARGS, | 610 {"getPreferredBlockSize", getPreferredBlockSize, METH_VARARGS, |