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