Mercurial > hg > piper-cpp
comparison vamp-client/PiperPluginStub.h @ 92:21f8af53eaf0
Reorganise some classes
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 13 Oct 2016 12:02:44 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
91:c897c9a8daf1 | 92:21f8af53eaf0 |
---|---|
1 | |
2 #ifndef PIPER_STUB_PLUGIN_H | |
3 #define PIPER_STUB_PLUGIN_H | |
4 | |
5 #include <vamp-hostsdk/Plugin.h> | |
6 #include <vamp-hostsdk/PluginLoader.h> | |
7 #include <vamp-hostsdk/PluginStaticData.h> | |
8 #include <vamp-hostsdk/PluginConfiguration.h> | |
9 | |
10 #include <cstdint> | |
11 | |
12 #include "PiperClient.h" | |
13 | |
14 namespace piper { //!!! should be something else | |
15 | |
16 class PiperPluginStub : public Vamp::Plugin | |
17 { | |
18 enum State { | |
19 Loaded, Configured, Finished | |
20 }; | |
21 | |
22 public: | |
23 PiperPluginStub(PiperPluginClientInterface *client, | |
24 std::string pluginKey, | |
25 float inputSampleRate, | |
26 int adapterFlags, | |
27 Vamp::HostExt::PluginStaticData psd, | |
28 Vamp::HostExt::PluginConfiguration defaultConfig) : | |
29 Plugin(inputSampleRate), | |
30 m_client(client), | |
31 m_key(pluginKey), | |
32 m_adapterFlags(adapterFlags), | |
33 m_state(Loaded), | |
34 m_psd(psd), | |
35 m_defaultConfig(defaultConfig), | |
36 m_config(defaultConfig) | |
37 { } | |
38 | |
39 virtual ~PiperPluginStub() { | |
40 if (m_state != Finished) { | |
41 (void)m_client->finish(this); | |
42 } | |
43 } | |
44 | |
45 virtual std::string getIdentifier() const { | |
46 return m_psd.basic.identifier; | |
47 } | |
48 | |
49 virtual std::string getName() const { | |
50 return m_psd.basic.name; | |
51 } | |
52 | |
53 virtual std::string getDescription() const { | |
54 return m_psd.basic.description; | |
55 } | |
56 | |
57 virtual std::string getMaker() const { | |
58 return m_psd.maker; | |
59 } | |
60 | |
61 virtual std::string getCopyright() const { | |
62 return m_psd.copyright; | |
63 } | |
64 | |
65 virtual int getPluginVersion() const { | |
66 return m_psd.pluginVersion; | |
67 } | |
68 | |
69 virtual ParameterList getParameterDescriptors() const { | |
70 return m_psd.parameters; | |
71 } | |
72 | |
73 virtual float getParameter(std::string name) const { | |
74 if (m_config.parameterValues.find(name) != m_config.parameterValues.end()) { | |
75 return m_config.parameterValues.at(name); | |
76 } else { | |
77 return 0.f; | |
78 } | |
79 } | |
80 | |
81 virtual void setParameter(std::string name, float value) { | |
82 if (m_state != Loaded) { | |
83 throw std::logic_error("Can't set parameter after plugin initialised"); | |
84 } | |
85 m_config.parameterValues[name] = value; | |
86 } | |
87 | |
88 virtual ProgramList getPrograms() const { | |
89 return m_psd.programs; | |
90 } | |
91 | |
92 virtual std::string getCurrentProgram() const { | |
93 return m_config.currentProgram; | |
94 } | |
95 | |
96 virtual void selectProgram(std::string program) { | |
97 if (m_state != Loaded) { | |
98 throw std::logic_error("Can't select program after plugin initialised"); | |
99 } | |
100 m_config.currentProgram = program; | |
101 } | |
102 | |
103 virtual bool initialise(size_t inputChannels, | |
104 size_t stepSize, | |
105 size_t blockSize) { | |
106 | |
107 if (m_state != Loaded) { | |
108 throw std::logic_error("Plugin has already been initialised"); | |
109 } | |
110 | |
111 m_config.channelCount = inputChannels; | |
112 m_config.stepSize = stepSize; | |
113 m_config.blockSize = blockSize; | |
114 | |
115 m_outputs = m_client->configure(this, m_config); | |
116 | |
117 if (!m_outputs.empty()) { | |
118 m_state = Configured; | |
119 return true; | |
120 } else { | |
121 return false; | |
122 } | |
123 } | |
124 | |
125 virtual void reset() { | |
126 | |
127 if (m_state == Loaded) { | |
128 // reset is a no-op if the plugin hasn't been initialised yet | |
129 return; | |
130 } | |
131 | |
132 m_client->reset(this, m_config); | |
133 | |
134 m_state = Configured; | |
135 } | |
136 | |
137 virtual InputDomain getInputDomain() const { | |
138 return m_psd.inputDomain; | |
139 } | |
140 | |
141 virtual size_t getPreferredBlockSize() const { | |
142 return m_defaultConfig.blockSize; | |
143 } | |
144 | |
145 virtual size_t getPreferredStepSize() const { | |
146 return m_defaultConfig.stepSize; | |
147 } | |
148 | |
149 virtual size_t getMinChannelCount() const { | |
150 return m_psd.minChannelCount; | |
151 } | |
152 | |
153 virtual size_t getMaxChannelCount() const { | |
154 return m_psd.maxChannelCount; | |
155 } | |
156 | |
157 virtual OutputList getOutputDescriptors() const { | |
158 if (m_state == Configured) { | |
159 return m_outputs; | |
160 } | |
161 | |
162 //!!! todo: figure out for which hosts (and adapters?) it may | |
163 //!!! be a problem that the output descriptors are incomplete | |
164 //!!! here. Any such hosts/adapters are broken, but I bet they | |
165 //!!! exist | |
166 | |
167 OutputList staticOutputs; | |
168 for (const auto &o: m_psd.basicOutputInfo) { | |
169 OutputDescriptor od; | |
170 od.identifier = o.identifier; | |
171 od.name = o.name; | |
172 od.description = o.description; | |
173 staticOutputs.push_back(od); | |
174 } | |
175 return staticOutputs; | |
176 } | |
177 | |
178 virtual FeatureSet process(const float *const *inputBuffers, | |
179 Vamp::RealTime timestamp) { | |
180 | |
181 if (m_state == Loaded) { | |
182 throw std::logic_error("Plugin has not been initialised"); | |
183 } | |
184 if (m_state == Finished) { | |
185 throw std::logic_error("Plugin has already been disposed of"); | |
186 } | |
187 | |
188 //!!! ew | |
189 std::vector<std::vector<float> > vecbuf; | |
190 for (int c = 0; c < m_config.channelCount; ++c) { | |
191 vecbuf.push_back(std::vector<float> | |
192 (inputBuffers[c], | |
193 inputBuffers[c] + m_config.blockSize)); | |
194 } | |
195 | |
196 return m_client->process(this, vecbuf, timestamp); | |
197 } | |
198 | |
199 virtual FeatureSet getRemainingFeatures() { | |
200 | |
201 if (m_state == Loaded) { | |
202 throw std::logic_error("Plugin has not been configured"); | |
203 } | |
204 if (m_state == Finished) { | |
205 throw std::logic_error("Plugin has already been disposed of"); | |
206 } | |
207 | |
208 m_state = Finished; | |
209 | |
210 return m_client->finish(this); | |
211 } | |
212 | |
213 // Not Plugin methods, but needed by the PiperClient to support reloads: | |
214 | |
215 virtual float getInputSampleRate() const { | |
216 return m_inputSampleRate; | |
217 } | |
218 | |
219 virtual std::string getPluginKey() const { | |
220 return m_key; | |
221 } | |
222 | |
223 virtual int getAdapterFlags() const { | |
224 return m_adapterFlags; | |
225 } | |
226 | |
227 private: | |
228 PiperPluginClientInterface *m_client; | |
229 std::string m_key; | |
230 int m_adapterFlags; | |
231 State m_state; | |
232 Vamp::HostExt::PluginStaticData m_psd; | |
233 OutputList m_outputs; | |
234 Vamp::HostExt::PluginConfiguration m_defaultConfig; | |
235 Vamp::HostExt::PluginConfiguration m_config; | |
236 }; | |
237 | |
238 } | |
239 | |
240 #endif |