c@19: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@19: c@19: /* c@19: Vampipe c@19: c@19: Centre for Digital Music, Queen Mary, University of London. c@19: Copyright 2006-2016 Chris Cannam and QMUL. c@19: c@19: Permission is hereby granted, free of charge, to any person c@19: obtaining a copy of this software and associated documentation c@19: files (the "Software"), to deal in the Software without c@19: restriction, including without limitation the rights to use, copy, c@19: modify, merge, publish, distribute, sublicense, and/or sell copies c@19: of the Software, and to permit persons to whom the Software is c@19: furnished to do so, subject to the following conditions: c@19: c@19: The above copyright notice and this permission notice shall be c@19: included in all copies or substantial portions of the Software. c@19: c@19: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, c@19: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c@19: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND c@19: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR c@19: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF c@19: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION c@19: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c@19: c@19: Except as contained in this notice, the names of the Centre for c@19: Digital Music; Queen Mary, University of London; and Chris Cannam c@19: shall not be used in advertising or otherwise to promote the sale, c@19: use or other dealings in this Software without prior written c@19: authorization. c@19: */ c@19: c@19: #ifndef VAMPIPE_CONSTANT_PLUGIN_HANDLE_MAPPER_H c@19: #define VAMPIPE_CONSTANT_PLUGIN_HANDLE_MAPPER_H c@19: c@19: #include "PluginHandleMapper.h" c@19: c@19: namespace vampipe { c@19: c@19: /** c@19: * A trivial PluginHandleMapper, to be used for tests and for c@19: * translating between protocols that contain handles without actually c@19: * loading any plugins. c@19: * c@19: * This mapper only knows about one handle, and if it is asked for c@19: * that one, it returns a fixed plugin pointer (which might never be c@19: * dereferenced, depending on the context in which this class is c@19: * used). The idea would be to create one of these on the fly each c@19: * time a new handle needs to be translated. c@19: */ c@19: class ConstantPluginHandleMapper : public PluginHandleMapper c@19: { c@19: public: c@19: ConstantPluginHandleMapper(Vamp::Plugin *plugin, int32_t handle) : c@19: m_plugin(plugin), m_handle(handle) { } c@19: c@19: virtual int32_t pluginToHandle(Vamp::Plugin *p) { c@19: if (p == m_plugin) return m_handle; c@19: else throw NotFound(); c@19: } c@19: c@19: virtual Vamp::Plugin *handleToPlugin(int32_t h) { c@19: if (h == m_handle) return m_plugin; c@19: else throw NotFound(); c@19: } c@19: c@19: private: c@19: Vamp::Plugin *m_plugin; c@19: int32_t m_handle; c@19: }; c@19: c@19: } c@19: c@19: #endif