Mercurial > hg > vampy
comparison PyPlugin.h @ 71:40a01bb24209 vampyhost
Pull apart some type conversion classes for possible use in VamPy Host
author | Chris Cannam |
---|---|
date | Thu, 20 Nov 2014 13:02:50 +0000 |
parents | 146d14ab15e7 |
children | ffaa1fb3d7de |
comparison
equal
deleted
inserted
replaced
70:6c755f3e1173 | 71:40a01bb24209 |
---|---|
5 | 5 |
6 * Centre for Digital Music, Queen Mary University of London. | 6 * Centre for Digital Music, Queen Mary University of London. |
7 * Copyright (C) 2008-2009 Gyorgy Fazekas, QMUL. (See Vamp sources | 7 * Copyright (C) 2008-2009 Gyorgy Fazekas, QMUL. (See Vamp sources |
8 * for licence information.) | 8 * for licence information.) |
9 | 9 |
10 */ | |
11 | |
12 /* | |
13 Vamp | |
14 | |
15 An API for audio analysis and feature extraction plugins. | |
16 | |
17 Centre for Digital Music, Queen Mary, University of London. | |
18 Copyright 2006 Chris Cannam. | |
19 | |
20 Permission is hereby granted, free of charge, to any person | |
21 obtaining a copy of this software and associated documentation | |
22 files (the "Software"), to deal in the Software without | |
23 restriction, including without limitation the rights to use, copy, | |
24 modify, merge, publish, distribute, sublicense, and/or sell copies | |
25 of the Software, and to permit persons to whom the Software is | |
26 furnished to do so, subject to the following conditions: | |
27 | |
28 The above copyright notice and this permission notice shall be | |
29 included in all copies or substantial portions of the Software. | |
30 | |
31 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
32 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
33 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
34 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | |
35 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
36 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
37 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
38 | |
39 Except as contained in this notice, the names of the Centre for | |
40 Digital Music; Queen Mary, University of London; and Chris Cannam | |
41 shall not be used in advertising or otherwise to promote the sale, | |
42 use or other dealings in this Software without prior written | |
43 authorization. | |
44 */ | 10 */ |
45 | 11 |
46 #ifndef _PYTHON_WRAPPER_PLUGIN_H_ | 12 #ifndef _PYTHON_WRAPPER_PLUGIN_H_ |
47 #define _PYTHON_WRAPPER_PLUGIN_H_ | 13 #define _PYTHON_WRAPPER_PLUGIN_H_ |
48 | 14 |
53 #define FLAG_VALUE "Flag: " << flagName << ": " << ((rValue==0)?"False":"True") | 19 #define FLAG_VALUE "Flag: " << flagName << ": " << ((rValue==0)?"False":"True") |
54 | 20 |
55 #include <Python.h> | 21 #include <Python.h> |
56 #include "PyExtensionModule.h" | 22 #include "PyExtensionModule.h" |
57 #include "PyTypeInterface.h" | 23 #include "PyTypeInterface.h" |
24 #include "PyTypeConversions.h" | |
58 #include "vamp-sdk/Plugin.h" | 25 #include "vamp-sdk/Plugin.h" |
59 #include "Mutex.h" | 26 #include "Mutex.h" |
60 | 27 |
61 using std::string; | 28 using std::string; |
62 using std::cerr; | 29 using std::cerr; |
115 std::string m_path; | 82 std::string m_path; |
116 eProcessType m_processType; | 83 eProcessType m_processType; |
117 PyObject *m_pyProcess; | 84 PyObject *m_pyProcess; |
118 PyObject *m_pyProcessCallable; | 85 PyObject *m_pyProcessCallable; |
119 mutable InputDomain m_inputDomain; | 86 mutable InputDomain m_inputDomain; |
87 PyTypeConversions m_tc; | |
120 PyTypeInterface m_ti; | 88 PyTypeInterface m_ti; |
121 int m_vampyFlags; | 89 int m_vampyFlags; |
122 bool m_quitOnErrorFlag; | 90 bool m_quitOnErrorFlag; |
123 bool m_debugFlag; | 91 bool m_debugFlag; |
124 bool m_useRealTimeFlag; | 92 bool m_useRealTimeFlag; |
185 if (m_debugFlag) cerr << DEFAULT_RETURN << endl; | 153 if (m_debugFlag) cerr << DEFAULT_RETURN << endl; |
186 return rValue; | 154 return rValue; |
187 } | 155 } |
188 | 156 |
189 /// prepare arguments for fast method call | 157 /// prepare arguments for fast method call |
190 PyObject *pyMethod = m_ti.PyValue_From_CValue(method); | 158 PyObject *pyMethod = m_tc.PyValue_From_CValue(method); |
191 PyObject *pyCallable = PyObject_GetAttr(m_pyInstance,pyMethod); | 159 PyObject *pyCallable = PyObject_GetAttr(m_pyInstance,pyMethod); |
192 PyObject* pyArgs = PyTuple_New(1); | 160 PyObject* pyArgs = PyTuple_New(1); |
193 if (!(pyArgs && pyCallable && pyMethod)) { | 161 if (!(pyArgs && pyCallable && pyMethod)) { |
194 cerr << PLUGIN_ERROR << "Failed to prepare argument for calling method." << endl; | 162 cerr << PLUGIN_ERROR << "Failed to prepare argument for calling method." << endl; |
195 Py_CLEAR(pyMethod); | 163 Py_CLEAR(pyMethod); |
196 Py_CLEAR(pyCallable); | 164 Py_CLEAR(pyCallable); |
197 Py_CLEAR(pyArgs); | 165 Py_CLEAR(pyArgs); |
198 return rValue; | 166 return rValue; |
199 } | 167 } |
200 | 168 |
201 PyObject *pyArg1 = m_ti.PyValue_From_CValue(arg1); | 169 PyObject *pyArg1 = m_tc.PyValue_From_CValue(arg1); |
202 if (m_ti.error) { | 170 if (m_tc.error) { |
203 cerr << PLUGIN_ERROR << "Failed to convert argument for calling method." << endl; | 171 cerr << PLUGIN_ERROR << "Failed to convert argument for calling method." << endl; |
204 typeErrorHandler(method); | 172 typeErrorHandler(method); |
205 Py_CLEAR(pyMethod); | 173 Py_CLEAR(pyMethod); |
206 Py_CLEAR(pyCallable); | 174 Py_CLEAR(pyCallable); |
207 Py_CLEAR(pyArg1); | 175 Py_CLEAR(pyArg1); |
251 if (m_debugFlag) cerr << DEFAULT_RETURN << endl; | 219 if (m_debugFlag) cerr << DEFAULT_RETURN << endl; |
252 return rValue; | 220 return rValue; |
253 } | 221 } |
254 | 222 |
255 /// prepare arguments for fast method call | 223 /// prepare arguments for fast method call |
256 PyObject *pyMethod = m_ti.PyValue_From_CValue(method); | 224 PyObject *pyMethod = m_tc.PyValue_From_CValue(method); |
257 PyObject *pyCallable = PyObject_GetAttr(m_pyInstance,pyMethod); | 225 PyObject *pyCallable = PyObject_GetAttr(m_pyInstance,pyMethod); |
258 PyObject* pyArgs = PyTuple_New(2); | 226 PyObject* pyArgs = PyTuple_New(2); |
259 if (!(pyArgs && pyCallable && pyMethod)) { | 227 if (!(pyArgs && pyCallable && pyMethod)) { |
260 cerr << PLUGIN_ERROR << "Failed to prepare arguments for calling method." << endl; | 228 cerr << PLUGIN_ERROR << "Failed to prepare arguments for calling method." << endl; |
261 Py_CLEAR(pyMethod); | 229 Py_CLEAR(pyMethod); |
262 Py_CLEAR(pyCallable); | 230 Py_CLEAR(pyCallable); |
263 Py_CLEAR(pyArgs); | 231 Py_CLEAR(pyArgs); |
264 return rValue; | 232 return rValue; |
265 } | 233 } |
266 | 234 |
267 PyObject *pyArg1 = m_ti.PyValue_From_CValue(arg1); | 235 PyObject *pyArg1 = m_tc.PyValue_From_CValue(arg1); |
268 PyObject *pyArg2 = m_ti.PyValue_From_CValue(arg2); | 236 PyObject *pyArg2 = m_tc.PyValue_From_CValue(arg2); |
269 if (m_ti.error) { | 237 if (m_tc.error) { |
270 cerr << PLUGIN_ERROR << "Failed to convert arguments for calling method." << endl; | 238 cerr << PLUGIN_ERROR << "Failed to convert arguments for calling method." << endl; |
271 typeErrorHandler(method); | 239 typeErrorHandler(method); |
272 Py_CLEAR(pyMethod); | 240 Py_CLEAR(pyMethod); |
273 Py_CLEAR(pyCallable); | 241 Py_CLEAR(pyCallable); |
274 Py_CLEAR(pyArg1); | 242 Py_CLEAR(pyArg1); |
323 if (m_debugFlag) cerr << DEFAULT_RETURN << endl; | 291 if (m_debugFlag) cerr << DEFAULT_RETURN << endl; |
324 return rValue; | 292 return rValue; |
325 } | 293 } |
326 | 294 |
327 /// prepare arguments for fast method call | 295 /// prepare arguments for fast method call |
328 PyObject *pyMethod = m_ti.PyValue_From_CValue(method); | 296 PyObject *pyMethod = m_tc.PyValue_From_CValue(method); |
329 PyObject *pyCallable = PyObject_GetAttr(m_pyInstance,pyMethod); | 297 PyObject *pyCallable = PyObject_GetAttr(m_pyInstance,pyMethod); |
330 PyObject* pyArgs = PyTuple_New(3); | 298 PyObject* pyArgs = PyTuple_New(3); |
331 if (!(pyArgs && pyCallable && pyMethod)) { | 299 if (!(pyArgs && pyCallable && pyMethod)) { |
332 cerr << PLUGIN_ERROR << "Failed to prepare arguments for calling method." << endl; | 300 cerr << PLUGIN_ERROR << "Failed to prepare arguments for calling method." << endl; |
333 Py_CLEAR(pyMethod); | 301 Py_CLEAR(pyMethod); |
334 Py_CLEAR(pyCallable); | 302 Py_CLEAR(pyCallable); |
335 Py_CLEAR(pyArgs); | 303 Py_CLEAR(pyArgs); |
336 return rValue; | 304 return rValue; |
337 } | 305 } |
338 | 306 |
339 PyObject *pyArg1 = m_ti.PyValue_From_CValue(arg1); | 307 PyObject *pyArg1 = m_tc.PyValue_From_CValue(arg1); |
340 PyObject *pyArg2 = m_ti.PyValue_From_CValue(arg2); | 308 PyObject *pyArg2 = m_tc.PyValue_From_CValue(arg2); |
341 PyObject *pyArg3 = m_ti.PyValue_From_CValue(arg3); | 309 PyObject *pyArg3 = m_tc.PyValue_From_CValue(arg3); |
342 if (m_ti.error) { | 310 if (m_tc.error) { |
343 cerr << PLUGIN_ERROR << "Failed to convert arguments for calling method." << endl; | 311 cerr << PLUGIN_ERROR << "Failed to convert arguments for calling method." << endl; |
344 typeErrorHandler(method); | 312 typeErrorHandler(method); |
345 Py_CLEAR(pyMethod); | 313 Py_CLEAR(pyMethod); |
346 Py_CLEAR(pyCallable); | 314 Py_CLEAR(pyCallable); |
347 Py_CLEAR(pyArg1); | 315 Py_CLEAR(pyArg1); |