cannam@56
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@56
|
2
|
cannam@56
|
3 /*
|
cannam@56
|
4 Vamp
|
cannam@56
|
5
|
cannam@56
|
6 An API for audio analysis and feature extraction plugins.
|
cannam@56
|
7
|
cannam@56
|
8 Centre for Digital Music, Queen Mary, University of London.
|
cannam@56
|
9 Copyright 2006 Chris Cannam.
|
cannam@56
|
10
|
cannam@56
|
11 Permission is hereby granted, free of charge, to any person
|
cannam@56
|
12 obtaining a copy of this software and associated documentation
|
cannam@56
|
13 files (the "Software"), to deal in the Software without
|
cannam@56
|
14 restriction, including without limitation the rights to use, copy,
|
cannam@56
|
15 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@56
|
16 of the Software, and to permit persons to whom the Software is
|
cannam@56
|
17 furnished to do so, subject to the following conditions:
|
cannam@56
|
18
|
cannam@56
|
19 The above copyright notice and this permission notice shall be
|
cannam@56
|
20 included in all copies or substantial portions of the Software.
|
cannam@56
|
21
|
cannam@56
|
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@56
|
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@56
|
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@56
|
25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@56
|
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@56
|
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@56
|
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@56
|
29
|
cannam@56
|
30 Except as contained in this notice, the names of the Centre for
|
cannam@56
|
31 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@56
|
32 shall not be used in advertising or otherwise to promote the sale,
|
cannam@56
|
33 use or other dealings in this Software without prior written
|
cannam@56
|
34 authorization.
|
cannam@56
|
35 */
|
cannam@56
|
36
|
cannam@56
|
37 #ifndef _VAMP_PLUGIN_LOADER_H_
|
cannam@56
|
38 #define _VAMP_PLUGIN_LOADER_H_
|
cannam@56
|
39
|
cannam@56
|
40 #include <vector>
|
cannam@56
|
41 #include <string>
|
cannam@56
|
42 #include <map>
|
cannam@56
|
43
|
cannam@59
|
44 #include "PluginWrapper.h"
|
cannam@59
|
45
|
cannam@56
|
46 namespace Vamp {
|
cannam@56
|
47
|
cannam@56
|
48 class Plugin;
|
cannam@56
|
49
|
cannam@59
|
50 namespace HostExt {
|
cannam@59
|
51
|
cannam@62
|
52 /**
|
cannam@62
|
53 * Vamp::HostExt::PluginLoader is a convenience class for discovering
|
cannam@62
|
54 * and loading Vamp plugins using the typical plugin-path, library
|
cannam@62
|
55 * naming, and categorisation conventions described in the Vamp SDK
|
cannam@62
|
56 * documentation. This class is intended to greatly simplify the task
|
cannam@62
|
57 * of becoming a Vamp plugin host for any C++ application.
|
cannam@62
|
58 *
|
cannam@62
|
59 * Hosts are not required by the Vamp specification to use the same
|
cannam@62
|
60 * plugin search path and naming conventions as implemented by this
|
cannam@62
|
61 * class, and are certainly not required to use this actual class.
|
cannam@62
|
62 * But it's recommended, for sound practical reasons.
|
cannam@62
|
63 */
|
cannam@62
|
64
|
cannam@56
|
65 class PluginLoader
|
cannam@56
|
66 {
|
cannam@56
|
67 public:
|
cannam@62
|
68 /**
|
cannam@62
|
69 * PluginLoader is a singleton class. This function returns a
|
cannam@62
|
70 * pointer to the single instance of it. Use this to obtain your
|
cannam@62
|
71 * loader object.
|
cannam@62
|
72 */
|
cannam@59
|
73 static PluginLoader *getInstance();
|
cannam@56
|
74
|
cannam@62
|
75 /**
|
cannam@62
|
76 * PluginKey is a string type that is used to identify a plugin
|
cannam@62
|
77 * uniquely within the scope of "the current system". It consists
|
cannam@62
|
78 * of the base name of the plugin library, a colon separator, and
|
cannam@62
|
79 * the identifier string for the plugin. It is only meaningful in
|
cannam@62
|
80 * the context of a given plugin path (the one returned by
|
cannam@62
|
81 * PluginHostAdapter::getPluginPath()).
|
cannam@62
|
82 *
|
cannam@62
|
83 * Use composePluginKey to construct a plugin key from a known
|
cannam@62
|
84 * plugin library name and identifier.
|
cannam@62
|
85 */
|
cannam@56
|
86 typedef std::string PluginKey;
|
cannam@62
|
87
|
cannam@62
|
88 /**
|
cannam@62
|
89 * PluginKeyList is a sequence of plugin keys, such as returned by
|
cannam@62
|
90 * a plugin lookup function.
|
cannam@62
|
91 */
|
cannam@60
|
92 typedef std::vector<PluginKey> PluginKeyList;
|
cannam@62
|
93
|
cannam@62
|
94 /**
|
cannam@62
|
95 * PluginCategoryHierarchy is a sequence of general->specific
|
cannam@62
|
96 * category names, as may be associated with a single plugin.
|
cannam@62
|
97 * This sequence describes the location of a plugin within a
|
cannam@62
|
98 * category forest, containing the human-readable names of the
|
cannam@62
|
99 * plugin's category tree root, followed by each of the nodes down
|
cannam@62
|
100 * to the leaf containing the plugin.
|
cannam@62
|
101 */
|
cannam@57
|
102 typedef std::vector<std::string> PluginCategoryHierarchy;
|
cannam@56
|
103
|
cannam@62
|
104 /**
|
cannam@62
|
105 * Search for all available Vamp plugins, and return a list of
|
cannam@62
|
106 * them in the order in which they were found.
|
cannam@62
|
107 */
|
cannam@62
|
108 PluginKeyList listPlugins();
|
cannam@56
|
109
|
cannam@62
|
110 /**
|
cannam@62
|
111 * AdapterFlags contains a set of values that may be OR'd together
|
cannam@62
|
112 * to indicate in which circumstances PluginLoader should use a
|
cannam@62
|
113 * plugin adapter to make a plugin easier to use for a host that
|
cannam@62
|
114 * does not want to cater for complex features.
|
cannam@62
|
115 *
|
cannam@62
|
116 * The available flags are:
|
cannam@62
|
117 *
|
cannam@62
|
118 * ADAPT_INPUT_DOMAIN - If the plugin expects frequency domain
|
cannam@62
|
119 * input, wrap it in a PluginInputDomainAdapter that automatically
|
cannam@62
|
120 * converts the plugin to one that expects time-domain input.
|
cannam@62
|
121 * This enables a host to accommodate time- and frequency-domain
|
cannam@62
|
122 * plugins without needing to do any conversion itself.
|
cannam@62
|
123 *
|
cannam@62
|
124 * ADAPT_CHANNEL_COUNT - Wrap the plugin in a PluginChannelAdapter
|
cannam@62
|
125 * to handle any mismatch between the number of channels of audio
|
cannam@62
|
126 * the plugin can handle and the number available in the host.
|
cannam@62
|
127 * This enables a host to use plugins that may require the input
|
cannam@62
|
128 * to be mixed down to mono, etc., without having to worry about
|
cannam@62
|
129 * doing that itself.
|
cannam@62
|
130 *
|
cannam@62
|
131 * See PluginInputDomainAdapter and PluginChannelAdapter for more
|
cannam@62
|
132 * details of the classes that the loader may use if these flags
|
cannam@62
|
133 * are set.
|
cannam@62
|
134 */
|
cannam@61
|
135 enum AdapterFlags {
|
cannam@61
|
136 ADAPT_INPUT_DOMAIN = 0x01,
|
cannam@61
|
137 ADAPT_CHANNEL_COUNT = 0x02,
|
cannam@61
|
138 ADAPT_ALL = 0xff
|
cannam@61
|
139 };
|
cannam@61
|
140
|
cannam@62
|
141 /**
|
cannam@62
|
142 * Load a Vamp plugin, given its identifying key. If the plugin
|
cannam@62
|
143 * could not be loaded, returns 0.
|
cannam@62
|
144 *
|
cannam@62
|
145 * adapterFlags is a bitwise OR of the values in the AdapterFlags
|
cannam@62
|
146 * enum, indicating under which circumstances an adapter should be
|
cannam@62
|
147 * used to wrap the original plugin. See AdapterFlags for more
|
cannam@62
|
148 * details. If adapterFlags is 0, no optional adapters will be
|
cannam@62
|
149 * used.
|
cannam@62
|
150 *
|
cannam@62
|
151 * The returned plugin should be deleted (using the standard C++
|
cannam@62
|
152 * delete) after use.
|
cannam@62
|
153 */
|
cannam@62
|
154 Plugin *loadPlugin(PluginKey key,
|
cannam@61
|
155 float inputSampleRate,
|
cannam@61
|
156 int adapterFlags = 0);
|
cannam@56
|
157
|
cannam@62
|
158 /**
|
cannam@62
|
159 * Given a Vamp plugin library name and plugin identifier, return
|
cannam@62
|
160 * the corresponding plugin key in a form suitable for passing in to
|
cannam@62
|
161 * loadPlugin.
|
cannam@62
|
162 */
|
cannam@62
|
163 PluginKey composePluginKey(std::string libraryName,
|
cannam@62
|
164 std::string identifier);
|
cannam@62
|
165
|
cannam@62
|
166 /**
|
cannam@62
|
167 * Return the category hierarchy for a Vamp plugin, given its
|
cannam@62
|
168 * identifying key. See PluginCategoryHierarchy documentation for
|
cannam@62
|
169 * more details.
|
cannam@62
|
170 *
|
cannam@62
|
171 * If the plugin has no category information, return an empty
|
cannam@62
|
172 * hierarchy.
|
cannam@62
|
173 */
|
cannam@57
|
174 PluginCategoryHierarchy getPluginCategory(PluginKey plugin);
|
cannam@57
|
175
|
cannam@62
|
176 /**
|
cannam@62
|
177 * Return the file path of the dynamic library from which the
|
cannam@62
|
178 * given plugin will be loaded (if available).
|
cannam@62
|
179 */
|
cannam@57
|
180 std::string getLibraryPathForPlugin(PluginKey plugin);
|
cannam@56
|
181
|
cannam@56
|
182 protected:
|
cannam@59
|
183 PluginLoader();
|
cannam@59
|
184 virtual ~PluginLoader();
|
cannam@59
|
185
|
cannam@59
|
186 class PluginDeletionNotifyAdapter : public PluginWrapper {
|
cannam@59
|
187 public:
|
cannam@59
|
188 PluginDeletionNotifyAdapter(Plugin *plugin, PluginLoader *loader);
|
cannam@59
|
189 virtual ~PluginDeletionNotifyAdapter();
|
cannam@59
|
190 protected:
|
cannam@59
|
191 PluginLoader *m_loader;
|
cannam@59
|
192 };
|
cannam@59
|
193
|
cannam@59
|
194 virtual void pluginDeleted(PluginDeletionNotifyAdapter *adapter);
|
cannam@59
|
195
|
cannam@59
|
196 std::map<PluginKey, std::string> m_pluginLibraryNameMap;
|
cannam@59
|
197 void generateLibraryMap();
|
cannam@59
|
198
|
cannam@57
|
199 std::map<PluginKey, PluginCategoryHierarchy> m_taxonomy;
|
cannam@57
|
200 void generateTaxonomy();
|
cannam@59
|
201
|
cannam@59
|
202 std::map<Plugin *, void *> m_pluginLibraryHandleMap;
|
cannam@59
|
203
|
cannam@59
|
204 void *loadLibrary(std::string path);
|
cannam@59
|
205 void unloadLibrary(void *handle);
|
cannam@59
|
206 void *lookupInLibrary(void *handle, const char *symbol);
|
cannam@59
|
207
|
cannam@59
|
208 std::string splicePath(std::string a, std::string b);
|
cannam@59
|
209 std::vector<std::string> listFiles(std::string dir, std::string ext);
|
cannam@59
|
210
|
cannam@59
|
211 static PluginLoader *m_instance;
|
cannam@56
|
212 };
|
cannam@56
|
213
|
cannam@56
|
214 }
|
cannam@56
|
215
|
cannam@59
|
216 }
|
cannam@56
|
217
|
cannam@56
|
218 #endif
|
cannam@56
|
219
|