annotate PyPlugin.h @ 18:e9cf443b18f5

* Add duration support (Vamp 2.0)
author cannam
date Fri, 10 Jul 2009 15:14:24 +0000
parents a4c955e9a70b
children 1ae350e97f93
rev   line source
cannam@18 1 /* -*- c-basic-offset: 8 indent-tabs-mode: t -*- */
fazekasgy@0 2 /*
fazekasgy@0 3 Vamp
fazekasgy@0 4
fazekasgy@0 5 An API for audio analysis and feature extraction plugins.
fazekasgy@0 6
fazekasgy@0 7 Centre for Digital Music, Queen Mary, University of London.
fazekasgy@0 8 Copyright 2006 Chris Cannam.
fazekasgy@0 9
fazekasgy@0 10 Permission is hereby granted, free of charge, to any person
fazekasgy@0 11 obtaining a copy of this software and associated documentation
fazekasgy@0 12 files (the "Software"), to deal in the Software without
fazekasgy@0 13 restriction, including without limitation the rights to use, copy,
fazekasgy@0 14 modify, merge, publish, distribute, sublicense, and/or sell copies
fazekasgy@0 15 of the Software, and to permit persons to whom the Software is
fazekasgy@0 16 furnished to do so, subject to the following conditions:
fazekasgy@0 17
fazekasgy@0 18 The above copyright notice and this permission notice shall be
fazekasgy@0 19 included in all copies or substantial portions of the Software.
fazekasgy@0 20
fazekasgy@0 21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
fazekasgy@0 22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
fazekasgy@0 23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
fazekasgy@0 24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
fazekasgy@0 25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
fazekasgy@0 26 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
fazekasgy@0 27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
fazekasgy@0 28
fazekasgy@0 29 Except as contained in this notice, the names of the Centre for
fazekasgy@0 30 Digital Music; Queen Mary, University of London; and Chris Cannam
fazekasgy@0 31 shall not be used in advertising or otherwise to promote the sale,
fazekasgy@0 32 use or other dealings in this Software without prior written
fazekasgy@0 33 authorization.
fazekasgy@0 34 */
fazekasgy@0 35
fazekasgy@0 36 /**
cannam@7 37 * This plugin abstracts appropriate Python Scripts as a Vamp plugin.
fazekasgy@0 38 */
fazekasgy@0 39
fazekasgy@0 40 #ifndef _PYTHON_WRAPPER_PLUGIN_H_
fazekasgy@0 41 #define _PYTHON_WRAPPER_PLUGIN_H_
fazekasgy@0 42
fazekasgy@0 43 #include "vamp-sdk/Plugin.h"
cannam@3 44 #include <Python.h>
cannam@3 45
cannam@3 46 #include "Mutex.h"
fazekasgy@0 47
fazekasgy@0 48 //fields in OutputDescriptor
cannam@18 49 namespace o {
fazekasgy@0 50 enum eOutDescriptors {
fazekasgy@0 51 not_found,
fazekasgy@0 52 identifier,
fazekasgy@0 53 name,
fazekasgy@0 54 description,
fazekasgy@0 55 unit,
fazekasgy@0 56 hasFixedBinCount,
fazekasgy@0 57 binCount,
fazekasgy@0 58 binNames,
fazekasgy@0 59 hasKnownExtents,
fazekasgy@0 60 minValue,
fazekasgy@0 61 maxValue,
fazekasgy@0 62 isQuantized,
fazekasgy@0 63 quantizeStep,
fazekasgy@0 64 sampleType,
fazekasgy@0 65 sampleRate,
cannam@18 66 hasDuration,
fazekasgy@0 67 endNode
fazekasgy@0 68 };
cannam@18 69 }
fazekasgy@0 70
fazekasgy@0 71 namespace p {
fazekasgy@0 72 enum eParmDescriptors {
fazekasgy@0 73 not_found,
fazekasgy@0 74 identifier,
fazekasgy@0 75 name,
fazekasgy@0 76 description,
fazekasgy@0 77 unit,
fazekasgy@0 78 minValue,
fazekasgy@0 79 maxValue,
fazekasgy@0 80 defaultValue,
fazekasgy@0 81 isQuantized
fazekasgy@0 82 };
fazekasgy@0 83 }
fazekasgy@0 84
fazekasgy@0 85 enum eSampleTypes {
fazekasgy@0 86 OneSamplePerStep,
fazekasgy@0 87 FixedSampleRate,
fazekasgy@0 88 VariableSampleRate
fazekasgy@0 89 };
fazekasgy@0 90
fazekasgy@0 91 enum eFeatureFields {
fazekasgy@0 92 unknown,
fazekasgy@0 93 hasTimestamp,
fazekasgy@0 94 timeStamp,
cannam@18 95 hasDuration,
cannam@18 96 duration,
fazekasgy@0 97 values,
fazekasgy@0 98 label
fazekasgy@0 99 };
fazekasgy@0 100
fazekasgy@6 101 enum eProcessType {
fazekasgy@6 102 not_implemented,
fazekasgy@6 103 legacyProcess,
fazekasgy@6 104 numpyProcess
fazekasgy@6 105 };
fazekasgy@0 106
fazekasgy@0 107 class PyPlugin : public Vamp::Plugin
fazekasgy@0 108 {
fazekasgy@0 109 public:
cannam@18 110 PyPlugin(std::string plugin,float inputSampleRate, PyObject *pyInstance);
cannam@18 111 virtual ~PyPlugin();
fazekasgy@0 112
cannam@18 113 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
cannam@18 114 void reset();
fazekasgy@6 115
fazekasgy@0 116 InputDomain getInputDomain() const;
fazekasgy@0 117 size_t getPreferredBlockSize() const;
fazekasgy@0 118 size_t getPreferredStepSize() const;
fazekasgy@0 119 size_t getMinChannelCount() const;
fazekasgy@0 120 size_t getMaxChannelCount() const;
fazekasgy@0 121
cannam@18 122 std::string getIdentifier() const;
cannam@18 123 std::string getName() const;
cannam@18 124 std::string getDescription() const;
cannam@18 125 std::string getMaker() const;
cannam@18 126 int getPluginVersion() const;
cannam@18 127 std::string getCopyright() const;
cannam@18 128
cannam@18 129 OutputList getOutputDescriptors() const;
cannam@18 130 ParameterList getParameterDescriptors() const;
fazekasgy@0 131 float getParameter(std::string paramid) const;
fazekasgy@0 132 void setParameter(std::string paramid, float newval);
fazekasgy@0 133
cannam@18 134 FeatureSet process(const float *const *inputBuffers,
cannam@18 135 Vamp::RealTime timestamp);
fazekasgy@0 136
cannam@18 137 FeatureSet getRemainingFeatures();
fazekasgy@0 138
fazekasgy@0 139 protected:
fazekasgy@0 140 PyObject *m_pyInstance;
cannam@18 141 size_t m_stepSize;
cannam@18 142 size_t m_blockSize;
cannam@18 143 size_t m_channels;
fazekasgy@0 144 std::string m_plugin;
fazekasgy@0 145 std::string m_class;
fazekasgy@0 146 std::string m_path;
fazekasgy@6 147 int m_processType;
fazekasgy@6 148 PyObject *m_pyProcess;
fazekasgy@6 149 InputDomain m_inputDomain;
fazekasgy@6 150
fazekasgy@6 151 bool initMaps() const;
fazekasgy@6 152 std::vector<std::string> PyList_To_StringVector (PyObject *inputList) const;
fazekasgy@6 153 std::vector<float> PyList_As_FloatVector (PyObject *inputList) const;
cannam@3 154
cannam@3 155 static Mutex m_pythonInterpreterMutex;
fazekasgy@0 156 };
fazekasgy@0 157
fazekasgy@0 158
fazekasgy@0 159 #endif