summaryrefslogtreecommitdiff
path: root/libs/ardour/search_paths.cc
blob: 80f8d86a424ec3000243f1cd764955298fcadc8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
 * Copyright (C) 2014-2018 Robin Gareus <robin@gareus.org>
 * Copyright (C) 2014 John Emmas <john@creativepost.co.uk>
 * Copyright (C) 2015-2016 Paul Davis <paul@linuxaudiosystems.com>
 * Copyright (C) 2016 Ben Loftis <ben@harrisonconsoles.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <glib.h>
#include <glibmm.h>
#include <string.h>

#include "pbd/pathexpand.h"

#include "ardour/search_paths.h"
#include "ardour/directory_names.h"
#include "ardour/filesystem_paths.h"

#ifdef PLATFORM_WINDOWS
#include <windows.h>
#include <shlobj.h> // CSIDL_*
#include "pbd/windows_special_dirs.h"
#endif

namespace {
	const char * const backend_env_variable_name = "ARDOUR_BACKEND_PATH";
	const char * const surfaces_env_variable_name = "ARDOUR_SURFACES_PATH";
	const char * const export_env_variable_name = "ARDOUR_EXPORT_FORMATS_PATH";
	const char * const theme_env_variable_name = "ARDOUR_THEMES_PATH";
	const char * const ladspa_env_variable_name = "LADSPA_PATH";
	const char * const midi_patch_env_variable_name = "ARDOUR_MIDI_PATCH_PATH";
	const char * const panner_env_variable_name = "ARDOUR_PANNER_PATH";
} // anonymous

using namespace PBD;

namespace ARDOUR {

Searchpath
backend_search_path ()
{
	Searchpath spath(user_config_directory ());
	spath += ardour_dll_directory ();
	spath.add_subdirectory_to_paths(backend_dir_name);

	spath += Searchpath(Glib::getenv(backend_env_variable_name));
	return spath;
}

Searchpath
control_protocol_search_path ()
{
	Searchpath spath(user_config_directory ());
	spath += ardour_dll_directory ();
	spath.add_subdirectory_to_paths (surfaces_dir_name);

	spath += Searchpath(Glib::getenv(surfaces_env_variable_name));
	return spath;
}

Searchpath
theme_search_path ()
{
	Searchpath spath (ardour_data_search_path ());
	spath.add_subdirectory_to_paths (theme_dir_name);

	spath += Searchpath(Glib::getenv(theme_env_variable_name));
	return spath;
}

Searchpath
export_formats_search_path ()
{
	Searchpath spath (ardour_data_search_path());
	spath.add_subdirectory_to_paths (export_formats_dir_name);

	bool export_formats_path_defined = false;
	Searchpath spath_env (Glib::getenv(export_env_variable_name, export_formats_path_defined));

	if (export_formats_path_defined) {
		spath += spath_env;
	}

	return spath;
}

Searchpath
ladspa_search_path ()
{
	Searchpath spath_env (Glib::getenv(ladspa_env_variable_name));

	Searchpath spath (user_config_directory ());

	spath += ardour_dll_directory ();
	spath.add_subdirectory_to_paths (ladspa_dir_name);

#ifndef PLATFORM_WINDOWS
	spath.push_back ("/usr/local/lib64/ladspa");
	spath.push_back ("/usr/local/lib/ladspa");
	spath.push_back ("/usr/lib64/ladspa");
	spath.push_back ("/usr/lib/ladspa");
#endif

#ifdef __APPLE__
	spath.push_back (path_expand ("~/Library/Audio/Plug-Ins/LADSPA"));
	spath.push_back ("/Library/Audio/Plug-Ins/LADSPA");
#endif

	return spath_env + spath;
}

Searchpath
lv2_bundled_search_path ()
{
	Searchpath spath( ardour_dll_directory () );
	spath.add_subdirectory_to_paths ("LV2");

	return spath;
}

Searchpath
midi_patch_search_path ()
{
	Searchpath spath (ardour_data_search_path());
	spath.add_subdirectory_to_paths(midi_patch_dir_name);

	bool midi_patch_path_defined = false;
	Searchpath spath_env (Glib::getenv(midi_patch_env_variable_name, midi_patch_path_defined));

	if (midi_patch_path_defined) {
		spath += spath_env;
	}

	return spath;
}

Searchpath
panner_search_path ()
{
	Searchpath spath(user_config_directory ());

	spath += ardour_dll_directory ();
	spath.add_subdirectory_to_paths(panner_dir_name);
	spath += Searchpath(Glib::getenv(panner_env_variable_name));

	return spath;
}

Searchpath
template_search_path ()
{
	Searchpath spath (ardour_data_search_path());
	spath.add_subdirectory_to_paths(templates_dir_name);
	return spath;
}

Searchpath
plugin_metadata_search_path ()
{
	Searchpath spath (ardour_data_search_path());
	spath.add_subdirectory_to_paths(plugin_metadata_dir_name);
	return spath;
}

Searchpath
route_template_search_path ()
{
	Searchpath spath (ardour_data_search_path());
	spath.add_subdirectory_to_paths(route_templates_dir_name);
	return spath;
}

Searchpath
lua_search_path ()
{
	Searchpath spath (ardour_data_search_path());
	spath.add_subdirectory_to_paths(lua_dir_name);

	return spath;
}

#ifdef PLATFORM_WINDOWS

const char*
vst_search_path ()
{
	DWORD dwType = REG_SZ;
	HKEY hKey;
	DWORD dwSize = PATH_MAX;
	char* p = 0;
	char* user_home = 0;
	char tmp[PATH_MAX+1];

	if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_CURRENT_USER, "Software\\VST", 0, KEY_READ, &hKey)) {
		// Look for the user's VST Registry entry
		if (ERROR_SUCCESS == RegQueryValueExA (hKey, "VSTPluginsPath", 0, &dwType, (LPBYTE)tmp, &dwSize))
			p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), NULL);

		RegCloseKey (hKey);
	}

	if (p == 0) {
		if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\VST", 0, KEY_READ, &hKey))
		{
			// Look for a global VST Registry entry
			if (ERROR_SUCCESS == RegQueryValueExA (hKey, "VSTPluginsPath", 0, &dwType, (LPBYTE)tmp, &dwSize))
				p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), NULL);

			RegCloseKey (hKey);
		}
	}

	if (p == 0) {
#if ( (defined __i386__) || (defined _M_IX86) )
		char *pVSTx86 = 0;
		std::string pProgFilesX86 = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILESX86);

		if (!pProgFilesX86.empty()) {
			// Look for a VST folder under C:\Program Files (x86)
			if ((pVSTx86 = g_build_filename (pProgFilesX86.c_str(), "Steinberg", "VSTPlugins", NULL)))
			{
				if (Glib::file_test (pVSTx86, Glib::FILE_TEST_EXISTS))
					if (Glib::file_test (pVSTx86, Glib::FILE_TEST_IS_DIR))
						p = g_build_filename (pVSTx86, NULL);

				g_free (pVSTx86);
			}
		}
#else
		// Look for a VST folder under C:\Program Files
		char *pVST = 0;
		std::string pProgFiles = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);

		if (!pProgFiles.empty()) {
			if ((pVST = g_build_filename (pProgFiles.c_str(), "Steinberg", "VSTPlugins", NULL))) {
				if (Glib::file_test (pVST, Glib::FILE_TEST_EXISTS))
					if (Glib::file_test (pVST, Glib::FILE_TEST_IS_DIR))
						p = g_build_filename (pVST, NULL);

				g_free (pVST);
			}
		}
#endif
	}

	if (p == 0) {
		// If all else failed, assume the plugins are under "My Documents"
		user_home = (char*) g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
		if (user_home) {
			p = g_build_filename (user_home, "Plugins", "VST", NULL);
		} else {
			user_home = g_build_filename(g_get_home_dir(), "My Documents", NULL);
			if (user_home)
				p = g_build_filename (user_home, "Plugins", "VST", NULL);
		}
	} else {
		// Concatenate the registry path with the user's personal path
		user_home = (char*) g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);

		if (user_home) {
			p = g_build_path (";", p, g_build_filename(user_home, "Plugins", "VST", NULL), NULL);
		} else {
			user_home = g_build_filename(g_get_home_dir(), "My Documents", NULL);

			if (user_home) {
				p = g_build_path (";", p, g_build_filename (user_home, "Plugins", "VST", NULL), NULL);
			}
		}
	}

	return p;
}

#else

/* Unix-like. Probably require some OS X specific breakdown if we ever add VST
 * support on that platform.
 */

const char *
vst_search_path ()
{
	return "/usr/local/lib/vst:/usr/lib/vst";
}

#endif // PLATFORM_WINDOWS

} // namespace ARDOUR