Mercurial > hg > vampy-host
comparison native/PyPluginObject.cpp @ 86:78844c4b329c
Add get_output
author | Chris Cannam |
---|---|
date | Wed, 21 Jan 2015 14:03:43 +0000 |
parents | fbd084b81ece |
children | dd56716714e0 |
comparison
equal
deleted
inserted
replaced
85:02956a88ee58 | 86:78844c4b329c |
---|---|
169 delete self->plugin; | 169 delete self->plugin; |
170 PyObject_Del(self); | 170 PyObject_Del(self); |
171 } | 171 } |
172 | 172 |
173 static PyObject * | 173 static PyObject * |
174 convertOutput(const Plugin::OutputDescriptor &desc) | |
175 { | |
176 PyObject *outdict = PyDict_New(); | |
177 PyDict_SetItemString | |
178 (outdict, "identifier", pystr(desc.identifier)); | |
179 PyDict_SetItemString | |
180 (outdict, "name", pystr(desc.name)); | |
181 PyDict_SetItemString | |
182 (outdict, "description", pystr(desc.description)); | |
183 PyDict_SetItemString | |
184 (outdict, "bin_count", PyInt_FromLong(desc.binCount)); | |
185 if (desc.binCount > 0) { | |
186 if (desc.hasKnownExtents) { | |
187 PyDict_SetItemString | |
188 (outdict, "has_known_extents", Py_True); | |
189 PyDict_SetItemString | |
190 (outdict, "min_value", PyFloat_FromDouble(desc.minValue)); | |
191 PyDict_SetItemString | |
192 (outdict, "max_value", PyFloat_FromDouble(desc.maxValue)); | |
193 } else { | |
194 PyDict_SetItemString | |
195 (outdict, "has_known_extents", Py_False); | |
196 } | |
197 if (desc.isQuantized) { | |
198 PyDict_SetItemString | |
199 (outdict, "is_quantized", Py_True); | |
200 PyDict_SetItemString | |
201 (outdict, "quantize_step", PyFloat_FromDouble(desc.quantizeStep)); | |
202 } else { | |
203 PyDict_SetItemString | |
204 (outdict, "is_quantized", Py_False); | |
205 } | |
206 } | |
207 PyDict_SetItemString | |
208 (outdict, "sample_type", PyInt_FromLong((int)desc.sampleType)); | |
209 PyDict_SetItemString | |
210 (outdict, "sample_rate", PyFloat_FromDouble(desc.sampleRate)); | |
211 PyDict_SetItemString | |
212 (outdict, "has_duration", desc.hasDuration ? Py_True : Py_False); | |
213 return outdict; | |
214 } | |
215 | |
216 static PyObject * | |
217 get_output(PyObject *self, PyObject *args) | |
218 { | |
219 PyPluginObject *pd = getPluginObject(self); | |
220 if (!pd) return 0; | |
221 | |
222 int n = -1; | |
223 PyObject *pyId = 0; | |
224 | |
225 if (!PyArg_ParseTuple(args, "n", &n) && | |
226 !PyArg_ParseTuple(args, "S", &pyId)) { | |
227 PyErr_SetString(PyExc_TypeError, | |
228 "get_output takes either output id (string) or output index (int) argument"); | |
229 return 0; | |
230 } | |
231 | |
232 Plugin::OutputList ol = pd->plugin->getOutputDescriptors(); | |
233 | |
234 if (pyId) { | |
235 string id = PyString_AS_STRING(pyId); | |
236 for (int i = 0; i < int(ol.size()); ++i) { | |
237 if (ol[i].identifier == id) { | |
238 return convertOutput(ol[i]); | |
239 } | |
240 } | |
241 } else { | |
242 if (n >= 0 && n < int(ol.size())) { | |
243 return convertOutput(ol[n]); | |
244 } | |
245 } | |
246 | |
247 PyErr_SetString(PyExc_StandardError, | |
248 "unknown output id or output index out of range"); | |
249 return 0; | |
250 } | |
251 | |
252 static PyObject * | |
174 get_outputs(PyObject *self, PyObject *args) | 253 get_outputs(PyObject *self, PyObject *args) |
175 { | 254 { |
176 PyPluginObject *pd = getPluginObject(self); | 255 PyPluginObject *pd = getPluginObject(self); |
177 if (!pd) return 0; | 256 if (!pd) return 0; |
178 Plugin::OutputList ol = pd->plugin->getOutputDescriptors(); | 257 Plugin::OutputList ol = pd->plugin->getOutputDescriptors(); |
179 PyObject *outputs = PyList_New(ol.size()); | 258 PyObject *outputs = PyList_New(ol.size()); |
180 | 259 |
181 for (int i = 0; i < (int)ol.size(); ++i) { | 260 for (int i = 0; i < (int)ol.size(); ++i) { |
182 PyObject *outdict = PyDict_New(); | 261 PyObject *outdict = convertOutput(ol[i]); |
183 PyDict_SetItemString | |
184 (outdict, "identifier", pystr(ol[i].identifier)); | |
185 PyDict_SetItemString | |
186 (outdict, "name", pystr(ol[i].name)); | |
187 PyDict_SetItemString | |
188 (outdict, "description", pystr(ol[i].description)); | |
189 PyDict_SetItemString | |
190 (outdict, "bin_count", PyInt_FromLong(ol[i].binCount)); | |
191 if (ol[i].binCount > 0) { | |
192 if (ol[i].hasKnownExtents) { | |
193 PyDict_SetItemString | |
194 (outdict, "has_known_extents", Py_True); | |
195 PyDict_SetItemString | |
196 (outdict, "min_value", PyFloat_FromDouble(ol[i].minValue)); | |
197 PyDict_SetItemString | |
198 (outdict, "max_value", PyFloat_FromDouble(ol[i].maxValue)); | |
199 } else { | |
200 PyDict_SetItemString | |
201 (outdict, "has_known_extents", Py_False); | |
202 } | |
203 if (ol[i].isQuantized) { | |
204 PyDict_SetItemString | |
205 (outdict, "is_quantized", Py_True); | |
206 PyDict_SetItemString | |
207 (outdict, "quantize_step", PyFloat_FromDouble(ol[i].quantizeStep)); | |
208 } else { | |
209 PyDict_SetItemString | |
210 (outdict, "is_quantized", Py_False); | |
211 } | |
212 } | |
213 PyDict_SetItemString | |
214 (outdict, "sample_type", PyInt_FromLong((int)ol[i].sampleType)); | |
215 PyDict_SetItemString | |
216 (outdict, "sample_rate", PyFloat_FromDouble(ol[i].sampleRate)); | |
217 PyDict_SetItemString | |
218 (outdict, "has_duration", ol[i].hasDuration ? Py_True : Py_False); | |
219 | |
220 PyList_SET_ITEM(outputs, i, outdict); | 262 PyList_SET_ITEM(outputs, i, outdict); |
221 } | 263 } |
222 | 264 |
223 return outputs; | 265 return outputs; |
224 } | 266 } |
631 | 673 |
632 static PyMethodDef PyPluginObject_methods[] = | 674 static PyMethodDef PyPluginObject_methods[] = |
633 { | 675 { |
634 {"get_outputs", get_outputs, METH_NOARGS, | 676 {"get_outputs", get_outputs, METH_NOARGS, |
635 "get_outputs() -> Obtain the output descriptors for all of the plugin's outputs."}, | 677 "get_outputs() -> Obtain the output descriptors for all of the plugin's outputs."}, |
678 | |
679 {"get_output", get_output, METH_VARARGS, | |
680 "get_output(out) -> Obtain the output descriptor for a single output, by either id (string) or index (int)."}, | |
636 | 681 |
637 {"get_parameter_value", get_parameter_value, METH_VARARGS, | 682 {"get_parameter_value", get_parameter_value, METH_VARARGS, |
638 "get_parameter_value(identifier) -> Return the value of the parameter with the given identifier."}, | 683 "get_parameter_value(identifier) -> Return the value of the parameter with the given identifier."}, |
639 | 684 |
640 {"set_parameter_value", set_parameter_value, METH_VARARGS, | 685 {"set_parameter_value", set_parameter_value, METH_VARARGS, |