annotate vamp-hostsdk/hostext/PluginLoader.h @ 231:90e3acb4a728 distinct-libraries

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