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