permit different sizes for audio playback & capture buffers
[ardour.git] / libs / ardour / template_utils.cc
index ae7f653fb8abf405c0f222752c08cc6410c0e540..aa0a583af4d982771658c92786720ad4108e2448 100644 (file)
@@ -2,6 +2,7 @@
 #include <cstring>
 
 #include "pbd/filesystem.h"
+#include "pbd/basename.h"
 #include "pbd/pathscanner.h"
 #include "pbd/xml++.h"
 
@@ -11,6 +12,9 @@
 #include "ardour/filename_extensions.h"
 #include "ardour/io.h"
 
+using namespace std;
+using namespace PBD;
+
 namespace ARDOUR {
 
 sys::path
@@ -60,28 +64,64 @@ user_route_template_directory ()
 }
 
 static bool
-template_filter (const string &str, void *arg)
+template_filter (const string &str, void */*arg*/)
 {
-       return (str.length() > strlen(temp_suffix) &&
-               str.find (temp_suffix) == (str.length() - strlen (temp_suffix)));
+       cerr << "Checking into " << str << " using " << template_suffix << endl;
+       return (str.length() > strlen(template_suffix) &&
+               str.find (template_suffix) == (str.length() - strlen (template_suffix)));
 }
 
 void
-find_route_templates (vector<RouteTemplateInfo>& template_names)
+find_session_templates (vector<TemplateInfo>& template_names)
 {
        vector<string *> *templates;
        PathScanner scanner;
-       SearchPath spath (system_data_search_path());
+       SearchPath spath (system_template_directory());
+       spath += user_template_directory ();
 
-       spath += user_config_directory();
-       spath.add_subdirectory_to_paths(route_templates_dir_name);
+       templates = scanner (spath.to_string(), template_filter, 0, false, true);
+
+       if (!templates) {
+               cerr << "Found nothing along " << spath.to_string() << endl;
+               return;
+       }
+
+       cerr << "Found " << templates->size() << " along " << spath.to_string() << endl;
+
+       for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
+               string fullpath = *(*i);
+
+               XMLTree tree;
+
+               if (!tree.read (fullpath.c_str())) {
+                       continue;
+               }
+
+               TemplateInfo rti;
+
+               rti.name = basename_nosuffix (fullpath);
+               rti.path = fullpath;
+
+               template_names.push_back (rti);
+       }
+
+       delete templates;
+}
+
+void
+find_route_templates (vector<TemplateInfo>& template_names)
+{
+       vector<string *> *templates;
+       PathScanner scanner;
+       SearchPath spath (system_route_template_directory());
+       spath += user_route_template_directory ();
 
        templates = scanner (spath.to_string(), template_filter, 0, false, true);
-       
+
        if (!templates) {
                return;
        }
-       
+
        for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
                string fullpath = *(*i);
 
@@ -92,8 +132,8 @@ find_route_templates (vector<RouteTemplateInfo>& template_names)
                }
 
                XMLNode* root = tree.root();
-               
-               RouteTemplateInfo rti;
+
+               TemplateInfo rti;
 
                rti.name = IO::name_from_state (*root->children().front());
                rti.path = fullpath;
@@ -101,7 +141,7 @@ find_route_templates (vector<RouteTemplateInfo>& template_names)
                template_names.push_back (rti);
        }
 
-       free (templates);
+       delete templates;
 }
 
-} // namespace ARDOUR
+}