comparison plugin/PiperVampPluginFactory.cpp @ 1240:42a4b058f8ba 3.0-integration

Support for multiple servers
author Chris Cannam
date Tue, 01 Nov 2016 12:09:05 +0000
parents fe391a7b8376
children c6bdf247016a
comparison
equal deleted inserted replaced
1239:5261a7791f1c 1240:42a4b058f8ba
43 43
44 using namespace std; 44 using namespace std;
45 45
46 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1 46 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1
47 47
48 PiperVampPluginFactory::PiperVampPluginFactory() : 48 PiperVampPluginFactory::PiperVampPluginFactory()
49 // No server unless we find one - don't run arbitrary stuff from the path:
50 m_serverName()
51 { 49 {
52 // Server must exist either in the same directory as this one or 50 // Server must exist either in the same directory as this one or
53 // (preferably) a subdirectory called "piper-bin". 51 // (preferably) a subdirectory called "piper-bin".
54 //!!! todo: merge this with plugin scan checker thingy used in main.cpp? 52 //!!! todo: merge this with plugin scan checker thingy used in main.cpp?
53
55 QString myDir = QCoreApplication::applicationDirPath(); 54 QString myDir = QCoreApplication::applicationDirPath();
56 QString name = "piper-vamp-simple-server"; 55 QString name = "piper-vamp-simple-server";
57 QString path = myDir + "/piper-bin/" + name; 56 QStringList suffixes = getServerSuffixes();
58 QString suffix = ""; 57 QString extension = "";
59 #ifdef _WIN32 58 #ifdef _WIN32
60 suffix = ".exe"; 59 extension = ".exe";
61 #endif 60 #endif
62 if (!QFile(path + suffix).exists()) { 61
63 cerr << "NOTE: Piper Vamp server not found at " << (path + suffix) 62 for (QString s: suffixes) {
64 << ", trying in my own directory" << endl; 63
65 path = myDir + "/" + name; 64 QString path = myDir + "/piper-bin/" + name + s + extension;
66 } 65
67 if (!QFile(path + suffix).exists()) { 66 if (QFile(path).exists()) {
68 cerr << "NOTE: Piper Vamp server not found at " << (path + suffix) 67 m_servers.push_back(path);
69 << endl; 68 } else {
69 cerr << "NOTE: Piper Vamp server " << name << s
70 << " not found at " << path
71 << ", trying in my own directory" << endl;
72 path = myDir + "/" + name + s + extension;
73
74 if (QFile(path).exists()) {
75 m_servers.push_back(path);
76 } else {
77 cerr << "NOTE: Piper Vamp server " << name << s
78 << " not found at " << path << endl;
79 }
80 }
81 }
82
83 if (m_servers.empty()) {
84 cerr << "NOTE: No Piper Vamp servers found" << endl;
85 }
86 }
87
88 QStringList
89 PiperVampPluginFactory::getServerSuffixes()
90 {
91 if (sizeof(void *) == 8) {
92 return { "-64", "", "-32" };
70 } else { 93 } else {
71 m_serverName = (path + suffix).toStdString(); 94 return { "", "-32" };
72 } 95 }
73 } 96 }
74 97
75 vector<QString> 98 vector<QString>
76 PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage) 99 PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage)
77 { 100 {
78 Profiler profiler("PiperVampPluginFactory::getPluginIdentifiers"); 101 Profiler profiler("PiperVampPluginFactory::getPluginIdentifiers");
79 102
80 QMutexLocker locker(&m_mutex); 103 QMutexLocker locker(&m_mutex);
81 104
82 if (m_serverName == "") { 105 if (m_servers.empty()) {
83 errorMessage = QObject::tr("External plugin host executable does not appear to be installed"); 106 errorMessage = QObject::tr("External plugin host executable does not appear to be installed");
84 return {}; 107 return {};
85 } 108 }
86 109
87 if (m_pluginData.empty()) { 110 if (m_pluginData.empty()) {
101 PiperVampPluginFactory::instantiatePlugin(QString identifier, 124 PiperVampPluginFactory::instantiatePlugin(QString identifier,
102 sv_samplerate_t inputSampleRate) 125 sv_samplerate_t inputSampleRate)
103 { 126 {
104 Profiler profiler("PiperVampPluginFactory::instantiatePlugin"); 127 Profiler profiler("PiperVampPluginFactory::instantiatePlugin");
105 128
129 if (m_origins.find(identifier) == m_origins.end()) {
130 cerr << "ERROR: No known server for identifier " << identifier << endl;
131 return 0;
132 }
133
106 auto psd = getPluginStaticData(identifier); 134 auto psd = getPluginStaticData(identifier);
107 if (psd.pluginKey == "") { 135 if (psd.pluginKey == "") {
108 return 0; 136 return 0;
109 } 137 }
110 138
111 auto ap = new piper_vamp::client::AutoPlugin 139 auto ap = new piper_vamp::client::AutoPlugin
112 (m_serverName, psd.pluginKey, float(inputSampleRate), 0); 140 (m_origins[identifier].toStdString(),
141 psd.pluginKey, float(inputSampleRate), 0);
142
113 if (!ap->isOK()) { 143 if (!ap->isOK()) {
114 delete ap; 144 delete ap;
115 return 0; 145 return 0;
116 } 146 }
117 147
139 } 169 }
140 170
141 void 171 void
142 PiperVampPluginFactory::populate(QString &errorMessage) 172 PiperVampPluginFactory::populate(QString &errorMessage)
143 { 173 {
144 if (m_serverName == "") return; 174 QString someError;
145 175
146 piper_vamp::client::ProcessQtTransport transport(m_serverName, "capnp"); 176 for (QString s: m_servers) {
177
178 populateFrom(s, someError);
179
180 if (someError != "" && errorMessage == "") {
181 errorMessage = someError;
182 }
183 }
184 }
185
186 void
187 PiperVampPluginFactory::populateFrom(QString server, QString &errorMessage)
188 {
189 piper_vamp::client::ProcessQtTransport transport(server.toStdString(),
190 "capnp");
147 if (!transport.isOK()) { 191 if (!transport.isOK()) {
148 errorMessage = QObject::tr("Could not start external plugin host"); 192 errorMessage = QObject::tr("Could not start external plugin host");
149 return; 193 return;
150 } 194 }
151 195
163 .arg(e.what()); 207 .arg(e.what());
164 return; 208 return;
165 } 209 }
166 210
167 for (const auto &pd: lr.available) { 211 for (const auto &pd: lr.available) {
168 212
169 QString identifier = 213 QString identifier =
170 QString("vamp:") + QString::fromStdString(pd.pluginKey); 214 QString("vamp:") + QString::fromStdString(pd.pluginKey);
171 215
216 if (m_origins.find(identifier) != m_origins.end()) {
217 // have it already, from a higher-priority server
218 // (e.g. 64-bit instead of 32-bit)
219 continue;
220 }
221
222 m_origins[identifier] = server;
223
172 m_pluginData[identifier] = pd; 224 m_pluginData[identifier] = pd;
173 225
174 QStringList catlist; 226 QStringList catlist;
175 for (const auto &cs: pd.category) { 227 for (const auto &cs: pd.category) {
176 catlist.push_back(QString::fromStdString(cs)); 228 catlist.push_back(QString::fromStdString(cs));