annotate vamp-sdk/hostext/PluginLoader.h @ 88:d17b9ca3b8c9

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