Mercurial > hg > svcore
comparison plugin/PiperVampPluginFactory.cpp @ 1225:ba16388b937d piper
Restore native-Vamp factory and make the choice between Piper and Native a preference
author | Chris Cannam |
---|---|
date | Fri, 21 Oct 2016 11:49:27 +0100 |
parents | plugin/FeatureExtractionPluginFactory.cpp@ab050519c4ba |
children | 5d886b7b4029 |
comparison
equal
deleted
inserted
replaced
1224:ab050519c4ba | 1225:ba16388b937d |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam and QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "PiperVampPluginFactory.h" | |
17 #include "PluginIdentifier.h" | |
18 | |
19 #include "system/System.h" | |
20 | |
21 #include "PluginScan.h" | |
22 | |
23 #ifdef _WIN32 | |
24 #undef VOID | |
25 #undef ERROR | |
26 #define CAPNP_LITE 1 | |
27 #endif | |
28 | |
29 #include "vamp-client/AutoPlugin.h" | |
30 | |
31 #include <QDir> | |
32 #include <QFile> | |
33 #include <QFileInfo> | |
34 #include <QTextStream> | |
35 | |
36 #include <iostream> | |
37 | |
38 #include "base/Profiler.h" | |
39 | |
40 #include "vamp-client/ProcessQtTransport.h" | |
41 #include "vamp-client/CapnpRRClient.h" | |
42 | |
43 using namespace std; | |
44 | |
45 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1 | |
46 | |
47 PiperVampPluginFactory::PiperVampPluginFactory() : | |
48 m_serverName("piper-cpp/bin/piper-vamp-server") //!!! | |
49 { | |
50 } | |
51 | |
52 vector<QString> | |
53 PiperVampPluginFactory::getPluginIdentifiers() | |
54 { | |
55 Profiler profiler("PiperVampPluginFactory::getPluginIdentifiers"); | |
56 | |
57 QMutexLocker locker(&m_mutex); | |
58 | |
59 if (m_pluginData.empty()) { | |
60 populate(); | |
61 } | |
62 | |
63 vector<QString> rv; | |
64 | |
65 for (const auto &d: m_pluginData) { | |
66 rv.push_back(QString("vamp:") + QString::fromStdString(d.second.pluginKey)); | |
67 } | |
68 | |
69 return rv; | |
70 } | |
71 | |
72 Vamp::Plugin * | |
73 PiperVampPluginFactory::instantiatePlugin(QString identifier, | |
74 sv_samplerate_t inputSampleRate) | |
75 { | |
76 Profiler profiler("PiperVampPluginFactory::instantiatePlugin"); | |
77 | |
78 auto psd = getPluginStaticData(identifier); | |
79 if (psd.pluginKey == "") { | |
80 return 0; | |
81 } | |
82 | |
83 auto ap = new piper_vamp::client::AutoPlugin | |
84 (m_serverName, psd.pluginKey, float(inputSampleRate), 0); | |
85 if (!ap->isOK()) { | |
86 delete ap; | |
87 return 0; | |
88 } | |
89 | |
90 return ap; | |
91 } | |
92 | |
93 piper_vamp::PluginStaticData | |
94 PiperVampPluginFactory::getPluginStaticData(QString identifier) | |
95 { | |
96 if (m_pluginData.find(identifier) != m_pluginData.end()) { | |
97 return m_pluginData[identifier]; | |
98 } else { | |
99 return {}; | |
100 } | |
101 } | |
102 | |
103 QString | |
104 PiperVampPluginFactory::getPluginCategory(QString identifier) | |
105 { | |
106 if (m_taxonomy.find(identifier) != m_taxonomy.end()) { | |
107 return m_taxonomy[identifier]; | |
108 } else { | |
109 return {}; | |
110 } | |
111 } | |
112 | |
113 void | |
114 PiperVampPluginFactory::populate() | |
115 { | |
116 piper_vamp::client::ProcessQtTransport transport(m_serverName); | |
117 piper_vamp::client::CapnpRRClient client(&transport); | |
118 piper_vamp::ListResponse lr = client.listPluginData(); | |
119 | |
120 for (const auto &pd: lr.available) { | |
121 | |
122 QString identifier = | |
123 QString("vamp:") + QString::fromStdString(pd.pluginKey); | |
124 | |
125 m_pluginData[identifier] = pd; | |
126 | |
127 QStringList catlist; | |
128 for (const auto &cs: pd.category) { | |
129 catlist.push_back(QString::fromStdString(cs)); | |
130 } | |
131 | |
132 m_taxonomy[identifier] = catlist.join(" > "); | |
133 } | |
134 } | |
135 |