6 #include "pbd/filesystem.h"
7 #include "pbd/basename.h"
8 #include "pbd/pathscanner.h"
11 #include "ardour/template_utils.h"
12 #include "ardour/directory_names.h"
13 #include "ardour/filesystem_paths.h"
14 #include "ardour/filename_extensions.h"
15 #include "ardour/io.h"
23 template_search_path ()
25 SearchPath spath (ardour_data_search_path());
26 spath.add_subdirectory_to_paths(templates_dir_name);
31 route_template_search_path ()
33 SearchPath spath (ardour_data_search_path());
34 spath.add_subdirectory_to_paths(route_templates_dir_name);
39 user_template_directory ()
41 sys::path p(user_config_directory());
42 p /= templates_dir_name;
48 user_route_template_directory ()
50 sys::path p(user_config_directory());
51 p /= route_templates_dir_name;
57 template_filter (const string &str, void */*arg*/)
59 if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) {
67 route_template_filter (const string &str, void */*arg*/)
69 if (str.find (template_suffix) == str.length() - strlen (template_suffix)) {
77 session_template_dir_to_file (string const & dir)
79 sys::path dir_path = dir;
80 sys::path file_path = dir;
81 file_path /= dir_path.leaf() + template_suffix;
82 return file_path.to_string ();
87 find_session_templates (vector<TemplateInfo>& template_names)
89 vector<string *> *templates;
91 SearchPath spath (template_search_path());
93 templates = scanner (spath.to_string(), template_filter, 0, true, true);
96 cerr << "Found nothing along " << spath.to_string() << endl;
100 cerr << "Found " << templates->size() << " along " << spath.to_string() << endl;
102 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
103 string file = session_template_dir_to_file (**i);
107 if (!tree.read (file.c_str())) {
113 rti.name = basename_nosuffix (**i);
116 template_names.push_back (rti);
123 find_route_templates (vector<TemplateInfo>& template_names)
125 vector<string *> *templates;
127 SearchPath spath (route_template_search_path());
129 templates = scanner (spath.to_string(), route_template_filter, 0, false, true);
135 for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
136 string fullpath = *(*i);
140 if (!tree.read (fullpath.c_str())) {
144 XMLNode* root = tree.root();
148 rti.name = IO::name_from_state (*root->children().front());
151 template_names.push_back (rti);