cannam@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@0: cannam@0: /* cannam@0: Vamp cannam@0: cannam@0: An API for audio analysis and feature extraction plugins. cannam@0: cannam@0: Centre for Digital Music, Queen Mary, University of London. cannam@0: Copyright 2006 Chris Cannam. cannam@0: cannam@0: Permission is hereby granted, free of charge, to any person cannam@0: obtaining a copy of this software and associated documentation cannam@0: files (the "Software"), to deal in the Software without cannam@0: restriction, including without limitation the rights to use, copy, cannam@0: modify, merge, publish, distribute, sublicense, and/or sell copies cannam@0: of the Software, and to permit persons to whom the Software is cannam@0: furnished to do so, subject to the following conditions: cannam@0: cannam@0: The above copyright notice and this permission notice shall be cannam@0: included in all copies or substantial portions of the Software. cannam@0: cannam@0: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, cannam@0: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF cannam@0: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND cannam@0: NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR cannam@0: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF cannam@0: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION cannam@0: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cannam@0: cannam@0: Except as contained in this notice, the names of the Centre for cannam@0: Digital Music; Queen Mary, University of London; and Chris Cannam cannam@0: shall not be used in advertising or otherwise to promote the sale, cannam@0: use or other dealings in this Software without prior written cannam@0: authorization. cannam@0: */ cannam@0: cannam@0: #ifndef _PLUGIN_ADAPTER_H_ cannam@0: #define _PLUGIN_ADAPTER_H_ cannam@0: cannam@0: #include "vamp.h" cannam@0: #include "Plugin.h" cannam@0: cannam@0: #include cannam@0: cannam@0: namespace Vamp { cannam@0: cannam@0: class PluginAdapterBase cannam@0: { cannam@0: public: cannam@0: virtual ~PluginAdapterBase(); cannam@0: const VampPluginDescriptor *getDescriptor(); cannam@0: cannam@0: protected: cannam@0: PluginAdapterBase(); cannam@0: cannam@0: virtual Plugin *createPlugin(float inputSampleRate) = 0; cannam@0: cannam@0: static VampPluginHandle vampInstantiate(const VampPluginDescriptor *desc, cannam@0: float inputSampleRate); cannam@0: cannam@0: static void vampCleanup(VampPluginHandle handle); cannam@0: cannam@0: static int vampInitialise(VampPluginHandle handle, unsigned int channels, cannam@0: unsigned int stepSize, unsigned int blockSize); cannam@0: cannam@0: static void vampReset(VampPluginHandle handle); cannam@0: cannam@0: static float vampGetParameter(VampPluginHandle handle, int param); cannam@0: static void vampSetParameter(VampPluginHandle handle, int param, float value); cannam@0: cannam@0: static unsigned int vampGetCurrentProgram(VampPluginHandle handle); cannam@0: static void vampSelectProgram(VampPluginHandle handle, unsigned int program); cannam@0: cannam@0: static unsigned int vampGetPreferredStepSize(VampPluginHandle handle); cannam@0: static unsigned int vampGetPreferredBlockSize(VampPluginHandle handle); cannam@0: static unsigned int vampGetMinChannelCount(VampPluginHandle handle); cannam@0: static unsigned int vampGetMaxChannelCount(VampPluginHandle handle); cannam@0: cannam@0: static unsigned int vampGetOutputCount(VampPluginHandle handle); cannam@0: cannam@0: static VampOutputDescriptor *vampGetOutputDescriptor(VampPluginHandle handle, cannam@0: unsigned int i); cannam@0: cannam@0: static void vampReleaseOutputDescriptor(VampOutputDescriptor *desc); cannam@0: cannam@0: static VampFeatureList **vampProcess(VampPluginHandle handle, cannam@0: float **inputBuffers, cannam@0: int sec, cannam@0: int nsec); cannam@0: cannam@0: static VampFeatureList **vampGetRemainingFeatures(VampPluginHandle handle); cannam@0: cannam@0: static void vampReleaseFeatureSet(VampFeatureList **fs); cannam@0: cannam@0: void cleanup(Plugin *plugin); cannam@0: void checkOutputMap(Plugin *plugin); cannam@0: unsigned int getOutputCount(Plugin *plugin); cannam@0: VampOutputDescriptor *getOutputDescriptor(Plugin *plugin, cannam@0: unsigned int i); cannam@0: VampFeatureList **process(Plugin *plugin, cannam@0: float **inputBuffers, cannam@0: int sec, int nsec); cannam@0: VampFeatureList **getRemainingFeatures(Plugin *plugin); cannam@0: VampFeatureList **convertFeatures(const Plugin::FeatureSet &features); cannam@0: cannam@0: typedef std::map AdapterMap; cannam@0: static AdapterMap m_adapterMap; cannam@0: static PluginAdapterBase *lookupAdapter(VampPluginHandle); cannam@0: cannam@0: bool m_populated; cannam@0: VampPluginDescriptor m_descriptor; cannam@0: Plugin::ParameterList m_parameters; cannam@0: Plugin::ProgramList m_programs; cannam@0: cannam@0: typedef std::map OutputMap; cannam@0: OutputMap m_pluginOutputs; cannam@0: cannam@0: typedef std::map FeatureBufferMap; cannam@0: FeatureBufferMap m_pluginFeatures; cannam@0: }; cannam@0: cannam@0: template cannam@0: class PluginAdapter : public PluginAdapterBase cannam@0: { cannam@0: public: cannam@0: PluginAdapter() : PluginAdapterBase() { } cannam@0: ~PluginAdapter() { } cannam@0: cannam@0: protected: cannam@0: Plugin *createPlugin(float inputSampleRate) { cannam@0: P *p = new P(inputSampleRate); cannam@0: Plugin *plugin = dynamic_cast(p); cannam@0: if (!plugin) { cannam@0: std::cerr << "ERROR: PluginAdapter::createPlugin: " cannam@0: << "Template type is not a plugin!" cannam@0: << std::endl; cannam@0: delete p; cannam@0: return 0; cannam@0: } cannam@0: return plugin; cannam@0: } cannam@0: }; cannam@0: cannam@0: } cannam@0: cannam@0: #endif cannam@0: