annotate vamp-support/PreservingPluginHandleMapper.h @ 263:9a044706ab73

Comments on dubiousness of all this
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 12 Oct 2018 11:12:09 +0100
parents 427c4c725085
children 7ada63fe1084
rev   line source
c@75 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@75 2
c@75 3 /*
c@75 4 Piper C++
c@75 5
c@75 6 Centre for Digital Music, Queen Mary, University of London.
c@75 7 Copyright 2006-2016 Chris Cannam and QMUL.
c@75 8
c@75 9 Permission is hereby granted, free of charge, to any person
c@75 10 obtaining a copy of this software and associated documentation
c@75 11 files (the "Software"), to deal in the Software without
c@75 12 restriction, including without limitation the rights to use, copy,
c@75 13 modify, merge, publish, distribute, sublicense, and/or sell copies
c@75 14 of the Software, and to permit persons to whom the Software is
c@75 15 furnished to do so, subject to the following conditions:
c@75 16
c@75 17 The above copyright notice and this permission notice shall be
c@75 18 included in all copies or substantial portions of the Software.
c@75 19
c@75 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c@75 21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c@75 22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c@75 23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
c@75 24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
c@75 25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
c@75 26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
c@75 27
c@75 28 Except as contained in this notice, the names of the Centre for
c@75 29 Digital Music; Queen Mary, University of London; and Chris Cannam
c@75 30 shall not be used in advertising or otherwise to promote the sale,
c@75 31 use or other dealings in this Software without prior written
c@75 32 authorization.
c@75 33 */
c@75 34
c@75 35 #ifndef PIPER_PRESERVING_PLUGIN_HANDLE_MAPPER_H
c@75 36 #define PIPER_PRESERVING_PLUGIN_HANDLE_MAPPER_H
c@75 37
c@75 38 #include "PluginHandleMapper.h"
c@75 39 #include "PreservingPluginOutputIdMapper.h"
c@75 40
c@75 41 #include <iostream>
c@75 42
c@97 43 namespace piper_vamp {
c@75 44
c@75 45 //!!! document -- this is a passthrough thing for a single plugin
c@75 46 //!!! handle only, it does not use actually valid Plugin pointers at
cannam@263 47 //!!! all. Or, better, reimplement in a way that doesn't involve
cannam@263 48 //!!! such alarmingly invalid reinterpret_casts
c@75 49
c@75 50 class PreservingPluginHandleMapper : public PluginHandleMapper
c@75 51 {
c@75 52 public:
c@75 53 PreservingPluginHandleMapper() :
c@75 54 m_handle(0),
c@75 55 m_plugin(0),
c@75 56 m_omapper(std::make_shared<PreservingPluginOutputIdMapper>()) { }
c@75 57
c@75 58 virtual Handle pluginToHandle(Vamp::Plugin *p) const noexcept {
c@75 59 if (!p) return INVALID_HANDLE;
c@75 60 if (p == m_plugin) return m_handle;
c@75 61 else {
c@75 62 std::cerr << "PreservingPluginHandleMapper: p = " << p
c@75 63 << " differs from saved m_plugin " << m_plugin
c@75 64 << " (not returning saved handle " << m_handle << ")"
c@75 65 << std::endl;
c@75 66 return INVALID_HANDLE;
c@75 67 }
c@75 68 }
c@75 69
c@75 70 virtual Vamp::Plugin *handleToPlugin(Handle h) const noexcept {
c@75 71 if (h == INVALID_HANDLE) return nullptr;
c@75 72 m_handle = h;
cannam@263 73 //!!! see comment at top
c@75 74 m_plugin = reinterpret_cast<Vamp::Plugin *>(h);
c@75 75 return m_plugin;
c@75 76 }
c@75 77
c@75 78 virtual const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper
c@75 79 (Vamp::Plugin *p) const noexcept {
c@75 80 if (!p) return {};
c@75 81 return m_omapper;
c@75 82 }
c@75 83
c@75 84 virtual const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper
c@75 85 (Handle h) const noexcept {
c@75 86 if (h == INVALID_HANDLE) return {};
c@75 87 return m_omapper;
c@75 88 }
c@75 89
c@75 90 private:
c@75 91 mutable Handle m_handle;
c@75 92 mutable Vamp::Plugin *m_plugin;
c@75 93 std::shared_ptr<PreservingPluginOutputIdMapper> m_omapper;
c@75 94 };
c@75 95
c@75 96 }
c@75 97
c@75 98 #endif