cannam@287: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@287: cannam@287: /* cannam@287: Piper C++ cannam@287: cannam@287: An API for audio analysis and feature extraction plugins. cannam@287: cannam@287: Centre for Digital Music, Queen Mary, University of London. cannam@287: Copyright 2006-2019 Chris Cannam and QMUL. cannam@287: cannam@287: Permission is hereby granted, free of charge, to any person cannam@287: obtaining a copy of this software and associated documentation cannam@287: files (the "Software"), to deal in the Software without cannam@287: restriction, including without limitation the rights to use, copy, cannam@287: modify, merge, publish, distribute, sublicense, and/or sell copies cannam@287: of the Software, and to permit persons to whom the Software is cannam@287: furnished to do so, subject to the following conditions: cannam@287: cannam@287: The above copyright notice and this permission notice shall be cannam@287: included in all copies or substantial portions of the Software. cannam@287: cannam@287: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, cannam@287: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF cannam@287: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND cannam@287: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR cannam@287: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF cannam@287: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION cannam@287: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cannam@287: cannam@287: Except as contained in this notice, the names of the Centre for cannam@287: Digital Music; Queen Mary, University of London; and Chris Cannam cannam@287: shall not be used in advertising or otherwise to promote the sale, cannam@287: use or other dealings in this Software without prior written cannam@287: authorization. cannam@287: */ cannam@287: cannam@287: #ifndef PIPER_PLUGIN_PROGRAM_PARAMETERS_H cannam@287: #define PIPER_PLUGIN_PROGRAM_PARAMETERS_H cannam@287: cannam@287: #include cannam@287: cannam@287: #include cannam@287: #include cannam@287: cannam@287: namespace piper_vamp { cannam@287: cannam@287: /** cannam@287: * \class PluginProgramParameters cannam@287: * cannam@287: * PluginProgramParameters is a structure mapping from program names cannam@287: * to the parameter settings associated with those programs. cannam@287: */ cannam@287: struct PluginProgramParameters cannam@287: { cannam@287: std::map> programParameters; cannam@287: cannam@287: /** cannam@287: * Extract the program parameters from the given plugin (without cannam@287: * retaining any persistent reference to the plugin itself). cannam@287: */ cannam@287: static PluginProgramParameters cannam@287: fromPlugin(Vamp::Plugin *p, const PluginConfiguration &defaultConfiguration) { cannam@287: cannam@287: auto programs = p->getPrograms(); cannam@287: if (programs.empty()) return {}; cannam@287: cannam@287: PluginProgramParameters pp; cannam@287: for (auto program: programs) { cannam@287: p->selectProgram(program); cannam@287: for (auto param: defaultConfiguration.parameterValues) { cannam@287: auto id = param.first; cannam@287: pp.programParameters[program][id] = p->getParameter(id); cannam@287: } cannam@287: } cannam@287: cannam@287: if (defaultConfiguration.currentProgram != "") { cannam@287: p->selectProgram(defaultConfiguration.currentProgram); cannam@287: } cannam@287: cannam@287: for (auto param: defaultConfiguration.parameterValues) { cannam@287: p->setParameter(param.first, param.second); cannam@287: } cannam@287: cannam@287: return pp; cannam@287: } cannam@287: }; cannam@287: cannam@287: } cannam@287: cannam@287: #endif