Mercurial > hg > piper-cpp
comparison vamp-support/PluginProgramParameters.h @ 287:09753ad777db
Add support for ProgramParameters. In theory this means we can select a program and then re-query the plugin's parameters and get the right values back, just as would happen if we were working with the remote extractor directly as a local Vamp plugin.
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 07 Apr 2020 15:56:02 +0100 |
parents | |
children | 26027c3a99a0 |
comparison
equal
deleted
inserted
replaced
286:b3b2e092bd61 | 287:09753ad777db |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Piper C++ | |
5 | |
6 An API for audio analysis and feature extraction plugins. | |
7 | |
8 Centre for Digital Music, Queen Mary, University of London. | |
9 Copyright 2006-2019 Chris Cannam and QMUL. | |
10 | |
11 Permission is hereby granted, free of charge, to any person | |
12 obtaining a copy of this software and associated documentation | |
13 files (the "Software"), to deal in the Software without | |
14 restriction, including without limitation the rights to use, copy, | |
15 modify, merge, publish, distribute, sublicense, and/or sell copies | |
16 of the Software, and to permit persons to whom the Software is | |
17 furnished to do so, subject to the following conditions: | |
18 | |
19 The above copyright notice and this permission notice shall be | |
20 included in all copies or substantial portions of the Software. | |
21 | |
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | |
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
29 | |
30 Except as contained in this notice, the names of the Centre for | |
31 Digital Music; Queen Mary, University of London; and Chris Cannam | |
32 shall not be used in advertising or otherwise to promote the sale, | |
33 use or other dealings in this Software without prior written | |
34 authorization. | |
35 */ | |
36 | |
37 #ifndef PIPER_PLUGIN_PROGRAM_PARAMETERS_H | |
38 #define PIPER_PLUGIN_PROGRAM_PARAMETERS_H | |
39 | |
40 #include <vamp-hostsdk/Plugin.h> | |
41 | |
42 #include <map> | |
43 #include <string> | |
44 | |
45 namespace piper_vamp { | |
46 | |
47 /** | |
48 * \class PluginProgramParameters | |
49 * | |
50 * PluginProgramParameters is a structure mapping from program names | |
51 * to the parameter settings associated with those programs. | |
52 */ | |
53 struct PluginProgramParameters | |
54 { | |
55 std::map<std::string, std::map<std::string, float>> programParameters; | |
56 | |
57 /** | |
58 * Extract the program parameters from the given plugin (without | |
59 * retaining any persistent reference to the plugin itself). | |
60 */ | |
61 static PluginProgramParameters | |
62 fromPlugin(Vamp::Plugin *p, const PluginConfiguration &defaultConfiguration) { | |
63 | |
64 auto programs = p->getPrograms(); | |
65 if (programs.empty()) return {}; | |
66 | |
67 PluginProgramParameters pp; | |
68 | |
69 for (auto program: programs) { | |
70 | |
71 p->selectProgram(program); | |
72 | |
73 for (auto param: defaultConfiguration.parameterValues) { | |
74 auto id = param.first; | |
75 pp.programParameters[program][id] = p->getParameter(id); | |
76 } | |
77 } | |
78 | |
79 if (defaultConfiguration.currentProgram != "") { | |
80 p->selectProgram(defaultConfiguration.currentProgram); | |
81 } | |
82 | |
83 for (auto param: defaultConfiguration.parameterValues) { | |
84 p->setParameter(param.first, param.second); | |
85 } | |
86 | |
87 return pp; | |
88 } | |
89 }; | |
90 | |
91 } | |
92 | |
93 #endif |