Mercurial > hg > piper-cpp
comparison vamp-client/qt/PiperAutoPlugin.h @ 208:c67a0a945b6b
Rename PluginStub to PiperVampPlugin and AutoPlugin to PiperAutoPlugin
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Thu, 09 Feb 2017 13:31:46 +0000 |
parents | |
children | df65480a08de |
comparison
equal
deleted
inserted
replaced
207:61034472c304 | 208:c67a0a945b6b |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 /* | |
3 Piper C++ | |
4 | |
5 An API for audio analysis and feature extraction plugins. | |
6 | |
7 Centre for Digital Music, Queen Mary, University of London. | |
8 Copyright 2006-2017 Chris Cannam and QMUL. | |
9 | |
10 Permission is hereby granted, free of charge, to any person | |
11 obtaining a copy of this software and associated documentation | |
12 files (the "Software"), to deal in the Software without | |
13 restriction, including without limitation the rights to use, copy, | |
14 modify, merge, publish, distribute, sublicense, and/or sell copies | |
15 of the Software, and to permit persons to whom the Software is | |
16 furnished to do so, subject to the following conditions: | |
17 | |
18 The above copyright notice and this permission notice shall be | |
19 included in all copies or substantial portions of the Software. | |
20 | |
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | |
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
26 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
28 | |
29 Except as contained in this notice, the names of the Centre for | |
30 Digital Music; Queen Mary, University of London; and Chris Cannam | |
31 shall not be used in advertising or otherwise to promote the sale, | |
32 use or other dealings in this Software without prior written | |
33 authorization. | |
34 */ | |
35 | |
36 #ifndef PIPER_AUTO_PLUGIN_H | |
37 #define PIPER_AUTO_PLUGIN_H | |
38 | |
39 #include "ProcessQtTransport.h" | |
40 #include "../CapnpRRClient.h" | |
41 #include "../Exceptions.h" | |
42 | |
43 #include <cstdint> | |
44 | |
45 namespace piper_vamp { | |
46 namespace client { | |
47 | |
48 /** | |
49 * This "plugin" make the Piper client abstraction behave like a local | |
50 * Vamp plugin, with its own server that lasts only for the lifetime | |
51 * of this plugin and serves only it. | |
52 * | |
53 * Note that any method may throw ServerCrashed, RequestTimedOut or | |
54 * ProtocolError exceptions. | |
55 */ | |
56 class PiperAutoPlugin : public Vamp::Plugin | |
57 { | |
58 public: | |
59 PiperAutoPlugin(std::string serverName, | |
60 std::string pluginKey, | |
61 float inputSampleRate, | |
62 int adapterFlags, | |
63 LogCallback *logger) : // logger may be nullptr for cerr | |
64 Vamp::Plugin(inputSampleRate), | |
65 m_logger(logger), | |
66 m_transport(serverName, "capnp", logger), | |
67 m_client(&m_transport, logger) | |
68 { | |
69 LoadRequest req; | |
70 req.pluginKey = pluginKey; | |
71 req.inputSampleRate = inputSampleRate; | |
72 req.adapterFlags = adapterFlags; | |
73 try { | |
74 LoadResponse resp = m_client.load(req); | |
75 m_plugin = resp.plugin; | |
76 } catch (ServerCrashed c) { | |
77 log(std::string("PiperAutoPlugin: Server crashed: ") + c.what()); | |
78 m_plugin = 0; | |
79 } | |
80 } | |
81 | |
82 virtual ~PiperAutoPlugin() { | |
83 delete m_plugin; | |
84 } | |
85 | |
86 bool isOK() const { | |
87 return (m_plugin != nullptr); | |
88 } | |
89 | |
90 virtual std::string getIdentifier() const { | |
91 return getPlugin()->getIdentifier(); | |
92 } | |
93 | |
94 virtual std::string getName() const { | |
95 return getPlugin()->getName(); | |
96 } | |
97 | |
98 virtual std::string getDescription() const { | |
99 return getPlugin()->getDescription(); | |
100 } | |
101 | |
102 virtual std::string getMaker() const { | |
103 return getPlugin()->getMaker(); | |
104 } | |
105 | |
106 virtual std::string getCopyright() const { | |
107 return getPlugin()->getCopyright(); | |
108 } | |
109 | |
110 virtual int getPluginVersion() const { | |
111 return getPlugin()->getPluginVersion(); | |
112 } | |
113 | |
114 virtual ParameterList getParameterDescriptors() const { | |
115 return getPlugin()->getParameterDescriptors(); | |
116 } | |
117 | |
118 virtual float getParameter(std::string name) const { | |
119 return getPlugin()->getParameter(name); | |
120 } | |
121 | |
122 virtual void setParameter(std::string name, float value) { | |
123 getPlugin()->setParameter(name, value); | |
124 } | |
125 | |
126 virtual ProgramList getPrograms() const { | |
127 return getPlugin()->getPrograms(); | |
128 } | |
129 | |
130 virtual std::string getCurrentProgram() const { | |
131 return getPlugin()->getCurrentProgram(); | |
132 } | |
133 | |
134 virtual void selectProgram(std::string program) { | |
135 getPlugin()->selectProgram(program); | |
136 } | |
137 | |
138 virtual bool initialise(size_t inputChannels, | |
139 size_t stepSize, | |
140 size_t blockSize) { | |
141 return getPlugin()->initialise(inputChannels, stepSize, blockSize); | |
142 } | |
143 | |
144 virtual void reset() { | |
145 getPlugin()->reset(); | |
146 } | |
147 | |
148 virtual InputDomain getInputDomain() const { | |
149 return getPlugin()->getInputDomain(); | |
150 } | |
151 | |
152 virtual size_t getPreferredBlockSize() const { | |
153 return getPlugin()->getPreferredBlockSize(); | |
154 } | |
155 | |
156 virtual size_t getPreferredStepSize() const { | |
157 return getPlugin()->getPreferredStepSize(); | |
158 } | |
159 | |
160 virtual size_t getMinChannelCount() const { | |
161 return getPlugin()->getMinChannelCount(); | |
162 } | |
163 | |
164 virtual size_t getMaxChannelCount() const { | |
165 return getPlugin()->getMaxChannelCount(); | |
166 } | |
167 | |
168 virtual OutputList getOutputDescriptors() const { | |
169 return getPlugin()->getOutputDescriptors(); | |
170 } | |
171 | |
172 virtual FeatureSet process(const float *const *inputBuffers, | |
173 Vamp::RealTime timestamp) { | |
174 return getPlugin()->process(inputBuffers, timestamp); | |
175 } | |
176 | |
177 virtual FeatureSet getRemainingFeatures() { | |
178 return getPlugin()->getRemainingFeatures(); | |
179 } | |
180 | |
181 private: | |
182 LogCallback *m_logger; | |
183 ProcessQtTransport m_transport; | |
184 CapnpRRClient m_client; | |
185 Vamp::Plugin *m_plugin; | |
186 Vamp::Plugin *getPlugin() const { | |
187 if (!m_plugin) { | |
188 log("PiperAutoPlugin: getPlugin() failed (caller should have called PiperAutoPlugin::isOK)"); | |
189 throw std::logic_error("Plugin load failed"); | |
190 } | |
191 return m_plugin; | |
192 } | |
193 | |
194 void log(std::string message) const { | |
195 if (m_logger) m_logger->log(message); | |
196 else std::cerr << message << std::endl; | |
197 } | |
198 }; | |
199 | |
200 } | |
201 } | |
202 | |
203 #endif | |
204 | |
205 |