* radically cleaned up / refactored midi_clock_slave.cc
[ardour.git] / libs / ardour / template_utils.cc
index 18d7f3357066abc8a5d9b629d880309008ef7232..171939dac2ccc4b28e6373f1d95e2388bbde6634 100644 (file)
@@ -1,8 +1,8 @@
+#include <algorithm>
 
 #include <pbd/filesystem.h>
 
 #include <ardour/template_utils.h>
-#include <ardour/ardour.h>
 #include <ardour/directory_names.h>
 #include <ardour/filesystem_paths.h>
 
@@ -11,10 +11,15 @@ namespace ARDOUR {
 sys::path
 system_template_directory ()
 {
-       sys::path p(get_system_data_path());
-       p /= templates_dir_name;
+       SearchPath spath(system_data_search_path());
+       spath.add_subdirectory_to_paths(templates_dir_name);
 
-       return p;
+       // just return the first directory in the search path that exists
+       SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
+
+       if (i == spath.end()) return sys::path();
+
+       return *i;
 }
 
 sys::path