annotate src/vamp-plugin-sdk-2.5/vamp-hostsdk/PluginLoader.h @ 23:619f715526df sv_v2.1

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