ardour
search_paths.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Tim Mayberry
3  Copyright (C) 2013 Paul Davis
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19 */
20 
21 #include <glib.h>
22 #include <glibmm.h>
23 #include <string.h>
24 
25 #include "pbd/pathexpand.h"
26 
27 #include "ardour/search_paths.h"
28 #include "ardour/directory_names.h"
30 
31 #ifdef PLATFORM_WINDOWS
32 #include <windows.h>
33 #include <shlobj.h> // CSIDL_*
35 #endif
36 
37 namespace {
38  const char * const backend_env_variable_name = "ARDOUR_BACKEND_PATH";
39  const char * const surfaces_env_variable_name = "ARDOUR_SURFACES_PATH";
40  const char * const export_env_variable_name = "ARDOUR_EXPORT_FORMATS_PATH";
41  const char * const ladspa_env_variable_name = "LADSPA_PATH";
42  const char * const midi_patch_env_variable_name = "ARDOUR_MIDI_PATCH_PATH";
43  const char * const panner_env_variable_name = "ARDOUR_PANNER_PATH";
44 } // anonymous
45 
46 using namespace PBD;
47 
48 namespace ARDOUR {
49 
52 {
54  spath += ardour_dll_directory ();
56 
57  spath += Searchpath(Glib::getenv(backend_env_variable_name));
58  return spath;
59 }
60 
63 {
65  spath += ardour_dll_directory ();
67 
68  spath += Searchpath(Glib::getenv(surfaces_env_variable_name));
69  return spath;
70 }
71 
74 {
77 
78  bool export_formats_path_defined = false;
79  Searchpath spath_env (Glib::getenv(export_env_variable_name, export_formats_path_defined));
80 
81  if (export_formats_path_defined) {
82  spath += spath_env;
83  }
84 
85  return spath;
86 }
87 
90 {
91  Searchpath spath_env (Glib::getenv(ladspa_env_variable_name));
92 
94 
95  spath += ardour_dll_directory ();
97 
98 #ifndef PLATFORM_WINDOWS
99  spath.push_back ("/usr/local/lib64/ladspa");
100  spath.push_back ("/usr/local/lib/ladspa");
101  spath.push_back ("/usr/lib64/ladspa");
102  spath.push_back ("/usr/lib/ladspa");
103 #endif
104 
105 #ifdef __APPLE__
106  spath.push_back (path_expand ("~/Library/Audio/Plug-Ins/LADSPA"));
107  spath.push_back ("/Library/Audio/Plug-Ins/LADSPA");
108 #endif
109 
110  return spath_env + spath;
111 }
112 
115 {
116  Searchpath spath( ardour_dll_directory () );
117  spath.add_subdirectory_to_paths ("LV2");
118 
119  return spath;
120 }
121 
124 {
127 
128  bool midi_patch_path_defined = false;
129  Searchpath spath_env (Glib::getenv(midi_patch_env_variable_name, midi_patch_path_defined));
130 
131  if (midi_patch_path_defined) {
132  spath += spath_env;
133  }
134 
135  return spath;
136 }
137 
140 {
142 
143  spath += ardour_dll_directory ();
145  spath += Searchpath(Glib::getenv(panner_env_variable_name));
146 
147  return spath;
148 }
149 
152 {
155  return spath;
156 }
157 
160 {
163  return spath;
164 }
165 
166 #ifdef PLATFORM_WINDOWS
167 
168 const char*
170 {
171  DWORD dwType = REG_SZ;
172  HKEY hKey;
173  DWORD dwSize = PATH_MAX;
174  char* p = 0;
175  char* user_home = 0;
176  char tmp[PATH_MAX+1];
177 
178  if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_CURRENT_USER, "Software\\VST", 0, KEY_READ, &hKey)) {
179  // Look for the user's VST Registry entry
180  if (ERROR_SUCCESS == RegQueryValueExA (hKey, "VSTPluginsPath", 0, &dwType, (LPBYTE)tmp, &dwSize))
181  p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), NULL);
182 
183  RegCloseKey (hKey);
184  }
185 
186  if (p == 0) {
187  if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\VST", 0, KEY_READ, &hKey))
188  {
189  // Look for a global VST Registry entry
190  if (ERROR_SUCCESS == RegQueryValueExA (hKey, "VSTPluginsPath", 0, &dwType, (LPBYTE)tmp, &dwSize))
191  p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), NULL);
192 
193  RegCloseKey (hKey);
194  }
195  }
196 
197  if (p == 0) {
198  char *pVSTx86 = 0;
199  char *pProgFilesX86 = PBD::get_win_special_folder (CSIDL_PROGRAM_FILESX86);
200 
201  if (pProgFilesX86) {
202  // Look for a VST folder under C:\Program Files (x86)
203  if ((pVSTx86 = g_build_filename (pProgFilesX86, "Steinberg", "VSTPlugins", NULL)))
204  {
205  if (Glib::file_test (pVSTx86, Glib::FILE_TEST_EXISTS))
206  if (Glib::file_test (pVSTx86, Glib::FILE_TEST_IS_DIR))
207  p = g_build_filename (pVSTx86, NULL);
208 
209  g_free (pVSTx86);
210  }
211 
212  g_free (pProgFilesX86);
213  }
214 
215  if (p == 0) {
216  // Look for a VST folder under C:\Program Files
217  char *pVST = 0;
218  char *pProgFiles = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
219 
220  if (pProgFiles) {
221  if ((pVST = g_build_filename (pProgFiles, "Steinberg", "VSTPlugins", NULL))) {
222  if (Glib::file_test (pVST, Glib::FILE_TEST_EXISTS))
223  if (Glib::file_test (pVST, Glib::FILE_TEST_IS_DIR))
224  p = g_build_filename (pVST, NULL);
225 
226  g_free (pVST);
227  }
228 
229  g_free (pProgFiles);
230  }
231  }
232  }
233 
234  if (p == 0) {
235  // If all else failed, assume the plugins are under "My Documents"
236  user_home = (char*) g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
237  if (user_home) {
238  p = g_build_filename (user_home, "Plugins", "VST", NULL);
239  } else {
240  user_home = g_build_filename(g_get_home_dir(), "My Documents", NULL);
241  if (user_home)
242  p = g_build_filename (user_home, "Plugins", "VST", NULL);
243  }
244  } else {
245  // Concatenate the registry path with the user's personal path
246  user_home = (char*) g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
247 
248  if (user_home) {
249  p = g_build_path (";", p, g_build_filename(user_home, "Plugins", "VST", NULL), NULL);
250  } else {
251  user_home = g_build_filename(g_get_home_dir(), "My Documents", NULL);
252 
253  if (user_home) {
254  p = g_build_path (";", p, g_build_filename (user_home, "Plugins", "VST", NULL), NULL);
255  }
256  }
257  }
258 
259  return p;
260 }
261 
262 #else
263 
264 /* Unix-like. Probably require some OS X specific breakdown if we ever add VST
265  * support on that platform.
266  */
267 
268 const char *
270 {
271  return "/usr/local/lib/vst:/usr/lib/vst";
272 }
273 
274 #endif // PLATFORM_WINDOWS
275 
276 } // namespace ARDOUR
LIBPBD_API std::string path_expand(std::string path)
LIBARDOUR_API const char *const export_formats_dir_name
LIBARDOUR_API PBD::Searchpath ladspa_search_path()
Definition: search_paths.cc:89
LIBARDOUR_API const char *const midi_patch_dir_name
LIBARDOUR_API const char *const backend_dir_name
LIBARDOUR_API PBD::Searchpath midi_patch_search_path()
LIBARDOUR_API const char *const panner_dir_name
LIBARDOUR_API PBD::Searchpath panner_search_path()
LIBPBD_API char * get_win_special_folder(int csidl)
LIBARDOUR_API const char *const route_templates_dir_name
LIBARDOUR_API const char *const surfaces_dir_name
LIBPBD_TEMPLATE_MEMBER_API Searchpath & add_subdirectory_to_paths(const std::string &subdir)
Definition: search_path.cc:158
LIBARDOUR_API const char * vst_search_path()
LIBARDOUR_API PBD::Searchpath template_search_path()
LIBARDOUR_API std::string user_config_directory(int version=-1)
#define PATH_MAX
Definition: lv2_plugin.h:34
LIBARDOUR_API PBD::Searchpath control_protocol_search_path()
Definition: search_paths.cc:62
LIBARDOUR_API const char *const ladspa_dir_name
Definition: amp.h:29
LIBARDOUR_API PBD::Searchpath backend_search_path()
Definition: search_paths.cc:51
LIBARDOUR_API std::string ardour_dll_directory()
LIBARDOUR_API PBD::Searchpath export_formats_search_path()
Definition: search_paths.cc:73
LIBARDOUR_API const char *const templates_dir_name
Definition: debug.h:30
LIBARDOUR_API PBD::Searchpath ardour_data_search_path()
LIBARDOUR_API PBD::Searchpath route_template_search_path()
LIBARDOUR_API PBD::Searchpath lv2_bundled_search_path()