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