annotate vamp-support/LoaderRequests.h @ 185:3eb00e5c76c4

Pull step & block size out into framing struct, return in config Update the C++ code to separate out the framing parameters (step and block size) from the configuration structure into their own structure, as in the latest schema, and to return the accepted framing params in the configuration response. This also implies that the plugin stub (which adapts Piper API back to Vamp) makes a note of the returned values, making them available via its own getPreferredStep/BlockSize so that the host can retry the initialise call in the case where it failed for having the wrong values first time.
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 03 Feb 2017 16:23:21 +0000
parents bf8e3e7dd7de
children 52322dde68ea
rev   line source
c@97 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@97 2
c@97 3 /*
c@97 4 Piper C++
c@97 5
c@97 6 An API for audio analysis and feature extraction plugins.
c@97 7
c@97 8 Centre for Digital Music, Queen Mary, University of London.
c@97 9 Copyright 2006-2016 Chris Cannam and QMUL.
c@97 10
c@97 11 Permission is hereby granted, free of charge, to any person
c@97 12 obtaining a copy of this software and associated documentation
c@97 13 files (the "Software"), to deal in the Software without
c@97 14 restriction, including without limitation the rights to use, copy,
c@97 15 modify, merge, publish, distribute, sublicense, and/or sell copies
c@97 16 of the Software, and to permit persons to whom the Software is
c@97 17 furnished to do so, subject to the following conditions:
c@97 18
c@97 19 The above copyright notice and this permission notice shall be
c@97 20 included in all copies or substantial portions of the Software.
c@97 21
c@97 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c@97 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c@97 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c@97 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
c@97 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
c@97 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
c@97 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
c@97 29
c@97 30 Except as contained in this notice, the names of the Centre for
c@97 31 Digital Music; Queen Mary, University of London; and Chris Cannam
c@97 32 shall not be used in advertising or otherwise to promote the sale,
c@97 33 use or other dealings in this Software without prior written
c@97 34 authorization.
c@97 35 */
c@97 36
c@97 37 #ifndef PIPER_LOADER_REQUESTS_H
c@97 38 #define PIPER_LOADER_REQUESTS_H
c@97 39
c@97 40 #include "PluginStaticData.h"
c@97 41 #include "PluginConfiguration.h"
c@97 42
c@97 43 #include <vamp-hostsdk/PluginLoader.h>
c@97 44
c@97 45 #include <map>
c@97 46 #include <string>
c@134 47 #include <iostream>
c@97 48
c@97 49 namespace piper_vamp {
c@97 50
c@97 51 class LoaderRequests
c@97 52 {
c@97 53 public:
c@97 54 ListResponse
c@127 55 listPluginData(ListRequest req) {
c@97 56
c@97 57 auto loader = Vamp::HostExt::PluginLoader::getInstance();
c@134 58
cannam@150 59 // std::cerr << "listPluginData: about to ask loader to list plugins" << std::endl;
c@127 60
c@127 61 std::vector<std::string> keys;
c@127 62 if (req.from.empty()) {
c@127 63 keys = loader->listPlugins();
c@127 64 } else {
c@127 65 keys = loader->listPluginsIn(req.from);
c@127 66 }
c@127 67
cannam@150 68 // std::cerr << "listPluginData: loader listed " << keys.size() << " plugins" << std::endl;
c@134 69
c@97 70 ListResponse response;
c@97 71 for (std::string key: keys) {
cannam@150 72 // std::cerr << "listPluginData: loading plugin and querying static data: " << key << std::endl;
c@97 73 Vamp::Plugin *p = loader->loadPlugin(key, 44100, 0);
c@97 74 if (!p) continue;
c@97 75 auto category = loader->getPluginCategory(key);
c@97 76 response.available.push_back
c@97 77 (PluginStaticData::fromPlugin(key, category, p));
c@97 78 delete p;
c@97 79 }
c@97 80
c@97 81 return response;
c@97 82 }
c@97 83
c@97 84 LoadResponse
c@97 85 loadPlugin(LoadRequest req) {
c@97 86
c@97 87 auto loader = Vamp::HostExt::PluginLoader::getInstance();
c@97 88
c@97 89 Vamp::Plugin *plugin = loader->loadPlugin(req.pluginKey,
c@97 90 req.inputSampleRate,
c@97 91 req.adapterFlags);
c@97 92
c@97 93 LoadResponse response;
c@97 94 response.plugin = plugin;
c@97 95 if (!plugin) return response;
c@97 96
c@97 97 response.plugin = plugin;
c@97 98 response.staticData = PluginStaticData::fromPlugin
c@97 99 (req.pluginKey,
c@97 100 loader->getPluginCategory(req.pluginKey),
c@97 101 plugin);
c@97 102
c@97 103 int defaultChannels = 0;
c@97 104 if (plugin->getMinChannelCount() == plugin->getMaxChannelCount()) {
c@108 105 defaultChannels = int(plugin->getMinChannelCount());
c@97 106 }
c@97 107
c@97 108 response.defaultConfiguration = PluginConfiguration::fromPlugin
c@97 109 (plugin,
c@97 110 defaultChannels,
c@108 111 int(plugin->getPreferredStepSize()),
c@108 112 int(plugin->getPreferredBlockSize()));
c@97 113
c@97 114 return response;
c@97 115 }
c@97 116
c@97 117 ConfigurationResponse
c@97 118 configurePlugin(ConfigurationRequest req) {
c@97 119
c@97 120 for (PluginConfiguration::ParameterMap::const_iterator i =
c@97 121 req.configuration.parameterValues.begin();
c@97 122 i != req.configuration.parameterValues.end(); ++i) {
c@97 123 req.plugin->setParameter(i->first, i->second);
c@97 124 }
c@97 125
c@97 126 if (req.configuration.currentProgram != "") {
c@97 127 req.plugin->selectProgram(req.configuration.currentProgram);
c@97 128 }
c@97 129
c@97 130 ConfigurationResponse response;
c@97 131
c@97 132 response.plugin = req.plugin;
cannam@185 133
cannam@185 134 if (req.configuration.framing.stepSize == 0 ||
cannam@185 135 req.configuration.framing.blockSize == 0) {
cannam@185 136 return response;
cannam@185 137 }
cannam@185 138
c@97 139 if (req.plugin->initialise(req.configuration.channelCount,
cannam@185 140 req.configuration.framing.stepSize,
cannam@185 141 req.configuration.framing.blockSize)) {
cannam@185 142
c@97 143 response.outputs = req.plugin->getOutputDescriptors();
cannam@185 144
cannam@185 145 // If the Vamp plugin initialise() call succeeds, then by
cannam@185 146 // definition it is accepting the step and block size
cannam@185 147 // passed in
cannam@185 148 response.framing = req.configuration.framing;
cannam@185 149
cannam@185 150 } else {
cannam@185 151
cannam@185 152 // If initialise() fails, one reason could be that it
cannam@185 153 // didn't like the passed-in step and block size. If we
cannam@185 154 // return its current preferred values here, the
cannam@185 155 // host/client can retry with these (if they differ)
cannam@185 156 response.framing.stepSize = req.plugin->getPreferredStepSize();
cannam@185 157 response.framing.blockSize = req.plugin->getPreferredBlockSize();
cannam@185 158 }
c@97 159
c@97 160 return response;
c@97 161 }
c@97 162 };
c@97 163
c@97 164 }
c@97 165
c@97 166 #endif