Mercurial > hg > piper-cpp
diff bits/CountingPluginHandleMapper.h @ 51:f4244a2d55ac
Introduce and use output id mappers
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 16 Sep 2016 15:10:57 +0100 |
parents | 55d69b26d4db |
children | e90fd30990eb |
line wrap: on
line diff
--- a/bits/CountingPluginHandleMapper.h Fri Sep 16 14:15:41 2016 +0100 +++ b/bits/CountingPluginHandleMapper.h Fri Sep 16 15:10:57 2016 +0100 @@ -36,6 +36,8 @@ #define VAMPIPE_COUNTING_PLUGIN_HANDLE_MAPPER_H #include "PluginHandleMapper.h" +#include "PluginOutputIdMapper.h" +#include "DefaultPluginOutputIdMapper.h" #include <set> #include <map> @@ -48,19 +50,28 @@ public: CountingPluginHandleMapper() : m_nextHandle(1) { } + ~CountingPluginHandleMapper() { + for (auto &o: m_outputMappers) { + delete o.second; + } + } + void addPlugin(Vamp::Plugin *p) { if (m_rplugins.find(p) == m_rplugins.end()) { - int32_t h = m_nextHandle++; + Handle h = m_nextHandle++; m_plugins[h] = p; m_rplugins[p] = h; + m_outputMappers[h] = new DefaultPluginOutputIdMapper(p); } } - void removePlugin(int32_t h) { + void removePlugin(Handle h) { if (m_plugins.find(h) == m_plugins.end()) { throw NotFound(); } Vamp::Plugin *p = m_plugins[h]; + delete m_outputMappers.at(h); + m_outputMappers.erase(h); m_plugins.erase(h); if (isConfigured(h)) { m_configuredPlugins.erase(h); @@ -69,38 +80,52 @@ m_rplugins.erase(p); } - int32_t pluginToHandle(Vamp::Plugin *p) const { + Handle pluginToHandle(Vamp::Plugin *p) const { if (m_rplugins.find(p) == m_rplugins.end()) { throw NotFound(); } return m_rplugins.at(p); } - Vamp::Plugin *handleToPlugin(int32_t h) const { + Vamp::Plugin *handleToPlugin(Handle h) const { if (m_plugins.find(h) == m_plugins.end()) { throw NotFound(); } return m_plugins.at(h); } - bool isConfigured(int32_t h) const { + //!!! iffy: mapper will move when another plugin is added. return by value? + const PluginOutputIdMapper &pluginToOutputIdMapper(Vamp::Plugin *p) const { + // pluginToHandle checks the plugin has been registered with us + return *m_outputMappers.at(pluginToHandle(p)); + } + + //!!! iffy: mapper will move when another plugin is added. return by value? + const PluginOutputIdMapper &handleToOutputIdMapper(Handle h) const { + if (m_plugins.find(h) == m_plugins.end()) { + throw NotFound(); + } + return *m_outputMappers.at(h); + } + + bool isConfigured(Handle h) const { return m_configuredPlugins.find(h) != m_configuredPlugins.end(); } - void markConfigured(int32_t h, int channelCount, int blockSize) { + void markConfigured(Handle h, int channelCount, int blockSize) { m_configuredPlugins.insert(h); m_channelCounts[h] = channelCount; m_blockSizes[h] = blockSize; } - int getChannelCount(int32_t h) const { + int getChannelCount(Handle h) const { if (m_channelCounts.find(h) == m_channelCounts.end()) { throw NotFound(); } return m_channelCounts.at(h); } - int getBlockSize(int32_t h) const { + int getBlockSize(Handle h) const { if (m_blockSizes.find(h) == m_blockSizes.end()) { throw NotFound(); } @@ -108,12 +133,13 @@ } private: - int32_t m_nextHandle; // NB plugin handle type must fit in JSON number - std::map<uint32_t, Vamp::Plugin *> m_plugins; - std::map<Vamp::Plugin *, uint32_t> m_rplugins; - std::set<uint32_t> m_configuredPlugins; - std::map<uint32_t, int> m_channelCounts; - std::map<uint32_t, int> m_blockSizes; + Handle m_nextHandle; // NB plugin handle type must fit in JSON number + std::map<Handle, Vamp::Plugin *> m_plugins; + std::map<Vamp::Plugin *, Handle> m_rplugins; + std::set<Handle> m_configuredPlugins; + std::map<Handle, int> m_channelCounts; + std::map<Handle, int> m_blockSizes; + std::map<Handle, DefaultPluginOutputIdMapper *> m_outputMappers; }; }