comparison vamp-client/qt/AutoPlugin.h @ 150:bf8e3e7dd7de

Move some things around, and add overall test script
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 20 Jan 2017 17:45:54 +0000
parents
children 6ccb195d6de6
comparison
equal deleted inserted replaced
149:70bf40743d6a 150:bf8e3e7dd7de
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-2016 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
42 #include <cstdint>
43
44 namespace piper_vamp {
45 namespace client {
46
47 class AutoPlugin : public Vamp::Plugin
48 {
49 public:
50 AutoPlugin(std::string serverName,
51 std::string pluginKey,
52 float inputSampleRate,
53 int adapterFlags,
54 LogCallback *logger) : // logger may be nullptr for cerr
55 Vamp::Plugin(inputSampleRate),
56 m_logger(logger),
57 m_transport(serverName, "capnp", logger),
58 m_client(&m_transport, logger)
59 {
60 LoadRequest req;
61 req.pluginKey = pluginKey;
62 req.inputSampleRate = inputSampleRate;
63 req.adapterFlags = adapterFlags;
64 try {
65 LoadResponse resp = m_client.loadPlugin(req);
66 m_plugin = resp.plugin;
67 } catch (ServerCrashed c) {
68 log(std::string("AutoPlugin: Server crashed: ") + c.what());
69 m_plugin = 0;
70 }
71 }
72
73 virtual ~AutoPlugin() {
74 delete m_plugin;
75 }
76
77 bool isOK() const {
78 return (m_plugin != nullptr);
79 }
80
81 virtual std::string getIdentifier() const {
82 return getPlugin()->getIdentifier();
83 }
84
85 virtual std::string getName() const {
86 return getPlugin()->getName();
87 }
88
89 virtual std::string getDescription() const {
90 return getPlugin()->getDescription();
91 }
92
93 virtual std::string getMaker() const {
94 return getPlugin()->getMaker();
95 }
96
97 virtual std::string getCopyright() const {
98 return getPlugin()->getCopyright();
99 }
100
101 virtual int getPluginVersion() const {
102 return getPlugin()->getPluginVersion();
103 }
104
105 virtual ParameterList getParameterDescriptors() const {
106 return getPlugin()->getParameterDescriptors();
107 }
108
109 virtual float getParameter(std::string name) const {
110 return getPlugin()->getParameter(name);
111 }
112
113 virtual void setParameter(std::string name, float value) {
114 getPlugin()->setParameter(name, value);
115 }
116
117 virtual ProgramList getPrograms() const {
118 return getPlugin()->getPrograms();
119 }
120
121 virtual std::string getCurrentProgram() const {
122 return getPlugin()->getCurrentProgram();
123 }
124
125 virtual void selectProgram(std::string program) {
126 getPlugin()->selectProgram(program);
127 }
128
129 virtual bool initialise(size_t inputChannels,
130 size_t stepSize,
131 size_t blockSize) {
132 return getPlugin()->initialise(inputChannels, stepSize, blockSize);
133 }
134
135 virtual void reset() {
136 getPlugin()->reset();
137 }
138
139 virtual InputDomain getInputDomain() const {
140 return getPlugin()->getInputDomain();
141 }
142
143 virtual size_t getPreferredBlockSize() const {
144 return getPlugin()->getPreferredBlockSize();
145 }
146
147 virtual size_t getPreferredStepSize() const {
148 return getPlugin()->getPreferredStepSize();
149 }
150
151 virtual size_t getMinChannelCount() const {
152 return getPlugin()->getMinChannelCount();
153 }
154
155 virtual size_t getMaxChannelCount() const {
156 return getPlugin()->getMaxChannelCount();
157 }
158
159 virtual OutputList getOutputDescriptors() const {
160 return getPlugin()->getOutputDescriptors();
161 }
162
163 virtual FeatureSet process(const float *const *inputBuffers,
164 Vamp::RealTime timestamp) {
165 return getPlugin()->process(inputBuffers, timestamp);
166 }
167
168 virtual FeatureSet getRemainingFeatures() {
169 return getPlugin()->getRemainingFeatures();
170 }
171
172 private:
173 LogCallback *m_logger;
174 ProcessQtTransport m_transport;
175 CapnpRRClient m_client;
176 Vamp::Plugin *m_plugin;
177 Vamp::Plugin *getPlugin() const {
178 if (!m_plugin) {
179 log("AutoPlugin: getPlugin() failed (caller should have called AutoPlugin::isOK)");
180 throw std::logic_error("Plugin load failed");
181 }
182 return m_plugin;
183 }
184
185 void log(std::string message) const {
186 if (m_logger) m_logger->log(message);
187 else std::cerr << message << std::endl;
188 }
189 };
190
191 }
192 }
193
194 #endif
195
196