| 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@97 | 47 | 
| c@97 | 48 namespace piper_vamp { | 
| c@97 | 49 | 
| c@97 | 50 class LoaderRequests | 
| c@97 | 51 { | 
| c@97 | 52 public: | 
| c@97 | 53     ListResponse | 
| c@97 | 54     listPluginData() { | 
| c@97 | 55 | 
| c@97 | 56 	auto loader = Vamp::HostExt::PluginLoader::getInstance(); | 
| c@97 | 57 	auto keys = loader->listPlugins(); | 
| c@97 | 58 	ListResponse response; | 
| c@97 | 59 | 
| c@97 | 60 	for (std::string key: keys) { | 
| c@97 | 61 	    Vamp::Plugin *p = loader->loadPlugin(key, 44100, 0); | 
| c@97 | 62 	    if (!p) continue; | 
| c@97 | 63 	    auto category = loader->getPluginCategory(key); | 
| c@97 | 64 	    response.available.push_back | 
| c@97 | 65 		(PluginStaticData::fromPlugin(key, category, p)); | 
| c@97 | 66 	    delete p; | 
| c@97 | 67 	} | 
| c@97 | 68 | 
| c@97 | 69 	return response; | 
| c@97 | 70     } | 
| c@97 | 71 | 
| c@97 | 72     LoadResponse | 
| c@97 | 73     loadPlugin(LoadRequest req) { | 
| c@97 | 74 | 
| c@97 | 75 	auto loader = Vamp::HostExt::PluginLoader::getInstance(); | 
| c@97 | 76 | 
| c@97 | 77 	Vamp::Plugin *plugin = loader->loadPlugin(req.pluginKey, | 
| c@97 | 78 						  req.inputSampleRate, | 
| c@97 | 79 						  req.adapterFlags); | 
| c@97 | 80 | 
| c@97 | 81 	LoadResponse response; | 
| c@97 | 82 	response.plugin = plugin; | 
| c@97 | 83 	if (!plugin) return response; | 
| c@97 | 84 | 
| c@97 | 85 	response.plugin = plugin; | 
| c@97 | 86 	response.staticData = PluginStaticData::fromPlugin | 
| c@97 | 87 	    (req.pluginKey, | 
| c@97 | 88 	     loader->getPluginCategory(req.pluginKey), | 
| c@97 | 89 	     plugin); | 
| c@97 | 90 | 
| c@97 | 91 	int defaultChannels = 0; | 
| c@97 | 92 	if (plugin->getMinChannelCount() == plugin->getMaxChannelCount()) { | 
| c@108 | 93 	    defaultChannels = int(plugin->getMinChannelCount()); | 
| c@97 | 94 	} | 
| c@97 | 95 | 
| c@97 | 96 	response.defaultConfiguration = PluginConfiguration::fromPlugin | 
| c@97 | 97 	    (plugin, | 
| c@97 | 98 	     defaultChannels, | 
| c@108 | 99 	     int(plugin->getPreferredStepSize()), | 
| c@108 | 100 	     int(plugin->getPreferredBlockSize())); | 
| c@97 | 101 | 
| c@97 | 102 	return response; | 
| c@97 | 103     } | 
| c@97 | 104 | 
| c@97 | 105     ConfigurationResponse | 
| c@97 | 106     configurePlugin(ConfigurationRequest req) { | 
| c@97 | 107 | 
| c@97 | 108 	for (PluginConfiguration::ParameterMap::const_iterator i = | 
| c@97 | 109 		 req.configuration.parameterValues.begin(); | 
| c@97 | 110 	     i != req.configuration.parameterValues.end(); ++i) { | 
| c@97 | 111 	    req.plugin->setParameter(i->first, i->second); | 
| c@97 | 112 	} | 
| c@97 | 113 | 
| c@97 | 114 	if (req.configuration.currentProgram != "") { | 
| c@97 | 115 	    req.plugin->selectProgram(req.configuration.currentProgram); | 
| c@97 | 116 	} | 
| c@97 | 117 | 
| c@97 | 118 	ConfigurationResponse response; | 
| c@97 | 119 | 
| c@97 | 120 	response.plugin = req.plugin; | 
| c@97 | 121 | 
| c@97 | 122 	if (req.plugin->initialise(req.configuration.channelCount, | 
| c@97 | 123 				   req.configuration.stepSize, | 
| c@97 | 124 				   req.configuration.blockSize)) { | 
| c@97 | 125 	    response.outputs = req.plugin->getOutputDescriptors(); | 
| c@97 | 126 	} | 
| c@97 | 127 | 
| c@97 | 128 	return response; | 
| c@97 | 129     } | 
| c@97 | 130 }; | 
| c@97 | 131 | 
| c@97 | 132 } | 
| c@97 | 133 | 
| c@97 | 134 #endif |