c@80
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@80
|
2
|
c@80
|
3 /*
|
c@80
|
4 Piper C++
|
c@80
|
5
|
c@80
|
6 Centre for Digital Music, Queen Mary, University of London.
|
c@80
|
7 Copyright 2006-2016 Chris Cannam and QMUL.
|
c@80
|
8
|
c@80
|
9 Permission is hereby granted, free of charge, to any person
|
c@80
|
10 obtaining a copy of this software and associated documentation
|
c@80
|
11 files (the "Software"), to deal in the Software without
|
c@80
|
12 restriction, including without limitation the rights to use, copy,
|
c@80
|
13 modify, merge, publish, distribute, sublicense, and/or sell copies
|
c@80
|
14 of the Software, and to permit persons to whom the Software is
|
c@80
|
15 furnished to do so, subject to the following conditions:
|
c@80
|
16
|
c@80
|
17 The above copyright notice and this permission notice shall be
|
c@80
|
18 included in all copies or substantial portions of the Software.
|
c@80
|
19
|
c@80
|
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
c@80
|
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
c@80
|
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
c@80
|
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
c@80
|
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
c@80
|
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
c@80
|
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
c@80
|
27
|
c@80
|
28 Except as contained in this notice, the names of the Centre for
|
c@80
|
29 Digital Music; Queen Mary, University of London; and Chris Cannam
|
c@80
|
30 shall not be used in advertising or otherwise to promote the sale,
|
c@80
|
31 use or other dealings in this Software without prior written
|
c@80
|
32 authorization.
|
c@80
|
33 */
|
c@80
|
34
|
c@80
|
35 #ifndef PIPER_ASSIGNED_PLUGIN_HANDLE_MAPPER_H
|
c@80
|
36 #define PIPER_ASSIGNED_PLUGIN_HANDLE_MAPPER_H
|
c@80
|
37
|
c@80
|
38 #include "PluginHandleMapper.h"
|
c@80
|
39 #include "PluginOutputIdMapper.h"
|
c@80
|
40 #include "DefaultPluginOutputIdMapper.h"
|
c@80
|
41
|
c@80
|
42 #include <set>
|
c@80
|
43 #include <map>
|
c@80
|
44 #include <iostream>
|
c@80
|
45
|
c@80
|
46 namespace piper {
|
c@80
|
47
|
c@80
|
48 class AssignedPluginHandleMapper : public PluginHandleMapper
|
c@80
|
49 {
|
c@80
|
50 public:
|
c@80
|
51 AssignedPluginHandleMapper() { }
|
c@80
|
52
|
c@84
|
53 void addPlugin(Handle h, Vamp::Plugin *p) {
|
c@80
|
54 if (!p) return;
|
c@80
|
55 if (m_rplugins.find(p) == m_rplugins.end()) {
|
c@80
|
56 if (m_plugins.find(h) != m_plugins.end()) {
|
c@80
|
57 std::cerr << "ERROR: Duplicate plugin handle " << h
|
c@80
|
58 << " for plugin " << p << " (already used for plugin "
|
c@80
|
59 << m_plugins[h] << ")" << std::endl;
|
c@80
|
60 throw std::logic_error("Duplicate plugin handle");
|
c@80
|
61 }
|
c@80
|
62 m_plugins[h] = p;
|
c@80
|
63 m_rplugins[p] = h;
|
c@80
|
64 m_outputMappers[h] =
|
c@80
|
65 std::make_shared<DefaultPluginOutputIdMapper>(p);
|
c@80
|
66 }
|
c@80
|
67 }
|
c@80
|
68
|
c@80
|
69 void removePlugin(Handle h) {
|
c@80
|
70 if (m_plugins.find(h) == m_plugins.end()) return;
|
c@80
|
71 Vamp::Plugin *p = m_plugins[h];
|
c@80
|
72 m_outputMappers.erase(h);
|
c@80
|
73 m_plugins.erase(h);
|
c@80
|
74 if (isConfigured(h)) {
|
c@80
|
75 m_configuredPlugins.erase(h);
|
c@80
|
76 m_channelCounts.erase(h);
|
c@80
|
77 }
|
c@80
|
78 m_rplugins.erase(p);
|
c@80
|
79 }
|
c@91
|
80
|
c@91
|
81 bool havePlugin(Vamp::Plugin *p) {
|
c@91
|
82 return (m_rplugins.find(p) != m_rplugins.end());
|
c@91
|
83 }
|
c@80
|
84
|
c@80
|
85 Handle pluginToHandle(Vamp::Plugin *p) const noexcept {
|
c@80
|
86 if (m_rplugins.find(p) == m_rplugins.end()) {
|
c@80
|
87 return INVALID_HANDLE;
|
c@80
|
88 }
|
c@80
|
89 return m_rplugins.at(p);
|
c@80
|
90 }
|
c@80
|
91
|
c@80
|
92 Vamp::Plugin *handleToPlugin(Handle h) const noexcept {
|
c@80
|
93 if (m_plugins.find(h) == m_plugins.end()) {
|
c@80
|
94 return nullptr;
|
c@80
|
95 }
|
c@80
|
96 return m_plugins.at(h);
|
c@80
|
97 }
|
c@80
|
98
|
c@80
|
99 const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper
|
c@80
|
100 (Vamp::Plugin *p) const noexcept {
|
c@80
|
101 return handleToOutputIdMapper(pluginToHandle(p));
|
c@80
|
102 }
|
c@80
|
103
|
c@80
|
104 const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper
|
c@80
|
105 (Handle h) const noexcept {
|
c@80
|
106 if (h != INVALID_HANDLE &&
|
c@80
|
107 m_outputMappers.find(h) != m_outputMappers.end()) {
|
c@80
|
108 return m_outputMappers.at(h);
|
c@80
|
109 } else {
|
c@80
|
110 return {};
|
c@80
|
111 }
|
c@80
|
112 }
|
c@80
|
113
|
c@80
|
114 bool isConfigured(Handle h) const noexcept {
|
c@80
|
115 if (h == INVALID_HANDLE) return false;
|
c@80
|
116 return m_configuredPlugins.find(h) != m_configuredPlugins.end();
|
c@80
|
117 }
|
c@80
|
118
|
c@80
|
119 void markConfigured(Handle h, int channelCount, int blockSize) {
|
c@80
|
120 if (h == INVALID_HANDLE) return;
|
c@80
|
121 m_configuredPlugins.insert(h);
|
c@80
|
122 m_channelCounts[h] = channelCount;
|
c@80
|
123 m_blockSizes[h] = blockSize;
|
c@80
|
124 }
|
c@80
|
125
|
c@80
|
126 int getChannelCount(Handle h) const noexcept {
|
c@80
|
127 if (m_channelCounts.find(h) == m_channelCounts.end()) {
|
c@80
|
128 return 0;
|
c@80
|
129 }
|
c@80
|
130 return m_channelCounts.at(h);
|
c@80
|
131 }
|
c@80
|
132
|
c@80
|
133 int getBlockSize(Handle h) const noexcept {
|
c@80
|
134 if (m_blockSizes.find(h) == m_blockSizes.end()) {
|
c@80
|
135 return 0;
|
c@80
|
136 }
|
c@80
|
137 return m_blockSizes.at(h);
|
c@80
|
138 }
|
c@80
|
139
|
c@80
|
140 private:
|
c@80
|
141 std::map<Handle, Vamp::Plugin *> m_plugins;
|
c@80
|
142 std::map<Vamp::Plugin *, Handle> m_rplugins;
|
c@80
|
143 std::set<Handle> m_configuredPlugins;
|
c@80
|
144 std::map<Handle, int> m_channelCounts;
|
c@80
|
145 std::map<Handle, int> m_blockSizes;
|
c@80
|
146 std::map<Handle, std::shared_ptr<PluginOutputIdMapper>> m_outputMappers;
|
c@80
|
147 };
|
c@80
|
148
|
c@80
|
149 }
|
c@80
|
150
|
c@80
|
151 #endif
|