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