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