Mercurial > hg > piper-cpp
comparison vamp-client/qt/AutoPlugin.h @ 209:ac4f5f8ee0e7
Merge branch 'dev/step-and-block-size'
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Thu, 09 Feb 2017 14:16:37 +0000 |
parents | ad6025dc0b04 |
children |
comparison
equal
deleted
inserted
replaced
205:587e9691a44e | 209:ac4f5f8ee0e7 |
---|---|
44 | 44 |
45 namespace piper_vamp { | 45 namespace piper_vamp { |
46 namespace client { | 46 namespace client { |
47 | 47 |
48 /** | 48 /** |
49 * This "plugin" make the Piper client abstraction behave like a local | 49 * AutoPlugin presents a Piper feature extractor in the form of a Vamp |
50 * Vamp plugin, with its own server that lasts only for the lifetime | 50 * plugin, managing its own single-use server instance. That is, the |
51 * of this plugin and serves only it. | 51 * distinguishing quality of AutoPlugin (in comparison with |
52 * PluginStub) is that it runs and terminates its own Piper server, | |
53 * whose lifetime matches that of the plugin. | |
54 * | |
55 * Example usage: | |
56 * | |
57 * Vamp::Plugin *plugin = | |
58 * new AutoPlugin("piper-server-name.exe", | |
59 * "vamp-example-plugins:zerocrossing", | |
60 * 44100.0f, | |
61 * Vamp::HostExt::PluginLoader::ADAPT_ALL_SAFE, | |
62 * nullptr); | |
63 * plugin->initialise(...); | |
64 * plugin->process(...); <-- in the normal way for a Vamp plugin | |
65 * delete plugin; <-- causes the server to exit | |
66 * | |
67 * AutoPlugin makes use of the Loader and PluginClient interfaces, | |
68 * providing them its own transport layer object for its single server. | |
52 * | 69 * |
53 * Note that any method may throw ServerCrashed, RequestTimedOut or | 70 * Note that any method may throw ServerCrashed, RequestTimedOut or |
54 * ProtocolError exceptions. | 71 * ProtocolError exceptions. |
55 */ | 72 */ |
56 class AutoPlugin : public Vamp::Plugin | 73 class AutoPlugin : public Vamp::Plugin |
57 { | 74 { |
58 public: | 75 public: |
76 /** | |
77 * Construct an AutoPlugin that runs an instance of the Piper | |
78 * server with the given server name (executable path), requesting | |
79 * the given plugin key from the server. | |
80 * | |
81 * \param adapterFlags a bitwise OR of the values in the | |
82 * Vamp::HostExt::PluginLoader::AdapterFlags enumeration | |
83 * | |
84 * \param logger an optional callback for log messages. Pass a | |
85 * null pointer to use cerr instead. | |
86 */ | |
59 AutoPlugin(std::string serverName, | 87 AutoPlugin(std::string serverName, |
60 std::string pluginKey, | 88 std::string pluginKey, |
61 float inputSampleRate, | 89 float inputSampleRate, |
62 int adapterFlags, | 90 int adapterFlags, |
63 LogCallback *logger) : // logger may be nullptr for cerr | 91 LogCallback *logger) : |
64 Vamp::Plugin(inputSampleRate), | 92 Vamp::Plugin(inputSampleRate), |
65 m_logger(logger), | 93 m_logger(logger), |
66 m_transport(serverName, "capnp", logger), | 94 m_transport(serverName, "capnp", logger), |
67 m_client(&m_transport, logger) | 95 m_client(&m_transport, logger) |
68 { | 96 { |
79 } | 107 } |
80 } | 108 } |
81 | 109 |
82 virtual ~AutoPlugin() { | 110 virtual ~AutoPlugin() { |
83 delete m_plugin; | 111 delete m_plugin; |
112 // The transport is a plain data member and will be deleted | |
113 // here, which will have the effect of terminating the server | |
84 } | 114 } |
85 | 115 |
86 bool isOK() const { | 116 bool isOK() const { |
87 return (m_plugin != nullptr); | 117 return (m_plugin != nullptr); |
88 } | 118 } |