comparison vamp-hostsdk/PluginLoader.h @ 233:521734d2b498 distinct-libraries

* Flatten directory tree a bit, update doxygen
author cannam
date Fri, 07 Nov 2008 15:28:33 +0000
parents
children 3cf5bd155e5b
comparison
equal deleted inserted replaced
232:71ea10a3cbe7 233:521734d2b498
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-2007 Chris Cannam and QMUL.
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 AUTHORS 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 _VAMP_PLUGIN_LOADER_H_
38 #define _VAMP_PLUGIN_LOADER_H_
39
40 #include <vector>
41 #include <string>
42 #include <map>
43
44 #include "PluginWrapper.h"
45
46 namespace Vamp {
47
48 class Plugin;
49
50 namespace HostExt {
51
52 /**
53 * \class PluginLoader PluginLoader.h <vamp-hostsdk/PluginLoader.h>
54 *
55 * Vamp::HostExt::PluginLoader is a convenience class for discovering
56 * and loading Vamp plugins using the typical plugin-path, library
57 * naming, and categorisation conventions described in the Vamp SDK
58 * documentation. This class is intended to greatly simplify the task
59 * of becoming a Vamp plugin host for any C++ application.
60 *
61 * Hosts are not required by the Vamp specification to use the same
62 * plugin search path and naming conventions as implemented by this
63 * class, and are certainly not required to use this actual class.
64 * But we do strongly recommend it.
65 *
66 * \note This class was introduced in version 1.1 of the Vamp plugin SDK.
67 */
68
69 class PluginLoader
70 {
71 public:
72 /**
73 * Obtain a pointer to the singleton instance of PluginLoader.
74 * Use this to obtain your loader object.
75 */
76 static PluginLoader *getInstance();
77
78 /**
79 * PluginKey is a string type that is used to identify a plugin
80 * uniquely within the scope of "the current system". It consists
81 * of the lower-cased base name of the plugin library, a colon
82 * separator, and the identifier string for the plugin. It is
83 * only meaningful in the context of a given plugin path (the one
84 * returned by PluginHostAdapter::getPluginPath()).
85 *
86 * Use composePluginKey() to construct a plugin key from a known
87 * plugin library name and identifier.
88 *
89 * Note: the fact that the library component of the key is
90 * lower-cased implies that library names are matched
91 * case-insensitively by the PluginLoader class, regardless of the
92 * case sensitivity of the underlying filesystem. (Plugin
93 * identifiers _are_ case sensitive, however.) Also, it is not
94 * possible to portably extract a working library name from a
95 * plugin key, as the result may fail on case-sensitive
96 * filesystems. Use getLibraryPathForPlugin() instead.
97 */
98 typedef std::string PluginKey;
99
100 /**
101 * PluginKeyList is a sequence of plugin keys, such as returned by
102 * listPlugins().
103 */
104 typedef std::vector<PluginKey> PluginKeyList;
105
106 /**
107 * PluginCategoryHierarchy is a sequence of general->specific
108 * category names, as may be associated with a single plugin.
109 * This sequence describes the location of a plugin within a
110 * category forest, containing the human-readable names of the
111 * plugin's category tree root, followed by each of the nodes down
112 * to the leaf containing the plugin.
113 *
114 * \see getPluginCategory()
115 */
116 typedef std::vector<std::string> PluginCategoryHierarchy;
117
118 /**
119 * Search for all available Vamp plugins, and return a list of
120 * them in the order in which they were found.
121 */
122 PluginKeyList listPlugins();
123
124 /**
125 * AdapterFlags contains a set of values that may be OR'd together
126 * to indicate in which circumstances PluginLoader should use a
127 * plugin adapter to make a plugin easier to use for a host that
128 * does not want to cater for complex features.
129 *
130 * The available flags are:
131 *
132 * ADAPT_INPUT_DOMAIN - If the plugin expects frequency domain
133 * input, wrap it in a PluginInputDomainAdapter that automatically
134 * converts the plugin to one that expects time-domain input.
135 * This enables a host to accommodate time- and frequency-domain
136 * plugins without needing to do any conversion itself.
137 *
138 * ADAPT_CHANNEL_COUNT - Wrap the plugin in a PluginChannelAdapter
139 * to handle any mismatch between the number of channels of audio
140 * the plugin can handle and the number available in the host.
141 * This enables a host to use plugins that may require the input
142 * to be mixed down to mono, etc., without having to worry about
143 * doing that itself.
144 *
145 * ADAPT_BUFFER_SIZE - Wrap the plugin in a PluginBufferingAdapter
146 * permitting the host to provide audio input using any block
147 * size, with no overlap, regardless of the plugin's preferred
148 * block size (suitable for hosts that read from non-seekable
149 * streaming media, for example). This adapter introduces some
150 * run-time overhead and also changes the semantics of the plugin
151 * slightly (see the PluginBufferingAdapter header documentation
152 * for details).
153 *
154 * ADAPT_ALL_SAFE - Perform all available adaptations that are
155 * meaningful for the plugin and "safe". Currently this means to
156 * ADAPT_INPUT_DOMAIN if the plugin wants FrequencyDomain input;
157 * ADAPT_CHANNEL_COUNT always; and ADAPT_BUFFER_SIZE never.
158 *
159 * ADAPT_ALL - Perform all available adaptations that are
160 * meaningful for the plugin.
161 *
162 * See PluginInputDomainAdapter, PluginChannelAdapter and
163 * PluginBufferingAdapter for more details of the classes that the
164 * loader may use if these flags are set.
165 */
166 enum AdapterFlags {
167
168 ADAPT_INPUT_DOMAIN = 0x01,
169 ADAPT_CHANNEL_COUNT = 0x02,
170 ADAPT_BUFFER_SIZE = 0x04,
171
172 ADAPT_ALL_SAFE = 0x03,
173
174 ADAPT_ALL = 0xff
175 };
176
177 /**
178 * Load a Vamp plugin, given its identifying key. If the plugin
179 * could not be loaded, returns 0.
180 *
181 * The returned plugin should be deleted (using the standard C++
182 * delete keyword) after use.
183 *
184 * \param adapterFlags a bitwise OR of the values in the AdapterFlags
185 * enumeration, indicating under which circumstances an adapter should be
186 * used to wrap the original plugin. If adapterFlags is 0, no
187 * optional adapters will be used. Otherwise, the returned plugin
188 * may be of an adapter class type which will behave identically
189 * to the original plugin, apart from any particular features
190 * implemented by the adapter itself.
191 *
192 * \see AdapterFlags, PluginInputDomainAdapter, PluginChannelAdapter
193 */
194 Plugin *loadPlugin(PluginKey key,
195 float inputSampleRate,
196 int adapterFlags = 0);
197
198 /**
199 * Given a Vamp plugin library name and plugin identifier, return
200 * the corresponding plugin key in a form suitable for passing in to
201 * loadPlugin().
202 */
203 PluginKey composePluginKey(std::string libraryName,
204 std::string identifier);
205
206 /**
207 * Return the category hierarchy for a Vamp plugin, given its
208 * identifying key.
209 *
210 * If the plugin has no category information, return an empty
211 * hierarchy.
212 *
213 * \see PluginCategoryHierarchy
214 */
215 PluginCategoryHierarchy getPluginCategory(PluginKey plugin);
216
217 /**
218 * Return the file path of the dynamic library from which the
219 * given plugin will be loaded (if available).
220 */
221 std::string getLibraryPathForPlugin(PluginKey plugin);
222
223 protected:
224 PluginLoader();
225 virtual ~PluginLoader();
226
227 class Impl;
228 Impl *m_impl;
229
230 static PluginLoader *m_instance;
231 };
232
233 }
234
235 }
236
237 #endif
238