annotate sdk/PluginAdapter.h @ 0:6479539d1b32

* Importing first cut of Sonic Visualiser's Vamp plugin format SDK
author cannam
date Fri, 31 Mar 2006 14:21:51 +0000
parents
children
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 Vamp
cannam@0 5
cannam@0 6 An API for audio analysis and feature extraction plugins.
cannam@0 7
cannam@0 8 Centre for Digital Music, Queen Mary, University of London.
cannam@0 9 Copyright 2006 Chris Cannam.
cannam@0 10
cannam@0 11 Permission is hereby granted, free of charge, to any person
cannam@0 12 obtaining a copy of this software and associated documentation
cannam@0 13 files (the "Software"), to deal in the Software without
cannam@0 14 restriction, including without limitation the rights to use, copy,
cannam@0 15 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@0 16 of the Software, and to permit persons to whom the Software is
cannam@0 17 furnished to do so, subject to the following conditions:
cannam@0 18
cannam@0 19 The above copyright notice and this permission notice shall be
cannam@0 20 included in all copies or substantial portions of the Software.
cannam@0 21
cannam@0 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@0 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@0 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@0 25 NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR
cannam@0 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@0 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@0 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@0 29
cannam@0 30 Except as contained in this notice, the names of the Centre for
cannam@0 31 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@0 32 shall not be used in advertising or otherwise to promote the sale,
cannam@0 33 use or other dealings in this Software without prior written
cannam@0 34 authorization.
cannam@0 35 */
cannam@0 36
cannam@0 37 #ifndef _PLUGIN_ADAPTER_H_
cannam@0 38 #define _PLUGIN_ADAPTER_H_
cannam@0 39
cannam@0 40 #include "vamp.h"
cannam@0 41 #include "Plugin.h"
cannam@0 42
cannam@0 43 #include <map>
cannam@0 44
cannam@0 45 namespace Vamp {
cannam@0 46
cannam@0 47 class PluginAdapterBase
cannam@0 48 {
cannam@0 49 public:
cannam@0 50 virtual ~PluginAdapterBase();
cannam@0 51 const VampPluginDescriptor *getDescriptor();
cannam@0 52
cannam@0 53 protected:
cannam@0 54 PluginAdapterBase();
cannam@0 55
cannam@0 56 virtual Plugin *createPlugin(float inputSampleRate) = 0;
cannam@0 57
cannam@0 58 static VampPluginHandle vampInstantiate(const VampPluginDescriptor *desc,
cannam@0 59 float inputSampleRate);
cannam@0 60
cannam@0 61 static void vampCleanup(VampPluginHandle handle);
cannam@0 62
cannam@0 63 static int vampInitialise(VampPluginHandle handle, unsigned int channels,
cannam@0 64 unsigned int stepSize, unsigned int blockSize);
cannam@0 65
cannam@0 66 static void vampReset(VampPluginHandle handle);
cannam@0 67
cannam@0 68 static float vampGetParameter(VampPluginHandle handle, int param);
cannam@0 69 static void vampSetParameter(VampPluginHandle handle, int param, float value);
cannam@0 70
cannam@0 71 static unsigned int vampGetCurrentProgram(VampPluginHandle handle);
cannam@0 72 static void vampSelectProgram(VampPluginHandle handle, unsigned int program);
cannam@0 73
cannam@0 74 static unsigned int vampGetPreferredStepSize(VampPluginHandle handle);
cannam@0 75 static unsigned int vampGetPreferredBlockSize(VampPluginHandle handle);
cannam@0 76 static unsigned int vampGetMinChannelCount(VampPluginHandle handle);
cannam@0 77 static unsigned int vampGetMaxChannelCount(VampPluginHandle handle);
cannam@0 78
cannam@0 79 static unsigned int vampGetOutputCount(VampPluginHandle handle);
cannam@0 80
cannam@0 81 static VampOutputDescriptor *vampGetOutputDescriptor(VampPluginHandle handle,
cannam@0 82 unsigned int i);
cannam@0 83
cannam@0 84 static void vampReleaseOutputDescriptor(VampOutputDescriptor *desc);
cannam@0 85
cannam@0 86 static VampFeatureList **vampProcess(VampPluginHandle handle,
cannam@0 87 float **inputBuffers,
cannam@0 88 int sec,
cannam@0 89 int nsec);
cannam@0 90
cannam@0 91 static VampFeatureList **vampGetRemainingFeatures(VampPluginHandle handle);
cannam@0 92
cannam@0 93 static void vampReleaseFeatureSet(VampFeatureList **fs);
cannam@0 94
cannam@0 95 void cleanup(Plugin *plugin);
cannam@0 96 void checkOutputMap(Plugin *plugin);
cannam@0 97 unsigned int getOutputCount(Plugin *plugin);
cannam@0 98 VampOutputDescriptor *getOutputDescriptor(Plugin *plugin,
cannam@0 99 unsigned int i);
cannam@0 100 VampFeatureList **process(Plugin *plugin,
cannam@0 101 float **inputBuffers,
cannam@0 102 int sec, int nsec);
cannam@0 103 VampFeatureList **getRemainingFeatures(Plugin *plugin);
cannam@0 104 VampFeatureList **convertFeatures(const Plugin::FeatureSet &features);
cannam@0 105
cannam@0 106 typedef std::map<const void *, PluginAdapterBase *> AdapterMap;
cannam@0 107 static AdapterMap m_adapterMap;
cannam@0 108 static PluginAdapterBase *lookupAdapter(VampPluginHandle);
cannam@0 109
cannam@0 110 bool m_populated;
cannam@0 111 VampPluginDescriptor m_descriptor;
cannam@0 112 Plugin::ParameterList m_parameters;
cannam@0 113 Plugin::ProgramList m_programs;
cannam@0 114
cannam@0 115 typedef std::map<Plugin *, Plugin::OutputList *> OutputMap;
cannam@0 116 OutputMap m_pluginOutputs;
cannam@0 117
cannam@0 118 typedef std::map<Plugin *, VampFeature ***> FeatureBufferMap;
cannam@0 119 FeatureBufferMap m_pluginFeatures;
cannam@0 120 };
cannam@0 121
cannam@0 122 template <typename P>
cannam@0 123 class PluginAdapter : public PluginAdapterBase
cannam@0 124 {
cannam@0 125 public:
cannam@0 126 PluginAdapter() : PluginAdapterBase() { }
cannam@0 127 ~PluginAdapter() { }
cannam@0 128
cannam@0 129 protected:
cannam@0 130 Plugin *createPlugin(float inputSampleRate) {
cannam@0 131 P *p = new P(inputSampleRate);
cannam@0 132 Plugin *plugin = dynamic_cast<Plugin *>(p);
cannam@0 133 if (!plugin) {
cannam@0 134 std::cerr << "ERROR: PluginAdapter::createPlugin: "
cannam@0 135 << "Template type is not a plugin!"
cannam@0 136 << std::endl;
cannam@0 137 delete p;
cannam@0 138 return 0;
cannam@0 139 }
cannam@0 140 return plugin;
cannam@0 141 }
cannam@0 142 };
cannam@0 143
cannam@0 144 }
cannam@0 145
cannam@0 146 #endif
cannam@0 147