Chris@1472
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1472
|
2
|
Chris@1472
|
3 /*
|
Chris@1472
|
4 Sonic Visualiser
|
Chris@1472
|
5 An audio file viewer and annotation editor.
|
Chris@1472
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1472
|
7
|
Chris@1472
|
8 This program is free software; you can redistribute it and/or
|
Chris@1472
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1472
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1472
|
11 License, or (at your option) any later version. See the file
|
Chris@1472
|
12 COPYING included with this distribution for more information.
|
Chris@1472
|
13 */
|
Chris@1472
|
14
|
Chris@1472
|
15 #include "PluginPathSetter.h"
|
Chris@1472
|
16
|
Chris@1472
|
17 #include <vamp-hostsdk/PluginHostAdapter.h>
|
Chris@1472
|
18
|
Chris@1472
|
19 #include "RealTimePluginFactory.h"
|
Chris@1472
|
20 #include "LADSPAPluginFactory.h"
|
Chris@1472
|
21 #include "DSSIPluginFactory.h"
|
Chris@1472
|
22
|
Chris@1472
|
23 #include <QSettings>
|
Chris@1472
|
24 #include <QMutexLocker>
|
Chris@1472
|
25
|
Chris@1472
|
26 QMutex
|
Chris@1472
|
27 PluginPathSetter::m_mutex;
|
Chris@1472
|
28
|
Chris@1472
|
29 PluginPathSetter::Paths
|
Chris@1472
|
30 PluginPathSetter::m_defaultPaths;
|
Chris@1472
|
31
|
Chris@1472
|
32 PluginPathSetter::Paths
|
Chris@1472
|
33 PluginPathSetter::getDefaultPaths()
|
Chris@1472
|
34 {
|
Chris@1472
|
35 QMutexLocker locker(&m_mutex);
|
Chris@1472
|
36
|
Chris@1472
|
37 if (!m_defaultPaths.empty()) {
|
Chris@1472
|
38 return m_defaultPaths;
|
Chris@1472
|
39 }
|
Chris@1472
|
40
|
Chris@1472
|
41 Paths paths;
|
Chris@1472
|
42
|
Chris@1472
|
43 auto vampPath = Vamp::PluginHostAdapter::getPluginPath();
|
Chris@1472
|
44
|
Chris@1472
|
45 QStringList qVampPath;
|
Chris@1472
|
46 for (auto s: vampPath) {
|
Chris@1472
|
47 qVampPath.push_back(QString::fromStdString(s));
|
Chris@1472
|
48 }
|
Chris@1472
|
49 paths["Vamp"] = { qVampPath, "VAMP_PATH", true };
|
Chris@1472
|
50
|
Chris@1472
|
51 auto dssiPath = DSSIPluginFactory::getPluginPath();
|
Chris@1472
|
52
|
Chris@1472
|
53 QStringList qDssiPath;
|
Chris@1472
|
54 for (auto s: dssiPath) {
|
Chris@1472
|
55 qDssiPath.push_back(s);
|
Chris@1472
|
56 }
|
Chris@1472
|
57 paths["DSSI"] = { qDssiPath, "DSSI_PATH", true };
|
Chris@1472
|
58
|
Chris@1472
|
59 auto ladspaPath = LADSPAPluginFactory::getPluginPath();
|
Chris@1472
|
60
|
Chris@1472
|
61 QStringList qLadspaPath;
|
Chris@1472
|
62 for (auto s: ladspaPath) {
|
Chris@1472
|
63 qLadspaPath.push_back(s);
|
Chris@1472
|
64 }
|
Chris@1472
|
65 paths["LADSPA"] = { qLadspaPath, "LADSPA_PATH", true };
|
Chris@1472
|
66
|
Chris@1472
|
67 m_defaultPaths = paths;
|
Chris@1472
|
68 return m_defaultPaths;
|
Chris@1472
|
69 }
|
Chris@1472
|
70
|
Chris@1472
|
71 PluginPathSetter::Paths
|
Chris@1472
|
72 PluginPathSetter::getPaths()
|
Chris@1472
|
73 {
|
Chris@1472
|
74 Paths paths = getDefaultPaths();
|
Chris@1472
|
75
|
Chris@1472
|
76 QSettings settings;
|
Chris@1472
|
77 settings.beginGroup("Plugins");
|
Chris@1472
|
78
|
Chris@1472
|
79 for (auto p: paths) {
|
Chris@1472
|
80
|
Chris@1472
|
81 QString tag = p.first;
|
Chris@1472
|
82
|
Chris@1472
|
83 QStringList directories =
|
Chris@1472
|
84 settings.value(QString("directories-%1").arg(tag),
|
Chris@1472
|
85 p.second.directories)
|
Chris@1472
|
86 .toStringList();
|
Chris@1472
|
87 QString envVariable =
|
Chris@1472
|
88 settings.value(QString("env-variable-%1").arg(tag),
|
Chris@1472
|
89 p.second.envVariable)
|
Chris@1472
|
90 .toString();
|
Chris@1472
|
91 bool useEnvVariable =
|
Chris@1472
|
92 settings.value(QString("use-env-variable-%1").arg(tag),
|
Chris@1472
|
93 p.second.useEnvVariable)
|
Chris@1472
|
94 .toBool();
|
Chris@1472
|
95 std::string envVarStr = envVariable.toStdString();
|
Chris@1472
|
96
|
Chris@1472
|
97 QString currentValue = qEnvironmentVariable(envVarStr.c_str());
|
Chris@1472
|
98 if (currentValue != QString() && useEnvVariable) {
|
Chris@1472
|
99 directories = currentValue.split(
|
Chris@1472
|
100 #ifdef Q_OS_WIN
|
Chris@1472
|
101 ";"
|
Chris@1472
|
102 #else
|
Chris@1472
|
103 ":"
|
Chris@1472
|
104 #endif
|
Chris@1472
|
105 );
|
Chris@1472
|
106 }
|
Chris@1472
|
107
|
Chris@1472
|
108 paths[tag] = { directories, envVariable, useEnvVariable };
|
Chris@1472
|
109 }
|
Chris@1472
|
110
|
Chris@1472
|
111 settings.endGroup();
|
Chris@1472
|
112
|
Chris@1472
|
113 return paths;
|
Chris@1472
|
114 }
|
Chris@1472
|
115
|
Chris@1472
|
116 void
|
Chris@1472
|
117 PluginPathSetter::savePathSettings(Paths paths)
|
Chris@1472
|
118 {
|
Chris@1472
|
119 QSettings settings;
|
Chris@1472
|
120 settings.beginGroup("Plugins");
|
Chris@1472
|
121
|
Chris@1472
|
122 for (auto p: paths) {
|
Chris@1472
|
123 QString tag = p.first;
|
Chris@1472
|
124 settings.setValue(QString("directories-%1").arg(tag),
|
Chris@1472
|
125 p.second.directories);
|
Chris@1472
|
126 settings.setValue(QString("env-variable-%1").arg(tag),
|
Chris@1472
|
127 p.second.envVariable);
|
Chris@1472
|
128 settings.setValue(QString("use-env-variable-%1").arg(tag),
|
Chris@1472
|
129 p.second.useEnvVariable);
|
Chris@1472
|
130 }
|
Chris@1472
|
131
|
Chris@1472
|
132 settings.endGroup();
|
Chris@1472
|
133 }
|
Chris@1472
|
134
|
Chris@1472
|
135 void
|
Chris@1472
|
136 PluginPathSetter::setEnvironmentVariables()
|
Chris@1472
|
137 {
|
Chris@1472
|
138 // Set the relevant environment variables from user configuration,
|
Chris@1472
|
139 // so that later lookups through the standard APIs will follow the
|
Chris@1472
|
140 // same paths as we have in the user config
|
Chris@1472
|
141
|
Chris@1472
|
142 // First ensure the default paths have been recorded for later, so
|
Chris@1472
|
143 // we don't erroneously re-read them from the environment
|
Chris@1472
|
144 // variables we've just set
|
Chris@1472
|
145 (void)getDefaultPaths();
|
Chris@1472
|
146
|
Chris@1472
|
147 Paths paths = getPaths();
|
Chris@1472
|
148
|
Chris@1472
|
149 for (auto p: paths) {
|
Chris@1472
|
150 QString envVariable = p.second.envVariable;
|
Chris@1472
|
151 std::string envVarStr = envVariable.toStdString();
|
Chris@1472
|
152 QString currentValue = qEnvironmentVariable(envVarStr.c_str());
|
Chris@1472
|
153 if (currentValue != QString() && p.second.useEnvVariable) {
|
Chris@1472
|
154 // don't override
|
Chris@1472
|
155 continue;
|
Chris@1472
|
156 }
|
Chris@1472
|
157 QString separator =
|
Chris@1472
|
158 #ifdef Q_OS_WIN
|
Chris@1472
|
159 ";"
|
Chris@1472
|
160 #else
|
Chris@1472
|
161 ":"
|
Chris@1472
|
162 #endif
|
Chris@1472
|
163 ;
|
Chris@1472
|
164 QString proposedValue = p.second.directories.join(separator);
|
Chris@1472
|
165 qputenv(envVarStr.c_str(), proposedValue.toUtf8());
|
Chris@1472
|
166 }
|
Chris@1472
|
167 }
|
Chris@1472
|
168
|