annotate src/knownplugins.cpp @ 34:6905d8b146f6 plugin-path-config

Toward supporting separate environment variables for 32-bit plugins on a 64-bit system (otherwise we try to load both from the same helpers)
author Chris Cannam
date Wed, 06 Jun 2018 13:49:23 +0100
parents c1081e8d26a7
children 4154894d638c
rev   line source
Chris@4 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@5 2 /*
Chris@20 3 Copyright (c) 2016 Queen Mary, University of London
Chris@5 4
Chris@20 5 Permission is hereby granted, free of charge, to any person
Chris@20 6 obtaining a copy of this software and associated documentation
Chris@20 7 files (the "Software"), to deal in the Software without
Chris@20 8 restriction, including without limitation the rights to use, copy,
Chris@20 9 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@20 10 of the Software, and to permit persons to whom the Software is
Chris@20 11 furnished to do so, subject to the following conditions:
Chris@5 12
Chris@20 13 The above copyright notice and this permission notice shall be
Chris@20 14 included in all copies or substantial portions of the Software.
Chris@5 15
Chris@20 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@20 17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@20 18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@20 19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
Chris@20 20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@20 21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@20 22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@5 23
Chris@20 24 Except as contained in this notice, the names of the Centre for
Chris@20 25 Digital Music and Queen Mary, University of London shall not be
Chris@20 26 used in advertising or otherwise to promote the sale, use or other
Chris@20 27 dealings in this Software without prior written authorization.
Chris@5 28 */
Chris@4 29
Chris@4 30 #include "knownplugins.h"
Chris@4 31
Chris@4 32 #include <sstream>
Chris@4 33
Chris@4 34 using namespace std;
Chris@4 35
Chris@4 36 #if defined(_WIN32)
Chris@4 37 #define PATH_SEPARATOR ';'
Chris@4 38 #else
Chris@4 39 #define PATH_SEPARATOR ':'
Chris@4 40 #endif
Chris@4 41
Chris@6 42 KnownPlugins::KnownPlugins(string helperExecutableName,
Chris@6 43 PluginCandidates::LogCallback *cb) :
Chris@20 44 m_candidates(helperExecutableName),
Chris@20 45 m_helperExecutableName(helperExecutableName)
Chris@4 46 {
Chris@6 47 m_candidates.setLogCallback(cb);
Chris@34 48
Chris@34 49 std::string variableSuffix = "";
Chris@34 50 if (is32bit()) {
Chris@34 51 variableSuffix = "_32";
Chris@34 52 }
Chris@6 53
Chris@34 54 m_known[VampPlugin] = {
Chris@34 55 "vamp",
Chris@34 56 "VAMP_PATH" + variableSuffix,
Chris@34 57 expandConventionalPath(VampPlugin, "VAMP_PATH" + variableSuffix),
Chris@34 58 "vampGetPluginDescriptor"
Chris@34 59 };
Chris@34 60
Chris@34 61 m_known[LADSPAPlugin] = {
Chris@34 62 "ladspa",
Chris@34 63 "LADSPA_PATH" + variableSuffix,
Chris@34 64 expandConventionalPath(LADSPAPlugin, "LADSPA_PATH" + variableSuffix),
Chris@34 65 "ladspa_descriptor"
Chris@34 66 };
Chris@34 67
Chris@34 68 m_known[DSSIPlugin] = {
Chris@34 69 "dssi",
Chris@34 70 "DSSI_PATH" + variableSuffix,
Chris@34 71 expandConventionalPath(DSSIPlugin, "DSSI_PATH" + variableSuffix),
Chris@34 72 "dssi_descriptor"
Chris@4 73 };
Chris@4 74
Chris@4 75 for (const auto &k: m_known) {
Chris@19 76 m_candidates.scan(k.second.tag, k.second.path, k.second.descriptor);
Chris@4 77 }
Chris@4 78 }
Chris@4 79
Chris@34 80 std::vector<KnownPlugins::PluginType>
Chris@34 81 KnownPlugins::getKnownPluginTypes() const
Chris@34 82 {
Chris@34 83 std::vector<PluginType> kt;
Chris@34 84
Chris@34 85 for (const auto &k: m_known) {
Chris@34 86 kt.push_back(k.first);
Chris@34 87 }
Chris@34 88
Chris@34 89 return kt;
Chris@34 90 }
Chris@34 91
Chris@20 92 bool
Chris@20 93 KnownPlugins::is32bit() const
Chris@20 94 {
Chris@20 95 return m_helperExecutableName.find("-32") != std::string::npos;
Chris@20 96 }
Chris@20 97
Chris@4 98 string
Chris@4 99 KnownPlugins::getDefaultPath(PluginType type)
Chris@4 100 {
Chris@4 101 switch (type) {
Chris@4 102
Chris@4 103 #if defined(_WIN32)
Chris@4 104
Chris@4 105 case VampPlugin:
Chris@19 106 return "%ProgramFiles%\\Vamp Plugins";
Chris@4 107 case LADSPAPlugin:
Chris@19 108 return "%ProgramFiles%\\LADSPA Plugins;%ProgramFiles%\\Audacity\\Plug-Ins";
Chris@4 109 case DSSIPlugin:
Chris@19 110 return "%ProgramFiles%\\DSSI Plugins";
Chris@19 111
Chris@4 112 #elif defined(__APPLE__)
Chris@19 113
Chris@4 114 case VampPlugin:
Chris@19 115 return "$HOME/Library/Audio/Plug-Ins/Vamp:/Library/Audio/Plug-Ins/Vamp";
Chris@4 116 case LADSPAPlugin:
Chris@19 117 return "$HOME/Library/Audio/Plug-Ins/LADSPA:/Library/Audio/Plug-Ins/LADSPA";
Chris@4 118 case DSSIPlugin:
Chris@19 119 return "$HOME/Library/Audio/Plug-Ins/DSSI:/Library/Audio/Plug-Ins/DSSI";
Chris@19 120
Chris@4 121 #else /* Linux, BSDs, etc */
Chris@19 122
Chris@4 123 case VampPlugin:
Chris@19 124 return "$HOME/vamp:$HOME/.vamp:/usr/local/lib/vamp:/usr/lib/vamp";
Chris@4 125 case LADSPAPlugin:
Chris@19 126 return "$HOME/ladspa:$HOME/.ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa";
Chris@4 127 case DSSIPlugin:
Chris@19 128 return "$HOME/dssi:$HOME/.dssi:/usr/local/lib/dssi:/usr/lib/dssi";
Chris@4 129 #endif
Chris@4 130 }
Chris@4 131
Chris@4 132 throw logic_error("unknown or unhandled plugin type");
Chris@4 133 }
Chris@4 134
Chris@4 135 vector<string>
Chris@4 136 KnownPlugins::expandConventionalPath(PluginType type, string var)
Chris@4 137 {
Chris@4 138 vector<string> pathList;
Chris@4 139 string path;
Chris@4 140
Chris@4 141 char *cpath = getenv(var.c_str());
Chris@4 142 if (cpath) path = cpath;
Chris@4 143
Chris@4 144 if (path == "") {
Chris@4 145
Chris@4 146 path = getDefaultPath(type);
Chris@4 147
Chris@19 148 if (path != "") {
Chris@4 149
Chris@19 150 char *home = getenv("HOME");
Chris@19 151 if (home) {
Chris@19 152 string::size_type f;
Chris@19 153 while ((f = path.find("$HOME")) != string::npos &&
Chris@19 154 f < path.length()) {
Chris@19 155 path.replace(f, 5, home);
Chris@19 156 }
Chris@19 157 }
Chris@4 158
Chris@4 159 #ifdef _WIN32
Chris@20 160 const char *pfiles = 0;
Chris@34 161 const char *pfiles32 = 0;
Chris@34 162
Chris@34 163 pfiles = getenv("ProgramFiles");
Chris@34 164 if (!pfiles) {
Chris@34 165 pfiles = "C:\\Program Files";
Chris@20 166 }
Chris@34 167
Chris@34 168 pfiles32 = getenv("ProgramFiles(x86)");
Chris@34 169 if (!pfiles32) {
Chris@34 170 pfiles32 = "C:\\Program Files (x86)";
Chris@20 171 }
Chris@34 172
Chris@20 173 string::size_type f;
Chris@20 174 while ((f = path.find("%ProgramFiles%")) != string::npos &&
Chris@20 175 f < path.length()) {
Chris@34 176 if (is32bit()) {
Chris@34 177 path.replace(f, 14, pfiles32);
Chris@34 178 } else {
Chris@34 179 path.replace(f, 14, pfiles);
Chris@34 180 }
Chris@20 181 }
Chris@4 182 #endif
Chris@19 183 }
Chris@4 184 }
Chris@4 185
Chris@4 186 string::size_type index = 0, newindex = 0;
Chris@4 187
Chris@4 188 while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) {
Chris@19 189 pathList.push_back(path.substr(index, newindex - index).c_str());
Chris@19 190 index = newindex + 1;
Chris@4 191 }
Chris@4 192
Chris@4 193 pathList.push_back(path.substr(index));
Chris@4 194
Chris@4 195 return pathList;
Chris@4 196 }
Chris@4 197
Chris@4 198 string
Chris@4 199 KnownPlugins::getFailureReport() const
Chris@4 200 {
Chris@4 201 vector<PluginCandidates::FailureRec> failures;
Chris@4 202
Chris@4 203 for (auto t: getKnownPluginTypes()) {
Chris@19 204 auto ff = m_candidates.getFailedLibrariesFor(getTagFor(t));
Chris@19 205 failures.insert(failures.end(), ff.begin(), ff.end());
Chris@4 206 }
Chris@4 207
Chris@4 208 if (failures.empty()) return "";
Chris@4 209
Chris@15 210 int n = int(failures.size());
Chris@4 211 int i = 0;
Chris@4 212
Chris@4 213 ostringstream os;
Chris@4 214
Chris@4 215 os << "<ul>";
Chris@4 216 for (auto f: failures) {
Chris@19 217 os << "<li>" + f.library;
Chris@19 218 if (f.message != "") {
Chris@19 219 os << "<br><i>" + f.message + "</i>";
Chris@19 220 } else {
Chris@19 221 os << "<br><i>unknown error</i>";
Chris@19 222 }
Chris@19 223 os << "</li>";
Chris@4 224
Chris@19 225 if (n > 10) {
Chris@19 226 if (++i == 5) {
Chris@19 227 os << "<li>(... and " << (n - i) << " further failures)</li>";
Chris@19 228 break;
Chris@19 229 }
Chris@19 230 }
Chris@4 231 }
Chris@4 232 os << "</ul>";
Chris@4 233
Chris@4 234 return os.str();
Chris@4 235 }