cannam@108: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@108: cannam@108: /* cannam@108: Vamp cannam@108: cannam@108: An API for audio analysis and feature extraction plugins. cannam@108: cannam@108: Centre for Digital Music, Queen Mary, University of London. cannam@108: Copyright 2006-2009 Chris Cannam and QMUL. cannam@108: cannam@108: Permission is hereby granted, free of charge, to any person cannam@108: obtaining a copy of this software and associated documentation cannam@108: files (the "Software"), to deal in the Software without cannam@108: restriction, including without limitation the rights to use, copy, cannam@108: modify, merge, publish, distribute, sublicense, and/or sell copies cannam@108: of the Software, and to permit persons to whom the Software is cannam@108: furnished to do so, subject to the following conditions: cannam@108: cannam@108: The above copyright notice and this permission notice shall be cannam@108: included in all copies or substantial portions of the Software. cannam@108: cannam@108: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, cannam@108: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF cannam@108: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND cannam@108: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR cannam@108: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF cannam@108: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION cannam@108: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cannam@108: cannam@108: Except as contained in this notice, the names of the Centre for cannam@108: Digital Music; Queen Mary, University of London; and Chris Cannam cannam@108: shall not be used in advertising or otherwise to promote the sale, cannam@108: use or other dealings in this Software without prior written cannam@108: authorization. cannam@108: */ cannam@108: cannam@108: #ifndef _VAMP_PLUGIN_LOADER_H_ cannam@108: #define _VAMP_PLUGIN_LOADER_H_ cannam@108: cannam@108: #include cannam@108: #include cannam@108: #include cannam@108: cannam@108: #include "hostguard.h" cannam@108: #include "PluginWrapper.h" cannam@108: cannam@108: _VAMP_SDK_HOSTSPACE_BEGIN(PluginLoader.h) cannam@108: cannam@108: namespace Vamp { cannam@108: cannam@108: class Plugin; cannam@108: cannam@108: namespace HostExt { cannam@108: cannam@108: /** cannam@108: * \class PluginLoader PluginLoader.h cannam@108: * cannam@108: * Vamp::HostExt::PluginLoader is a convenience class for discovering cannam@108: * and loading Vamp plugins using the typical plugin-path, library cannam@108: * naming, and categorisation conventions described in the Vamp SDK cannam@108: * documentation. This class is intended to greatly simplify the task cannam@108: * of becoming a Vamp plugin host for any C++ application. cannam@108: * cannam@108: * Hosts are not required by the Vamp specification to use the same cannam@108: * plugin search path and naming conventions as implemented by this cannam@108: * class, and are certainly not required to use this actual class. cannam@108: * But we do strongly recommend it. cannam@108: * cannam@108: * \note This class was introduced in version 1.1 of the Vamp plugin SDK. cannam@108: */ cannam@108: cannam@108: class PluginLoader cannam@108: { cannam@108: public: cannam@108: /** cannam@108: * Obtain a pointer to the singleton instance of PluginLoader. cannam@108: * Use this to obtain your loader object. cannam@108: */ cannam@108: static PluginLoader *getInstance(); cannam@108: cannam@108: /** cannam@108: * PluginKey is a string type that is used to identify a plugin cannam@108: * uniquely within the scope of "the current system". It consists cannam@108: * of the lower-cased base name of the plugin library, a colon cannam@108: * separator, and the identifier string for the plugin. It is cannam@108: * only meaningful in the context of a given plugin path (the one cannam@108: * returned by PluginHostAdapter::getPluginPath()). cannam@108: * cannam@108: * Use composePluginKey() to construct a plugin key from a known cannam@108: * plugin library name and identifier. cannam@108: * cannam@108: * Note: the fact that the library component of the key is cannam@108: * lower-cased implies that library names are matched cannam@108: * case-insensitively by the PluginLoader class, regardless of the cannam@108: * case sensitivity of the underlying filesystem. (Plugin cannam@108: * identifiers _are_ case sensitive, however.) Also, it is not cannam@108: * possible to portably extract a working library name from a cannam@108: * plugin key, as the result may fail on case-sensitive cannam@108: * filesystems. Use getLibraryPathForPlugin() instead. cannam@108: */ cannam@108: typedef std::string PluginKey; cannam@108: cannam@108: /** cannam@108: * PluginKeyList is a sequence of plugin keys, such as returned by cannam@108: * listPlugins(). cannam@108: */ cannam@108: typedef std::vector PluginKeyList; cannam@108: cannam@108: /** cannam@108: * PluginCategoryHierarchy is a sequence of general->specific cannam@108: * category names, as may be associated with a single plugin. cannam@108: * This sequence describes the location of a plugin within a cannam@108: * category forest, containing the human-readable names of the cannam@108: * plugin's category tree root, followed by each of the nodes down cannam@108: * to the leaf containing the plugin. cannam@108: * cannam@108: * \see getPluginCategory() cannam@108: */ cannam@108: typedef std::vector PluginCategoryHierarchy; cannam@108: cannam@108: /** cannam@108: * Search for all available Vamp plugins, and return a list of cannam@108: * them in the order in which they were found. cannam@108: */ cannam@108: PluginKeyList listPlugins(); cannam@108: cannam@108: /** cannam@108: * AdapterFlags contains a set of values that may be OR'd together cannam@108: * to indicate in which circumstances PluginLoader should use a cannam@108: * plugin adapter to make a plugin easier to use for a host that cannam@108: * does not want to cater for complex features. cannam@108: * cannam@108: * The available flags are: cannam@108: * cannam@108: * ADAPT_INPUT_DOMAIN - If the plugin expects frequency domain cannam@108: * input, wrap it in a PluginInputDomainAdapter that automatically cannam@108: * converts the plugin to one that expects time-domain input. cannam@108: * This enables a host to accommodate time- and frequency-domain cannam@108: * plugins without needing to do any conversion itself. cannam@108: * cannam@108: * ADAPT_CHANNEL_COUNT - Wrap the plugin in a PluginChannelAdapter cannam@108: * to handle any mismatch between the number of channels of audio cannam@108: * the plugin can handle and the number available in the host. cannam@108: * This enables a host to use plugins that may require the input cannam@108: * to be mixed down to mono, etc., without having to worry about cannam@108: * doing that itself. cannam@108: * cannam@108: * ADAPT_BUFFER_SIZE - Wrap the plugin in a PluginBufferingAdapter cannam@108: * permitting the host to provide audio input using any block cannam@108: * size, with no overlap, regardless of the plugin's preferred cannam@108: * block size (suitable for hosts that read from non-seekable cannam@108: * streaming media, for example). This adapter introduces some cannam@108: * run-time overhead and also changes the semantics of the plugin cannam@108: * slightly (see the PluginBufferingAdapter header documentation cannam@108: * for details). cannam@108: * cannam@108: * ADAPT_ALL_SAFE - Perform all available adaptations that are cannam@108: * meaningful for the plugin and "safe". Currently this means to cannam@108: * ADAPT_INPUT_DOMAIN if the plugin wants FrequencyDomain input; cannam@108: * ADAPT_CHANNEL_COUNT always; and ADAPT_BUFFER_SIZE never. cannam@108: * cannam@108: * ADAPT_ALL - Perform all available adaptations that are cannam@108: * meaningful for the plugin. cannam@108: * cannam@108: * See PluginInputDomainAdapter, PluginChannelAdapter and cannam@108: * PluginBufferingAdapter for more details of the classes that the cannam@108: * loader may use if these flags are set. cannam@108: */ cannam@108: enum AdapterFlags { cannam@108: cannam@108: ADAPT_INPUT_DOMAIN = 0x01, cannam@108: ADAPT_CHANNEL_COUNT = 0x02, cannam@108: ADAPT_BUFFER_SIZE = 0x04, cannam@108: cannam@108: ADAPT_ALL_SAFE = 0x03, cannam@108: cannam@108: ADAPT_ALL = 0xff cannam@108: }; cannam@108: cannam@108: /** cannam@108: * Load a Vamp plugin, given its identifying key. If the plugin cannam@108: * could not be loaded, returns 0. cannam@108: * cannam@108: * The returned plugin should be deleted (using the standard C++ cannam@108: * delete keyword) after use. cannam@108: * cannam@108: * \param adapterFlags a bitwise OR of the values in the AdapterFlags cannam@108: * enumeration, indicating under which circumstances an adapter should be cannam@108: * used to wrap the original plugin. If adapterFlags is 0, no cannam@108: * optional adapters will be used. Otherwise, the returned plugin cannam@108: * may be of an adapter class type which will behave identically cannam@108: * to the original plugin, apart from any particular features cannam@108: * implemented by the adapter itself. cannam@108: * cannam@108: * \see AdapterFlags, PluginInputDomainAdapter, PluginChannelAdapter cannam@108: */ cannam@108: Plugin *loadPlugin(PluginKey key, cannam@108: float inputSampleRate, cannam@108: int adapterFlags = 0); cannam@108: cannam@108: /** cannam@108: * Given a Vamp plugin library name and plugin identifier, return cannam@108: * the corresponding plugin key in a form suitable for passing in to cannam@108: * loadPlugin(). cannam@108: */ cannam@108: PluginKey composePluginKey(std::string libraryName, cannam@108: std::string identifier); cannam@108: cannam@108: /** cannam@108: * Return the category hierarchy for a Vamp plugin, given its cannam@108: * identifying key. cannam@108: * cannam@108: * If the plugin has no category information, return an empty cannam@108: * hierarchy. cannam@108: * cannam@108: * \see PluginCategoryHierarchy cannam@108: */ cannam@108: PluginCategoryHierarchy getPluginCategory(PluginKey plugin); cannam@108: cannam@108: /** cannam@108: * Return the file path of the dynamic library from which the cannam@108: * given plugin will be loaded (if available). cannam@108: */ cannam@108: std::string getLibraryPathForPlugin(PluginKey plugin); cannam@108: cannam@108: protected: cannam@108: PluginLoader(); cannam@108: virtual ~PluginLoader(); cannam@108: cannam@108: class Impl; cannam@108: Impl *m_impl; cannam@108: cannam@108: static PluginLoader *m_instance; cannam@108: }; cannam@108: cannam@108: } cannam@108: cannam@108: } cannam@108: cannam@108: _VAMP_SDK_HOSTSPACE_END(PluginLoader.h) cannam@108: cannam@108: #endif cannam@108: