comparison vamp-support/CountingPluginHandleMapper.h @ 80:d9e85a65d45b

Inching toward a client
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 11 Oct 2016 15:49:28 +0100
parents 81e1c48e97f9
children db9a6ab618bc
comparison
equal deleted inserted replaced
79:f4497c1da43d 80:d9e85a65d45b
35 #ifndef PIPER_COUNTING_PLUGIN_HANDLE_MAPPER_H 35 #ifndef PIPER_COUNTING_PLUGIN_HANDLE_MAPPER_H
36 #define PIPER_COUNTING_PLUGIN_HANDLE_MAPPER_H 36 #define PIPER_COUNTING_PLUGIN_HANDLE_MAPPER_H
37 37
38 #include "PluginHandleMapper.h" 38 #include "PluginHandleMapper.h"
39 #include "PluginOutputIdMapper.h" 39 #include "PluginOutputIdMapper.h"
40 #include "DefaultPluginOutputIdMapper.h" 40 #include "AssignedPluginHandleMapper.h"
41 41
42 #include <set> 42 #include <set>
43 #include <map> 43 #include <map>
44 44
45 namespace piper { 45 namespace piper {
48 { 48 {
49 public: 49 public:
50 CountingPluginHandleMapper() : m_nextHandle(1) { } 50 CountingPluginHandleMapper() : m_nextHandle(1) { }
51 51
52 void addPlugin(Vamp::Plugin *p) { 52 void addPlugin(Vamp::Plugin *p) {
53 if (!p) return; 53 Handle h = m_nextHandle++;
54 if (m_rplugins.find(p) == m_rplugins.end()) { 54 m_sub.addPlugin(p, h);
55 Handle h = m_nextHandle++;
56 m_plugins[h] = p;
57 m_rplugins[p] = h;
58 m_outputMappers[h] =
59 std::make_shared<DefaultPluginOutputIdMapper>(p);
60 }
61 } 55 }
62 56
63 void removePlugin(Handle h) { 57 void removePlugin(Handle h) {
64 if (m_plugins.find(h) == m_plugins.end()) return; 58 m_sub.removePlugin(h);
65 Vamp::Plugin *p = m_plugins[h];
66 m_outputMappers.erase(h);
67 m_plugins.erase(h);
68 if (isConfigured(h)) {
69 m_configuredPlugins.erase(h);
70 m_channelCounts.erase(h);
71 }
72 m_rplugins.erase(p);
73 } 59 }
74 60
75 Handle pluginToHandle(Vamp::Plugin *p) const noexcept { 61 Handle pluginToHandle(Vamp::Plugin *p) const noexcept {
76 if (m_rplugins.find(p) == m_rplugins.end()) { 62 return m_sub.pluginToHandle(p);
77 return INVALID_HANDLE;
78 }
79 return m_rplugins.at(p);
80 } 63 }
81 64
82 Vamp::Plugin *handleToPlugin(Handle h) const noexcept { 65 Vamp::Plugin *handleToPlugin(Handle h) const noexcept {
83 if (m_plugins.find(h) == m_plugins.end()) { 66 return m_sub.handleToPlugin(h);
84 return nullptr;
85 }
86 return m_plugins.at(h);
87 } 67 }
88 68
89 const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper 69 const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper
90 (Vamp::Plugin *p) const noexcept { 70 (Vamp::Plugin *p) const noexcept {
91 return handleToOutputIdMapper(pluginToHandle(p)); 71 return m_sub.pluginToOutputIdMapper(p);
92 } 72 }
93 73
94 const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper 74 const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper
95 (Handle h) const noexcept { 75 (Handle h) const noexcept {
96 if (h != INVALID_HANDLE && 76 return m_sub.handleToOutputIdMapper(h);
97 m_outputMappers.find(h) != m_outputMappers.end()) {
98 return m_outputMappers.at(h);
99 } else {
100 return {};
101 }
102 } 77 }
103 78
104 bool isConfigured(Handle h) const noexcept { 79 bool isConfigured(Handle h) const noexcept {
105 if (h == INVALID_HANDLE) return false; 80 return m_sub.isConfigured(h);
106 return m_configuredPlugins.find(h) != m_configuredPlugins.end();
107 } 81 }
108 82
109 void markConfigured(Handle h, int channelCount, int blockSize) { 83 void markConfigured(Handle h, int channelCount, int blockSize) {
110 if (h == INVALID_HANDLE) return; 84 m_sub.markConfigured(h, channelCount, blockSize);
111 m_configuredPlugins.insert(h);
112 m_channelCounts[h] = channelCount;
113 m_blockSizes[h] = blockSize;
114 } 85 }
115 86
116 int getChannelCount(Handle h) const noexcept { 87 int getChannelCount(Handle h) const noexcept {
117 if (m_channelCounts.find(h) == m_channelCounts.end()) { 88 return m_sub.getChannelCount(h);
118 return 0;
119 }
120 return m_channelCounts.at(h);
121 } 89 }
122 90
123 int getBlockSize(Handle h) const noexcept { 91 int getBlockSize(Handle h) const noexcept {
124 if (m_blockSizes.find(h) == m_blockSizes.end()) { 92 return m_sub.getBlockSize(h);
125 return 0;
126 }
127 return m_blockSizes.at(h);
128 } 93 }
129 94
130 private: 95 private:
131 Handle m_nextHandle; // NB plugin handle type must fit in JSON number 96 Handle m_nextHandle; // NB plugin handle type must fit in JSON number
132 std::map<Handle, Vamp::Plugin *> m_plugins; 97 AssignedPluginHandleMapper m_sub;
133 std::map<Vamp::Plugin *, Handle> m_rplugins;
134 std::set<Handle> m_configuredPlugins;
135 std::map<Handle, int> m_channelCounts;
136 std::map<Handle, int> m_blockSizes;
137 std::map<Handle, std::shared_ptr<PluginOutputIdMapper>> m_outputMappers;
138 }; 98 };
139 99
140 } 100 }
141 101
142 #endif 102 #endif