changeset 80:de501b7e165a

naming: PyPluginObject methods snake_case
author Chris Cannam
date Wed, 21 Jan 2015 12:31:32 +0000
parents 650f0697812f
children 0a2f2e7803ea
files native/PyPluginObject.cpp test/test_plugin_metadata.py test/test_processBlock.py vamp/collect.py vamp/load.py vamp/process.py
diffstat 6 files changed, 80 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/native/PyPluginObject.cpp	Wed Jan 21 12:28:16 2015 +0000
+++ b/native/PyPluginObject.cpp	Wed Jan 21 12:31:32 2015 +0000
@@ -171,7 +171,7 @@
 }
 
 static PyObject *
-getOutputs(PyObject *self, PyObject *args)
+get_outputs(PyObject *self, PyObject *args)
 { 
     PyPluginObject *pd = getPluginObject(self);
     if (!pd) return 0;
@@ -285,13 +285,13 @@
 }
 
 static PyObject *
-getParameterValue(PyObject *self, PyObject *args)
+get_parameter_value(PyObject *self, PyObject *args)
 {
     PyObject *pyParam;
 
     if (!PyArg_ParseTuple(args, "S", &pyParam)) {
         PyErr_SetString(PyExc_TypeError,
-                        "getParameterValue() takes parameter id (string) argument");
+                        "get_parameter_value() takes parameter id (string) argument");
         return 0; }
 
     PyPluginObject *pd = getPluginObject(self);
@@ -310,14 +310,14 @@
 }
 
 static PyObject *
-setParameterValue(PyObject *self, PyObject *args)
+set_parameter_value(PyObject *self, PyObject *args)
 {
     PyObject *pyParam;
     float value;
 
     if (!PyArg_ParseTuple(args, "Sf", &pyParam, &value)) {
         PyErr_SetString(PyExc_TypeError,
-                        "setParameterValue() takes parameter id (string), and value (float) arguments");
+                        "set_parameter_value() takes parameter id (string), and value (float) arguments");
         return 0; }
 
     PyPluginObject *pd = getPluginObject(self);
@@ -336,18 +336,18 @@
 }
 
 static PyObject *
-setParameterValues(PyObject *self, PyObject *args)
+set_parameter_values(PyObject *self, PyObject *args)
 {
     PyObject *dict;
 
     if (!PyArg_ParseTuple(args, "O", &dict)) {
         PyErr_SetString(PyExc_TypeError,
-                        "setParameterValues() takes dict argument");
+                        "set_parameter_values() takes dict argument");
         return 0; }
 
     if (!PyDict_Check(dict)) {
         PyErr_SetString(PyExc_TypeError,
-                        "setParameterValues() takes dict argument");
+                        "set_parameter_values() takes dict argument");
         return 0; }
     
     PyPluginObject *pd = getPluginObject(self);
@@ -385,13 +385,13 @@
 }
 
 static PyObject *
-selectProgram(PyObject *self, PyObject *args)
+select_program(PyObject *self, PyObject *args)
 {
     PyObject *pyParam;
 
     if (!PyArg_ParseTuple(args, "S", &pyParam)) {
         PyErr_SetString(PyExc_TypeError,
-                        "selectProgram() takes parameter id (string) argument");
+                        "select_program() takes parameter id (string) argument");
         return 0; }
 
     PyPluginObject *pd = getPluginObject(self);
@@ -509,7 +509,7 @@
 }
 
 static PyObject *
-processBlock(PyObject *self, PyObject *args)
+process_block(PyObject *self, PyObject *args)
 {
     PyObject *pyBuffer;
     PyObject *pyRealTime;
@@ -518,7 +518,7 @@
                           &pyBuffer,                    // Audio data
                           &pyRealTime)) {               // TimeStamp
         PyErr_SetString(PyExc_TypeError,
-                        "processBlock() takes buffer (2D array or list of arrays, one row per channel) and timestamp (RealTime) arguments");
+                        "process_block() takes buffer (2D array or list of arrays, one row per channel) and timestamp (RealTime) arguments");
         return 0; }
 
     if (!PyRealTime_Check(pyRealTime)) {
@@ -551,7 +551,7 @@
 }
 
 static PyObject *
-getRemainingFeatures(PyObject *self, PyObject *)
+get_remaining_features(PyObject *self, PyObject *)
 {
     PyPluginObject *pd = getPluginObject(self);
     if (!pd) return 0;
@@ -568,7 +568,7 @@
 }
 
 static PyObject *
-getPreferredBlockSize(PyObject *self, PyObject *)
+get_preferred_block_size(PyObject *self, PyObject *)
 {
     PyPluginObject *pd = getPluginObject(self);
     if (!pd) return 0;
@@ -576,7 +576,7 @@
 }
 
 static PyObject *
-getPreferredStepSize(PyObject *self, PyObject *)
+get_preferred_step_size(PyObject *self, PyObject *)
 {
     PyPluginObject *pd = getPluginObject(self);
     if (!pd) return 0;
@@ -584,7 +584,7 @@
 }
 
 static PyObject *
-getMinChannelCount(PyObject *self, PyObject *)
+get_min_channel_count(PyObject *self, PyObject *)
 {
     PyPluginObject *pd = getPluginObject(self);
     if (!pd) return 0;
@@ -592,7 +592,7 @@
 }
 
 static PyObject *
-getMaxChannelCount(PyObject *self, PyObject *)
+get_max_channel_count(PyObject *self, PyObject *)
 {
     PyPluginObject *pd = getPluginObject(self);
     if (!pd) return 0;
@@ -631,44 +631,44 @@
 
 static PyMethodDef PyPluginObject_methods[] =
 {
-    {"getOutputs", getOutputs, METH_NOARGS,
-     "getOutputs() -> Obtain the output descriptors for all of the plugin's outputs."},
+    {"get_outputs", get_outputs, METH_NOARGS,
+     "get_outputs() -> Obtain the output descriptors for all of the plugin's outputs."},
 
-    {"getParameterValue", getParameterValue, METH_VARARGS,
-     "getParameterValue(identifier) -> Return the value of the parameter with the given identifier."},
+    {"get_parameter_value", get_parameter_value, METH_VARARGS,
+     "get_parameter_value(identifier) -> Return the value of the parameter with the given identifier."},
 
-    {"setParameterValue", setParameterValue, METH_VARARGS,
-     "setParameterValue(identifier, value) -> Set the parameter with the given identifier to the given value."},
+    {"set_parameter_value", set_parameter_value, METH_VARARGS,
+     "set_parameter_value(identifier, value) -> Set the parameter with the given identifier to the given value."},
 
-    {"setParameterValues", setParameterValues, METH_VARARGS,
-     "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."},
+    {"set_parameter_values", set_parameter_values, METH_VARARGS,
+     "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."},
 
-    {"selectProgram", selectProgram, METH_VARARGS,
-     "selectProgram(name) -> Select the processing program with the given name."},
+    {"select_program", select_program, METH_VARARGS,
+     "select_program(name) -> Select the processing program with the given name."},
     
-    {"getPreferredBlockSize", getPreferredBlockSize, METH_VARARGS,
-     "getPreferredBlockSize() -> Return the plugin's preferred processing block size, or 0 if the plugin accepts any block size."},
+    {"get_preferred_block_size", get_preferred_block_size, METH_VARARGS,
+     "get_preferred_block_size() -> Return the plugin's preferred processing block size, or 0 if the plugin accepts any block size."},
 
-    {"getPreferredStepSize", getPreferredStepSize, METH_VARARGS,
-     "getPreferredStepSize() -> 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."},
+    {"get_preferred_step_size", get_preferred_step_size, METH_VARARGS,
+     "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."},
 
-    {"getMinChannelCount", getMinChannelCount, METH_VARARGS,
-     "getMinChannelCount() -> Return the minimum number of channels of audio data the plugin accepts as input."},
+    {"get_min_channel_count", get_min_channel_count, METH_VARARGS,
+     "get_min_channel_count() -> Return the minimum number of channels of audio data the plugin accepts as input."},
 
-    {"getMaxChannelCount", getMaxChannelCount, METH_VARARGS,
-     "getMaxChannelCount() -> Return the maximum number of channels of audio data the plugin accepts as input."},
+    {"get_max_channel_count", get_max_channel_count, METH_VARARGS,
+     "get_max_channel_count() -> Return the maximum number of channels of audio data the plugin accepts as input."},
     
     {"initialise", initialise, METH_VARARGS,
-     "initialise(channels, stepSize, blockSize) -> Initialise the plugin for the given number of channels and processing frame sizes. This must be called before processBlock() can be used."},
+     "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."},
 
     {"reset", reset, METH_NOARGS,
      "reset() -> Reset the plugin after processing, to prepare for another processing run with the same parameters."},
 
-    {"processBlock", processBlock, METH_VARARGS,
-     "processBlock(block, timestamp) -> Provide one processing frame to the plugin, with its timestamp, and obtain any features that were extracted immediately from this frame."},
+    {"process_block", process_block, METH_VARARGS,
+     "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."},
 
-    {"getRemainingFeatures", getRemainingFeatures, METH_NOARGS,
-     "getRemainingFeatures() -> Obtain any features extracted at the end of processing."},
+    {"get_remaining_features", get_remaining_features, METH_NOARGS,
+     "get_remaining_features() -> Obtain any features extracted at the end of processing."},
 
     {"unload", unload, METH_NOARGS,
      "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."},
--- a/test/test_plugin_metadata.py	Wed Jan 21 12:28:16 2015 +0000
+++ b/test/test_plugin_metadata.py	Wed Jan 21 12:31:32 2015 +0000
@@ -41,33 +41,33 @@
     plug = vh.load_plugin(testPluginKey, rate, vh.ADAPT_NONE)
     assert plug.parameters[0]["identifier"] == "produce_output"
     assert plug.parameters[0]["defaultValue"] == 1
-    assert plug.getParameterValue("produce_output") == plug.parameters[0]["defaultValue"]
-    assert plug.setParameterValue("produce_output", 0) == True
-    assert plug.getParameterValue("produce_output") == 0
-    assert plug.setParameterValues({ "produce_output": 1 }) == True
-    assert plug.getParameterValue("produce_output") == 1
+    assert plug.get_parameter_value("produce_output") == plug.parameters[0]["defaultValue"]
+    assert plug.set_parameter_value("produce_output", 0) == True
+    assert plug.get_parameter_value("produce_output") == 0
+    assert plug.set_parameter_values({ "produce_output": 1 }) == True
+    assert plug.get_parameter_value("produce_output") == 1
     try:
-        plug.setParameterValue("produce_output", "fish")
+        plug.set_parameter_value("produce_output", "fish")
         assert False
     except TypeError:
         pass
     try:
-        plug.setParameterValue(4, 0)
+        plug.set_parameter_value(4, 0)
         assert False
     except TypeError:
         pass
     try:
-        plug.setParameterValue("steak", 0)
+        plug.set_parameter_value("steak", 0)
         assert False
     except StandardError:
         pass
     try:
-        plug.getParameterValue(4)
+        plug.get_parameter_value(4)
         assert False
     except TypeError:
         pass
     try:
-        plug.getParameterValue("steak")
+        plug.get_parameter_value("steak")
         assert False
     except StandardError:
         pass
--- a/test/test_processBlock.py	Wed Jan 21 12:28:16 2015 +0000
+++ b/test/test_processBlock.py	Wed Jan 21 12:31:32 2015 +0000
@@ -17,16 +17,16 @@
 
 def test_get_set_parameter():
     plug = vh.load_plugin(testPluginKey, rate, vh.ADAPT_NONE)
-    value = plug.getParameterValue("produce_output")
+    value = plug.get_parameter_value("produce_output")
     assert(value == 1.0)
-    plug.setParameterValue("produce_output", 0.0)
-    value = plug.getParameterValue("produce_output")
+    plug.set_parameter_value("produce_output", 0.0)
+    value = plug.get_parameter_value("produce_output")
     assert(value == 0.0)
     
 def test_process_without_initialise():
     plug = vh.load_plugin(testPluginKey, rate, vh.ADAPT_NONE)
     try:
-        plug.processBlock([[1,2,3,4]], vh.RealTime(0, 0))
+        plug.process_block([[1,2,3,4]], vh.RealTime(0, 0))
         assert False
     except StandardError:
         pass
@@ -34,24 +34,24 @@
 def test_process_input_format():
     plug = vh.load_plugin(testPluginKey, rate, vh.ADAPT_NONE)
     plug.initialise(2, 4, 4) # channels, stepsize, blocksize
-    result = plug.processBlock([[1,2,3,4],[5,6,7,8]], vh.RealTime(0, 0))
-    result = plug.processBlock([np.array([1,2,3,4]),np.array([5,6,7,8])], vh.RealTime(0, 0))
-    result = plug.processBlock(np.array([[1,2,3,4],[5,6,7,8]]), vh.RealTime(0, 0))
+    result = plug.process_block([[1,2,3,4],[5,6,7,8]], vh.RealTime(0, 0))
+    result = plug.process_block([np.array([1,2,3,4]),np.array([5,6,7,8])], vh.RealTime(0, 0))
+    result = plug.process_block(np.array([[1,2,3,4],[5,6,7,8]]), vh.RealTime(0, 0))
     try:
         # Wrong number of channels
-        result = plug.processBlock(np.array([[1,2,3,4]]), vh.RealTime(0, 0))
+        result = plug.process_block(np.array([[1,2,3,4]]), vh.RealTime(0, 0))
         assert False
     except TypeError:
         pass
     try:
         # Wrong number of samples per channel
-        result = plug.processBlock(np.array([[1,2,3],[4,5,6]]), vh.RealTime(0, 0))
+        result = plug.process_block(np.array([[1,2,3],[4,5,6]]), vh.RealTime(0, 0))
         assert False
     except TypeError:
         pass
     try:
         # Differing numbers of samples per channel
-        result = plug.processBlock(np.array([[1,2,3,4],[5,6,7]]), vh.RealTime(0, 0))
+        result = plug.process_block(np.array([[1,2,3,4],[5,6,7]]), vh.RealTime(0, 0))
         assert False
     except TypeError:
         pass
@@ -61,13 +61,13 @@
     plug.initialise(1, 2, 2)
     try:
         # Too many channels
-        result = plug.processBlock([[3,4],[5,6]], vh.RealTime(0, 0))
+        result = plug.process_block([[3,4],[5,6]], vh.RealTime(0, 0))
         assert False
     except TypeError:
         pass
-    result = plug.processBlock([[3,3]], vh.RealTime(0, 0))
+    result = plug.process_block([[3,3]], vh.RealTime(0, 0))
     assert result[8] == [ { "label" : "", "values" : np.array([5.0]) } ]
-    result = plug.processBlock([[3,0]], vh.RealTime(0, 0))
+    result = plug.process_block([[3,0]], vh.RealTime(0, 0))
     assert result[8] == [ { "label" : "", "values" : np.array([4.0]) } ]
 
 def test_process_output_2ch():
@@ -75,19 +75,19 @@
     plug.initialise(2, 2, 2)
     try:
         # Too few channels
-        result = plug.processBlock([[3,4]], vh.RealTime(0, 0))
+        result = plug.process_block([[3,4]], vh.RealTime(0, 0))
         assert False
     except TypeError:
         pass
     try:
         # Too many channels
-        result = plug.processBlock([[3,4],[5,6],[7,8]], vh.RealTime(0, 0))
+        result = plug.process_block([[3,4],[5,6],[7,8]], vh.RealTime(0, 0))
         assert False
     except TypeError:
         pass
-    result = plug.processBlock([[3,3],[4,4]], vh.RealTime(0, 0))
+    result = plug.process_block([[3,3],[4,4]], vh.RealTime(0, 0))
     assert (result[8][0]["values"] == np.array([5.0,6.0])).all()
-    result = plug.processBlock([[3,0],[4,0]], vh.RealTime(0, 0))
+    result = plug.process_block([[3,0],[4,0]], vh.RealTime(0, 0))
     assert (result[8][0]["values"] == np.array([4.0,5.0])).all()
 
 def test_process_output_3ch():
@@ -95,19 +95,19 @@
     plug.initialise(3, 2, 2)
     try:
         # Too few channels
-        result = plug.processBlock([[3,4],[5,6]], vh.RealTime(0, 0))
+        result = plug.process_block([[3,4],[5,6]], vh.RealTime(0, 0))
         assert False
     except TypeError:
         pass
     try:
         # Too many channels
-        result = plug.processBlock([[3,4],[5,6],[7,8],[9,10]], vh.RealTime(0, 0))
+        result = plug.process_block([[3,4],[5,6],[7,8],[9,10]], vh.RealTime(0, 0))
         assert False
     except TypeError:
         pass
-    result = plug.processBlock([[3,3],[4,4],[5,5]], vh.RealTime(0, 0))
+    result = plug.process_block([[3,3],[4,4],[5,5]], vh.RealTime(0, 0))
     assert (result[8][0]["values"] == np.array([5.0,6.0,7.0])).all()
-    result = plug.processBlock([[3,0],[4,0],[5,0]], vh.RealTime(0, 0))
+    result = plug.process_block([[3,0],[4,0],[5,0]], vh.RealTime(0, 0))
     assert (result[8][0]["values"] == np.array([4.0,5.0,6.0])).all()
 
 
--- a/vamp/collect.py	Wed Jan 21 12:28:16 2015 +0000
+++ b/vamp/collect.py	Wed Jan 21 12:31:32 2015 +0000
@@ -36,7 +36,7 @@
     
     plug, stepSize, blockSize = load.loadAndConfigureFor(data, sampleRate, key, parameters)
 
-    plugOuts = plug.getOutputs()
+    plugOuts = plug.get_outputs()
     if plugOuts == []:
         return
 
--- a/vamp/load.py	Wed Jan 21 12:28:16 2015 +0000
+++ b/vamp/load.py	Wed Jan 21 12:31:32 2015 +0000
@@ -10,10 +10,10 @@
                                 vampyhost.ADAPT_INPUT_DOMAIN +
                                 vampyhost.ADAPT_CHANNEL_COUNT)
 
-    plug.setParameterValues(parameters)
+    plug.set_parameter_values(parameters)
 
-    stepSize = plug.getPreferredStepSize()
-    blockSize = plug.getPreferredBlockSize()
+    stepSize = plug.get_preferred_step_size()
+    blockSize = plug.get_preferred_block_size()
 
     if blockSize == 0:
         blockSize = 1024
--- a/vamp/process.py	Wed Jan 21 12:28:16 2015 +0000
+++ b/vamp/process.py	Wed Jan 21 12:31:32 2015 +0000
@@ -6,7 +6,7 @@
 
 def loadAndQuery(data, sampleRate, key, parameters):
     plug, stepSize, blockSize = load.loadAndConfigureFor(data, sampleRate, key, parameters)
-    plugOuts = plug.getOutputs()
+    plugOuts = plug.get_outputs()
     outIndices = dict(zip([o["identifier"] for o in plugOuts],
                           range(0, len(plugOuts))))  # id -> n
     return plug, stepSize, blockSize, outIndices
@@ -24,7 +24,7 @@
     fi = 0
 
     for f in ff:
-        results = plug.processBlock(f, vampyhost.frame_to_realtime(fi, sampleRate))
+        results = plug.process_block(f, vampyhost.frame_to_realtime(fi, sampleRate))
         # results is a dict mapping output number -> list of feature dicts
         for o in outputs:
             outix = outIndices[o]
@@ -33,7 +33,7 @@
                     yield { o: r }
         fi = fi + stepSize
 
-    results = plug.getRemainingFeatures()
+    results = plug.get_remaining_features()
     for o in outputs:
         outix = outIndices[o]
         if outix in results:
@@ -57,14 +57,14 @@
     fi = 0
 
     for f in ff:
-        results = plug.processBlock(f, vampyhost.frame_to_realtime(fi, sampleRate))
+        results = plug.process_block(f, vampyhost.frame_to_realtime(fi, sampleRate))
         # results is a dict mapping output number -> list of feature dicts
         if outix in results:
             for r in results[outix]:
                 yield r
         fi = fi + stepSize
 
-    results = plug.getRemainingFeatures()
+    results = plug.get_remaining_features()
     if outix in results:
         for r in results[outix]:
             yield r