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