comparison src/main.cpp @ 541:fea109b93831

Fixes to plugin path handling: use application path (even if not default); support wide-char APIs on Windows
author Chris Cannam
date Wed, 13 Feb 2019 10:33:44 +0000
parents 25aa28a27252
children 702a70e48ca9
comparison
equal deleted inserted replaced
540:f55363ecc57d 541:fea109b93831
119 return QApplication::event(event); 119 return QApplication::event(event);
120 } 120 }
121 } 121 }
122 }; 122 };
123 123
124 static QString
125 getEnvQStr(QString variable)
126 {
127 #ifdef Q_OS_WIN32
128 std::wstring wvar = variable.toStdWString();
129 wchar_t *value = _wgetenv(wvar.c_str());
130 if (!value) return QString();
131 else return QString::fromUtf16(value);
132 #else
133 std::string var = variable.toStdString();
134 return QString::fromUtf8(qgetenv(var.c_str()));
135 #endif
136 }
137
138 static void
139 putEnvQStr(QString assignment)
140 {
141 #ifdef Q_OS_WIN32
142 std::wstring wassignment = assignment.toStdWString();
143 _wputenv(wstrdup(wassignment));
144 #else
145 putenv(strdup(assignment.toUtf8().data()));
146 #endif
147 }
148
124 static void 149 static void
125 setupTonyVampPath() 150 setupTonyVampPath()
126 { 151 {
152 QString tonyVampPath = getEnvQStr("TONY_VAMP_PATH");
153
127 #ifdef Q_OS_WIN32 154 #ifdef Q_OS_WIN32
128 QChar sep(';'); 155 QChar sep(';');
129 QString programFiles = getenv("ProgramFiles");
130 if (programFiles == "") programFiles = "C:\\Program Files";
131 QString defaultTonyPath(programFiles + "\\Tony");
132 #else 156 #else
133 QChar sep(':'); 157 QChar sep(':');
134 #ifdef Q_OS_MAC 158 #endif
135 QString defaultTonyPath; 159
136 #else
137 QString defaultTonyPath("/usr/local/lib/tony:/usr/lib/tony");
138 #endif
139 #endif
140
141 QString tonyVampPath = getenv("TONY_VAMP_PATH");
142 if (tonyVampPath == "") { 160 if (tonyVampPath == "") {
143 tonyVampPath = defaultTonyPath; 161 tonyVampPath = QApplication::applicationDirPath();
144 } 162
145 if (tonyVampPath == "") { 163 #ifdef Q_OS_WIN32
146 // just use the default Vamp path or VAMP_PATH environment 164 QString programFiles = getEnvQStr("ProgramFiles");
147 // variable -- leave it up to the Vamp SDK 165 if (programFiles == "") programFiles = "C:\\Program Files";
148 return; 166 QString defaultTonyPath(programFiles + "\\Tony");
167 tonyVampPath = tonyVampPath + sep + defaultTonyPath;
168 #endif
169
170 #ifndef Q_OS_MAC
171 QString defaultTonyPath("/usr/local/lib/tony:/usr/lib/tony");
172 tonyVampPath = tonyVampPath + sep + defaultTonyPath;
173 #endif
149 } 174 }
150 175
151 std::vector<std::string> vampPathList = 176 std::vector<std::string> vampPathList =
152 Vamp::PluginHostAdapter::getPluginPath(); 177 Vamp::PluginHostAdapter::getPluginPath();
153 178
154 QStringList qVampPathList; 179 for (auto p: vampPathList) {
155 for (auto p: vampPathList) qVampPathList.push_back(p.c_str()); 180 tonyVampPath = tonyVampPath + sep + QString::fromUtf8(p.c_str());
156 QString vampPath = qVampPathList.join(sep); 181 }
157 QString newPath = tonyVampPath + sep + vampPath; 182
158 183 SVCERR << "Setting VAMP_PATH to " << tonyVampPath
159 cerr << "Setting VAMP_PATH to " << newPath << " for Tony plugins" << endl; 184 << " for Tony plugins" << endl;
160 185
161 QString env = "VAMP_PATH=" + newPath; 186 QString env = "VAMP_PATH=" + tonyVampPath;
162 187
163 // Windows lacks setenv, must use putenv (different arg convention) 188 // Windows lacks setenv, must use putenv (different arg convention)
164 putenv(strdup(env.toLocal8Bit().data())); 189 putEnvQStr(env);
165 } 190 }
166 191
167 int 192 int
168 main(int argc, char **argv) 193 main(int argc, char **argv)
169 { 194 {
174 // Fix for OS/X 10.9 font problem 199 // Fix for OS/X 10.9 font problem
175 QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); 200 QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
176 } 201 }
177 #endif 202 #endif
178 203
204 TonyApplication application(argc, argv);
205
179 setupTonyVampPath(); 206 setupTonyVampPath();
180
181 TonyApplication application(argc, argv);
182 207
183 QStringList args = application.arguments(); 208 QStringList args = application.arguments();
184 209
185 signal(SIGINT, signalHandler); 210 signal(SIGINT, signalHandler);
186 signal(SIGTERM, signalHandler); 211 signal(SIGTERM, signalHandler);