Mercurial > hg > vampy-host
comparison native/vampyhost.cpp @ 79:650f0697812f
naming: vampyhost module methods snake_case
author | Chris Cannam |
---|---|
date | Wed, 21 Jan 2015 12:28:16 +0000 |
parents | aa8491a11530 |
children | 9343eee50605 |
comparison
equal
deleted
inserted
replaced
78:f61ca3c81272 | 79:650f0697812f |
---|---|
62 using namespace std; | 62 using namespace std; |
63 using namespace Vamp; | 63 using namespace Vamp; |
64 using namespace Vamp::HostExt; | 64 using namespace Vamp::HostExt; |
65 | 65 |
66 static PyObject * | 66 static PyObject * |
67 enumeratePlugins(PyObject *self, PyObject *) | 67 list_plugins(PyObject *self, PyObject *) |
68 { | 68 { |
69 PluginLoader *loader = PluginLoader::getInstance(); | 69 PluginLoader *loader = PluginLoader::getInstance(); |
70 vector<PluginLoader::PluginKey> plugins = loader->listPlugins(); | 70 vector<PluginLoader::PluginKey> plugins = loader->listPlugins(); |
71 VectorConversion conv; | 71 VectorConversion conv; |
72 return conv.PyValue_From_StringVector(plugins); | 72 return conv.PyValue_From_StringVector(plugins); |
73 } | 73 } |
74 | 74 |
75 static PyObject * | 75 static PyObject * |
76 getPluginPath(PyObject *self, PyObject *) | 76 get_plugin_path(PyObject *self, PyObject *) |
77 { | 77 { |
78 vector<string> path = PluginHostAdapter::getPluginPath(); | 78 vector<string> path = PluginHostAdapter::getPluginPath(); |
79 VectorConversion conv; | 79 VectorConversion conv; |
80 return conv.PyValue_From_StringVector(path); | 80 return conv.PyValue_From_StringVector(path); |
81 } | 81 } |
95 | 95 |
96 return pluginKey; | 96 return pluginKey; |
97 } | 97 } |
98 | 98 |
99 static PyObject * | 99 static PyObject * |
100 getLibraryFor(PyObject *self, PyObject *args) | 100 get_library_for(PyObject *self, PyObject *args) |
101 { | 101 { |
102 PyObject *pyPluginKey; | 102 PyObject *pyPluginKey; |
103 | 103 |
104 if (!PyArg_ParseTuple(args, "S", &pyPluginKey)) { | 104 if (!PyArg_ParseTuple(args, "S", &pyPluginKey)) { |
105 PyErr_SetString(PyExc_TypeError, | 105 PyErr_SetString(PyExc_TypeError, |
106 "getLibraryPathForPlugin() takes plugin key (string) argument"); | 106 "get_library_for() takes plugin key (string) argument"); |
107 return 0; } | 107 return 0; } |
108 | 108 |
109 string pluginKey = toPluginKey(pyPluginKey); | 109 string pluginKey = toPluginKey(pyPluginKey); |
110 if (pluginKey == "") return 0; | 110 if (pluginKey == "") return 0; |
111 | 111 |
114 PyObject *pyPath = PyString_FromString(path.c_str()); | 114 PyObject *pyPath = PyString_FromString(path.c_str()); |
115 return pyPath; | 115 return pyPath; |
116 } | 116 } |
117 | 117 |
118 static PyObject * | 118 static PyObject * |
119 getPluginCategory(PyObject *self, PyObject *args) | 119 get_category_of(PyObject *self, PyObject *args) |
120 { | 120 { |
121 PyObject *pyPluginKey; | 121 PyObject *pyPluginKey; |
122 | 122 |
123 if (!PyArg_ParseTuple(args, "S", &pyPluginKey)) { | 123 if (!PyArg_ParseTuple(args, "S", &pyPluginKey)) { |
124 PyErr_SetString(PyExc_TypeError, | 124 PyErr_SetString(PyExc_TypeError, |
125 "getPluginCategory() takes plugin key (string) argument"); | 125 "get_category_of() takes plugin key (string) argument"); |
126 return 0; } | 126 return 0; } |
127 | 127 |
128 string pluginKey = toPluginKey(pyPluginKey); | 128 string pluginKey = toPluginKey(pyPluginKey); |
129 if (pluginKey == "") return 0; | 129 if (pluginKey == "") return 0; |
130 | 130 |
135 VectorConversion conv; | 135 VectorConversion conv; |
136 return conv.PyValue_From_StringVector(category); | 136 return conv.PyValue_From_StringVector(category); |
137 } | 137 } |
138 | 138 |
139 static PyObject * | 139 static PyObject * |
140 getOutputList(PyObject *self, PyObject *args) | 140 get_outputs_of(PyObject *self, PyObject *args) |
141 { | 141 { |
142 PyObject *pyPluginKey; | 142 PyObject *pyPluginKey; |
143 | 143 |
144 if (!PyArg_ParseTuple(args, "S", &pyPluginKey)) { | 144 if (!PyArg_ParseTuple(args, "S", &pyPluginKey)) { |
145 PyErr_SetString(PyExc_TypeError, | 145 PyErr_SetString(PyExc_TypeError, |
146 "getOutputList() takes plugin key (string) argument"); | 146 "get_outputs_of() takes plugin key (string) argument"); |
147 return 0; } | 147 return 0; } |
148 | 148 |
149 Plugin::OutputList outputs; | 149 Plugin::OutputList outputs; |
150 | 150 |
151 string pluginKey = toPluginKey(pyPluginKey); | 151 string pluginKey = toPluginKey(pyPluginKey); |
172 | 172 |
173 return pyList; | 173 return pyList; |
174 } | 174 } |
175 | 175 |
176 static PyObject * | 176 static PyObject * |
177 loadPlugin(PyObject *self, PyObject *args) | 177 load_plugin(PyObject *self, PyObject *args) |
178 { | 178 { |
179 PyObject *pyPluginKey; | 179 PyObject *pyPluginKey; |
180 float inputSampleRate; | 180 float inputSampleRate; |
181 int adapterFlags; | 181 int adapterFlags; |
182 | 182 |
183 if (!PyArg_ParseTuple(args, "Sfn", | 183 if (!PyArg_ParseTuple(args, "Sfn", |
184 &pyPluginKey, | 184 &pyPluginKey, |
185 &inputSampleRate, | 185 &inputSampleRate, |
186 &adapterFlags)) { | 186 &adapterFlags)) { |
187 PyErr_SetString(PyExc_TypeError, | 187 PyErr_SetString(PyExc_TypeError, |
188 "loadPlugin() takes plugin key (string), sample rate (float), and adapter flags (int) arguments"); | 188 "load_plugin() takes plugin key (string), sample rate (float), and adapter flags (int) arguments"); |
189 return 0; } | 189 return 0; } |
190 | 190 |
191 string pluginKey = toPluginKey(pyPluginKey); | 191 string pluginKey = toPluginKey(pyPluginKey); |
192 if (pluginKey == "") return 0; | 192 if (pluginKey == "") return 0; |
193 | 193 |
204 | 204 |
205 return PyPluginObject_From_Plugin(plugin); | 205 return PyPluginObject_From_Plugin(plugin); |
206 } | 206 } |
207 | 207 |
208 static PyObject * | 208 static PyObject * |
209 frame2RealTime(PyObject *self, PyObject *args) | 209 frame_to_realtime(PyObject *self, PyObject *args) |
210 { | 210 { |
211 int frame; | 211 int frame; |
212 int rate; | 212 int rate; |
213 | 213 |
214 if (!PyArg_ParseTuple(args, "nn", | 214 if (!PyArg_ParseTuple(args, "nn", |
215 &frame, | 215 &frame, |
216 &rate)) { | 216 &rate)) { |
217 PyErr_SetString(PyExc_TypeError, | 217 PyErr_SetString(PyExc_TypeError, |
218 "frame2RealTime() takes frame (int) and sample rate (int) arguments"); | 218 "frame_to_realtime() takes frame (int) and sample rate (int) arguments"); |
219 return 0; } | 219 return 0; } |
220 | 220 |
221 RealTime rt = RealTime::frame2RealTime(frame, rate); | 221 RealTime rt = RealTime::frame2RealTime(frame, rate); |
222 return PyRealTime_FromRealTime(rt); | 222 return PyRealTime_FromRealTime(rt); |
223 } | 223 } |
224 | 224 |
225 // module methods table | 225 // module methods table |
226 static PyMethodDef vampyhost_methods[] = { | 226 static PyMethodDef vampyhost_methods[] = { |
227 | 227 |
228 {"listPlugins", enumeratePlugins, METH_NOARGS, | 228 {"list_plugins", list_plugins, METH_NOARGS, |
229 "listPlugins() -> Return a list of the plugin keys of all installed Vamp plugins." }, | 229 "list_plugins() -> Return a list of the plugin keys of all installed Vamp plugins." }, |
230 | 230 |
231 {"getPluginPath", getPluginPath, METH_NOARGS, | 231 {"get_plugin_path", get_plugin_path, METH_NOARGS, |
232 "getPluginPath() -> Return a list of directories which will be searched for Vamp plugins. This may be changed by setting the VAMP_PATH environment variable."}, | 232 "get_plugin_path() -> Return a list of directories which will be searched for Vamp plugins. This may be changed by setting the VAMP_PATH environment variable."}, |
233 | 233 |
234 {"getCategoryOf", getPluginCategory, METH_VARARGS, | 234 {"get_category_of", get_category_of, METH_VARARGS, |
235 "getCategoryOf(pluginKey) -> Return the category of a Vamp plugin given its key, if known. The category is expressed as a list of nested types from least to most specific."}, | 235 "get_category_of(pluginKey) -> Return the category of a Vamp plugin given its key, if known. The category is expressed as a list of nested types from least to most specific."}, |
236 | 236 |
237 {"getLibraryFor", getLibraryFor, METH_VARARGS, | 237 {"get_library_for", get_library_for, METH_VARARGS, |
238 "getLibraryFor(pluginKey) -> Return the file path of the Vamp plugin library in which the given plugin key is found, or an empty string if the plugin is not installed."}, | 238 "get_library_for(pluginKey) -> Return the file path of the Vamp plugin library in which the given plugin key is found, or an empty string if the plugin is not installed."}, |
239 | 239 |
240 {"getOutputsOf", getOutputList, METH_VARARGS, | 240 {"get_outputs_of", get_outputs_of, METH_VARARGS, |
241 "getOutputsOf(pluginKey) -> Return a list of the output identifiers of the plugin with the given key, if installed."}, | 241 "get_outputs_of(pluginKey) -> Return a list of the output identifiers of the plugin with the given key, if installed."}, |
242 | 242 |
243 {"loadPlugin", loadPlugin, METH_VARARGS, | 243 {"load_plugin", load_plugin, METH_VARARGS, |
244 "loadPlugin(pluginKey, samplerate) -> Load the plugin that has the given key, if installed, and return the plugin object."}, | 244 "load_plugin(pluginKey, samplerate) -> Load the plugin that has the given key, if installed, and return the plugin object."}, |
245 | 245 |
246 {"frame2RealTime", frame2RealTime, METH_VARARGS, | 246 {"frame_to_realtime", frame_to_realtime, METH_VARARGS, |
247 "frame2RealTime() -> Convert sample frame number and sample rate to a RealTime object." }, | 247 "frame_to_realtime() -> Convert sample frame number and sample rate to a RealTime object." }, |
248 | 248 |
249 {0, 0} /* sentinel */ | 249 {0, 0} /* sentinel */ |
250 }; | 250 }; |
251 | 251 |
252 PyDoc_STRVAR(module_doc, "Load and run Vamp audio analysis plugins."); | 252 PyDoc_STRVAR(module_doc, "Load and run Vamp audio analysis plugins."); |