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