cannam@18: /* -*- c-basic-offset: 8 indent-tabs-mode: t -*- */ fazekasgy@0: /* fazekasgy@0: Vamp fazekasgy@0: fazekasgy@0: An API for audio analysis and feature extraction plugins. fazekasgy@0: fazekasgy@0: Centre for Digital Music, Queen Mary, University of London. fazekasgy@0: Copyright 2006 Chris Cannam. fazekasgy@0: fazekasgy@0: Permission is hereby granted, free of charge, to any person fazekasgy@0: obtaining a copy of this software and associated documentation fazekasgy@0: files (the "Software"), to deal in the Software without fazekasgy@0: restriction, including without limitation the rights to use, copy, fazekasgy@0: modify, merge, publish, distribute, sublicense, and/or sell copies fazekasgy@0: of the Software, and to permit persons to whom the Software is fazekasgy@0: furnished to do so, subject to the following conditions: fazekasgy@0: fazekasgy@0: The above copyright notice and this permission notice shall be fazekasgy@0: included in all copies or substantial portions of the Software. fazekasgy@0: fazekasgy@0: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, fazekasgy@0: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF fazekasgy@0: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND fazekasgy@0: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR fazekasgy@0: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF fazekasgy@0: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION fazekasgy@0: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fazekasgy@0: fazekasgy@0: Except as contained in this notice, the names of the Centre for fazekasgy@0: Digital Music; Queen Mary, University of London; and Chris Cannam fazekasgy@0: shall not be used in advertising or otherwise to promote the sale, fazekasgy@0: use or other dealings in this Software without prior written fazekasgy@0: authorization. fazekasgy@0: */ fazekasgy@0: fazekasgy@0: /** cannam@7: * This plugin abstracts appropriate Python Scripts as a Vamp plugin. fazekasgy@0: */ fazekasgy@0: fazekasgy@0: #ifndef _PYTHON_WRAPPER_PLUGIN_H_ fazekasgy@0: #define _PYTHON_WRAPPER_PLUGIN_H_ fazekasgy@0: fazekasgy@0: #include "vamp-sdk/Plugin.h" cannam@3: #include cannam@3: cannam@3: #include "Mutex.h" fazekasgy@0: fazekasgy@0: //fields in OutputDescriptor cannam@18: namespace o { fazekasgy@0: enum eOutDescriptors { fazekasgy@0: not_found, fazekasgy@0: identifier, fazekasgy@0: name, fazekasgy@0: description, fazekasgy@0: unit, fazekasgy@0: hasFixedBinCount, fazekasgy@0: binCount, fazekasgy@0: binNames, fazekasgy@0: hasKnownExtents, fazekasgy@0: minValue, fazekasgy@0: maxValue, fazekasgy@0: isQuantized, fazekasgy@0: quantizeStep, fazekasgy@0: sampleType, fazekasgy@0: sampleRate, cannam@18: hasDuration, fazekasgy@0: endNode fazekasgy@0: }; cannam@18: } fazekasgy@0: fazekasgy@0: namespace p { fazekasgy@0: enum eParmDescriptors { fazekasgy@0: not_found, fazekasgy@0: identifier, fazekasgy@0: name, fazekasgy@0: description, fazekasgy@0: unit, fazekasgy@0: minValue, fazekasgy@0: maxValue, fazekasgy@0: defaultValue, cannam@22: isQuantized, cannam@22: quantizeStep fazekasgy@0: }; fazekasgy@0: } fazekasgy@0: fazekasgy@0: enum eSampleTypes { fazekasgy@0: OneSamplePerStep, fazekasgy@0: FixedSampleRate, fazekasgy@0: VariableSampleRate fazekasgy@0: }; fazekasgy@0: fazekasgy@0: enum eFeatureFields { fazekasgy@0: unknown, fazekasgy@0: hasTimestamp, fazekasgy@0: timeStamp, cannam@18: hasDuration, cannam@18: duration, fazekasgy@0: values, fazekasgy@0: label fazekasgy@0: }; fazekasgy@0: fazekasgy@6: enum eProcessType { fazekasgy@6: not_implemented, fazekasgy@6: legacyProcess, fazekasgy@6: numpyProcess fazekasgy@6: }; fazekasgy@0: fazekasgy@0: class PyPlugin : public Vamp::Plugin fazekasgy@0: { fazekasgy@0: public: cannam@24: PyPlugin(std::string plugin,float inputSampleRate, PyObject *pyClass); cannam@18: virtual ~PyPlugin(); fazekasgy@0: cannam@18: bool initialise(size_t channels, size_t stepSize, size_t blockSize); cannam@18: void reset(); fazekasgy@6: fazekasgy@0: InputDomain getInputDomain() const; fazekasgy@0: size_t getPreferredBlockSize() const; fazekasgy@0: size_t getPreferredStepSize() const; fazekasgy@0: size_t getMinChannelCount() const; fazekasgy@0: size_t getMaxChannelCount() const; fazekasgy@0: cannam@18: std::string getIdentifier() const; cannam@18: std::string getName() const; cannam@18: std::string getDescription() const; cannam@18: std::string getMaker() const; cannam@18: int getPluginVersion() const; cannam@18: std::string getCopyright() const; cannam@18: cannam@18: OutputList getOutputDescriptors() const; cannam@18: ParameterList getParameterDescriptors() const; fazekasgy@0: float getParameter(std::string paramid) const; fazekasgy@0: void setParameter(std::string paramid, float newval); fazekasgy@0: cannam@18: FeatureSet process(const float *const *inputBuffers, cannam@18: Vamp::RealTime timestamp); fazekasgy@0: cannam@18: FeatureSet getRemainingFeatures(); fazekasgy@0: fazekasgy@0: protected: cannam@24: PyObject *m_pyClass; fazekasgy@0: PyObject *m_pyInstance; cannam@18: size_t m_stepSize; cannam@18: size_t m_blockSize; cannam@18: size_t m_channels; fazekasgy@0: std::string m_plugin; fazekasgy@0: std::string m_class; fazekasgy@0: std::string m_path; fazekasgy@6: int m_processType; fazekasgy@6: PyObject *m_pyProcess; fazekasgy@6: InputDomain m_inputDomain; fazekasgy@6: fazekasgy@6: bool initMaps() const; fazekasgy@6: std::vector PyList_To_StringVector (PyObject *inputList) const; fazekasgy@6: std::vector PyList_As_FloatVector (PyObject *inputList) const; cannam@3: cannam@3: static Mutex m_pythonInterpreterMutex; fazekasgy@0: }; fazekasgy@0: fazekasgy@0: fazekasgy@0: #endif