remove unneeded code in line_drag that was probably copy/pasted from control_point_dr...
[ardour.git] / libs / ardour / template_utils.cc
1 #include <algorithm>
2 #include <cstring>
3
4 #include "pbd/filesystem.h"
5 #include "pbd/pathscanner.h"
6 #include "pbd/xml++.h"
7
8 #include "ardour/template_utils.h"
9 #include "ardour/directory_names.h"
10 #include "ardour/filesystem_paths.h"
11 #include "ardour/filename_extensions.h"
12 #include "ardour/io.h"
13
14 namespace ARDOUR {
15
16 sys::path
17 system_template_directory ()
18 {
19         SearchPath spath(system_data_search_path());
20         spath.add_subdirectory_to_paths(templates_dir_name);
21
22         // just return the first directory in the search path that exists
23         SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
24
25         if (i == spath.end()) return sys::path();
26
27         return *i;
28 }
29
30 sys::path
31 system_route_template_directory ()
32 {
33         SearchPath spath(system_data_search_path());
34         spath.add_subdirectory_to_paths(route_templates_dir_name);
35
36         // just return the first directory in the search path that exists
37         SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
38
39         if (i == spath.end()) return sys::path();
40
41         return *i;
42 }
43
44 sys::path
45 user_template_directory ()
46 {
47         sys::path p(user_config_directory());
48         p /= templates_dir_name;
49
50         return p;
51 }
52
53 sys::path
54 user_route_template_directory ()
55 {
56         sys::path p(user_config_directory());
57         p /= route_templates_dir_name;
58
59         return p;
60 }
61
62 static bool
63 template_filter (const string &str, void *arg)
64 {
65         return (str.length() > strlen(temp_suffix) &&
66                 str.find (temp_suffix) == (str.length() - strlen (temp_suffix)));
67 }
68
69 void
70 find_route_templates (vector<RouteTemplateInfo>& template_names)
71 {
72         vector<string *> *templates;
73         PathScanner scanner;
74         SearchPath spath (system_data_search_path());
75
76         spath += user_config_directory();
77         spath.add_subdirectory_to_paths(route_templates_dir_name);
78
79         templates = scanner (spath.to_string(), template_filter, 0, false, true);
80         
81         if (!templates) {
82                 return;
83         }
84         
85         for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
86                 string fullpath = *(*i);
87
88                 XMLTree tree;
89
90                 if (!tree.read (fullpath.c_str())) {
91                         continue;
92                 }
93
94                 XMLNode* root = tree.root();
95                 
96                 RouteTemplateInfo rti;
97
98                 rti.name = IO::name_from_state (*root->children().front());
99                 rti.path = fullpath;
100
101                 template_names.push_back (rti);
102         }
103
104         free (templates);
105 }
106
107 } // namespace ARDOUR