annotate vamp-hostsdk/PluginLoader.h @ 434:e979a9c4ffb6 vampipe

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