c@75: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@75: c@75: /* c@75: Piper C++ c@75: c@75: Centre for Digital Music, Queen Mary, University of London. c@75: Copyright 2006-2016 Chris Cannam and QMUL. c@75: c@75: Permission is hereby granted, free of charge, to any person c@75: obtaining a copy of this software and associated documentation c@75: files (the "Software"), to deal in the Software without c@75: restriction, including without limitation the rights to use, copy, c@75: modify, merge, publish, distribute, sublicense, and/or sell copies c@75: of the Software, and to permit persons to whom the Software is c@75: furnished to do so, subject to the following conditions: c@75: c@75: The above copyright notice and this permission notice shall be c@75: included in all copies or substantial portions of the Software. c@75: c@75: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, c@75: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c@75: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND c@75: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR c@75: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF c@75: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION c@75: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c@75: c@75: Except as contained in this notice, the names of the Centre for c@75: Digital Music; Queen Mary, University of London; and Chris Cannam c@75: shall not be used in advertising or otherwise to promote the sale, c@75: use or other dealings in this Software without prior written c@75: authorization. c@75: */ c@75: c@75: #ifndef PIPER_PLUGIN_HANDLE_MAPPER_H c@75: #define PIPER_PLUGIN_HANDLE_MAPPER_H c@75: c@75: #include "PluginOutputIdMapper.h" c@75: c@75: #include salimma@295: #include c@75: #include c@75: c@97: namespace piper_vamp { c@75: c@75: /** c@75: * Convert plugin pointers to handles within some scope defined by the c@75: * individual PluginHandleMapper implementation. c@75: * c@75: * The special handle 0 and the NULL plugin pointer are both used to c@75: * represent "not found" and will be returned in any case where an c@75: * unknown handle or plugin is requested. c@75: * c@75: * Note that the handle type must be representable as a JSON number, c@75: * hence the use of a 32-bit rather than 64-bit int. c@75: * c@75: * This interface also includes methods for obtaining a c@75: * PluginOutputIdMapper, \see PluginOutputIdMapper. c@75: */ c@75: c@75: class PluginHandleMapper c@75: { c@75: public: cannam@265: /** cannam@265: * The handle type. This is 32-bit rather than 64-bit in order to cannam@265: * be representable as a JSON number without rounding, and is cannam@265: * unsigned to avoid C++ undefined behaviour in places where it cannam@265: * could wrap around. cannam@265: */ cannam@265: typedef uint32_t Handle; cannam@265: c@75: const Handle INVALID_HANDLE = 0; c@75: c@75: virtual ~PluginHandleMapper() noexcept { } c@75: c@75: /** c@75: * Look up and return the handle for a given plugin pointer. c@75: * If the given pointer is null or not known, return INVALID_HANDLE. c@75: */ c@75: virtual Handle pluginToHandle(Vamp::Plugin *) const noexcept = 0; c@75: c@75: /** c@75: * Look up and return the plugin for a given handle. c@75: * If the given handle is INVALID_HANDLE or not known, return nullptr. c@75: */ cannam@276: virtual Vamp::Plugin *handleToPlugin(Handle) const noexcept = 0; c@75: c@75: /** c@75: * Return a shared pointer to a PluginOutputIdMapper c@75: * implementation for the given plugin pointer. If the given c@75: * pointer is null or not known, return the null shared_ptr. c@75: */ c@75: virtual const std::shared_ptr pluginToOutputIdMapper c@75: (Vamp::Plugin *p) const noexcept = 0; c@75: c@75: /** c@75: * Return a shared pointer to a PluginOutputIdMapper c@75: * implementation for the given plugin handle. If the given c@75: * handle is INVALID_HANDLE or not known, return the null shared_ptr. c@75: */ c@75: virtual const std::shared_ptr handleToOutputIdMapper c@75: (Handle h) const noexcept = 0; c@75: }; c@75: c@75: } c@75: c@75: #endif c@75: