comparison vamp-client/AutoPlugin.h @ 98:f55631599988

Plugin that creates its own server
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 13 Oct 2016 19:11:24 +0100
parents
children 8c449824e08d
comparison
equal deleted inserted replaced
97:427c4c725085 98:f55631599988
1
2 #ifndef PIPER_AUTO_PLUGIN_H
3 #define PIPER_AUTO_PLUGIN_H
4
5 #include "ProcessQtTransport.h"
6 #include "CapnpRRClient.h"
7
8 #include <cstdint>
9
10 namespace piper_vamp {
11 namespace client {
12
13 class AutoPlugin : public Vamp::Plugin
14 {
15 public:
16 AutoPlugin(std::string pluginKey,
17 float inputSampleRate,
18 int adapterFlags) :
19 Vamp::Plugin(inputSampleRate),
20 m_transport("../bin/piper-vamp-server"), //!!!*£*$&"$*"
21 m_client(&m_transport)
22 {
23 LoadRequest req;
24 req.pluginKey = pluginKey;
25 req.inputSampleRate = inputSampleRate;
26 req.adapterFlags = adapterFlags;
27 LoadResponse resp = m_client.loadPlugin(req);
28 m_plugin = resp.plugin;
29 }
30
31 virtual ~AutoPlugin() {
32 delete m_plugin;
33 }
34
35 bool isOK() const {
36 return (m_plugin != nullptr);
37 }
38
39 virtual std::string getIdentifier() const {
40 return getPlugin()->getIdentifier();
41 }
42
43 virtual std::string getName() const {
44 return getPlugin()->getName();
45 }
46
47 virtual std::string getDescription() const {
48 return getPlugin()->getDescription();
49 }
50
51 virtual std::string getMaker() const {
52 return getPlugin()->getMaker();
53 }
54
55 virtual std::string getCopyright() const {
56 return getPlugin()->getCopyright();
57 }
58
59 virtual int getPluginVersion() const {
60 return getPlugin()->getPluginVersion();
61 }
62
63 virtual ParameterList getParameterDescriptors() const {
64 return getPlugin()->getParameterDescriptors();
65 }
66
67 virtual float getParameter(std::string name) const {
68 return getPlugin()->getParameter(name);
69 }
70
71 virtual void setParameter(std::string name, float value) {
72 getPlugin()->setParameter(name, value);
73 }
74
75 virtual ProgramList getPrograms() const {
76 return getPlugin()->getPrograms();
77 }
78
79 virtual std::string getCurrentProgram() const {
80 return getPlugin()->getCurrentProgram();
81 }
82
83 virtual void selectProgram(std::string program) {
84 getPlugin()->selectProgram(program);
85 }
86
87 virtual bool initialise(size_t inputChannels,
88 size_t stepSize,
89 size_t blockSize) {
90 return getPlugin()->initialise(inputChannels, stepSize, blockSize);
91 }
92
93 virtual void reset() {
94 getPlugin()->reset();
95 }
96
97 virtual InputDomain getInputDomain() const {
98 return getPlugin()->getInputDomain();
99 }
100
101 virtual size_t getPreferredBlockSize() const {
102 return getPlugin()->getPreferredBlockSize();
103 }
104
105 virtual size_t getPreferredStepSize() const {
106 return getPlugin()->getPreferredStepSize();
107 }
108
109 virtual size_t getMinChannelCount() const {
110 return getPlugin()->getMinChannelCount();
111 }
112
113 virtual size_t getMaxChannelCount() const {
114 return getPlugin()->getMaxChannelCount();
115 }
116
117 virtual OutputList getOutputDescriptors() const {
118 return getPlugin()->getOutputDescriptors();
119 }
120
121 virtual FeatureSet process(const float *const *inputBuffers,
122 Vamp::RealTime timestamp) {
123 return getPlugin()->process(inputBuffers, timestamp);
124 }
125
126 virtual FeatureSet getRemainingFeatures() {
127 return getPlugin()->getRemainingFeatures();
128 }
129
130 private:
131 ProcessQtTransport m_transport;
132 CapnpRRClient m_client;
133 Vamp::Plugin *m_plugin;
134 Vamp::Plugin *getPlugin() const {
135 if (!m_plugin) {
136 throw std::logic_error
137 ("Plugin load failed (should have called AutoPlugin::isOK)");
138 }
139 return m_plugin;
140 }
141 };
142
143 }
144 }
145
146 #endif
147
148