Optimize automation-event process splitting
[ardour.git] / libs / ardour / template_utils.cc
index f5a4dc78a6bcd1384666f774408da68e3d192a6b..4b8d5b2b7816b12f2e0f75ad11045ef1a9e3abc1 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Paul Davis 
+    Copyright (C) 2012 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -22,7 +22,6 @@
 
 #include <glibmm.h>
 
-#include "pbd/basename.h"
 #include "pbd/file_utils.h"
 #include "pbd/stl_delete.h"
 #include "pbd/xml++.h"
@@ -34,6 +33,8 @@
 #include "ardour/search_paths.h"
 #include "ardour/io.h"
 
+#include "pbd/i18n.h"
+
 using namespace std;
 using namespace PBD;
 
@@ -57,7 +58,7 @@ template_filter (const string &str, void* /*arg*/)
        if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) {
                return false;
        }
-       
+
        return true;
 }
 
@@ -67,7 +68,7 @@ route_template_filter (const string &str, void* /*arg*/)
        if (str.find (template_suffix) == str.length() - strlen (template_suffix)) {
                return true;
        }
-       
+
        return false;
 }
 
@@ -79,11 +80,11 @@ session_template_dir_to_file (string const & dir)
 
 
 void
-find_session_templates (vector<TemplateInfo>& template_names)
+find_session_templates (vector<TemplateInfo>& template_names, bool read_xml)
 {
        vector<string> templates;
 
-       find_files_matching_filter (templates, template_search_path(), template_filter, 0, true, true);
+       find_paths_matching_filter (templates, template_search_path(), template_filter, 0, true, true);
 
        if (templates.empty()) {
                cerr << "Found nothing along " << template_search_path().to_string() << endl;
@@ -95,19 +96,42 @@ find_session_templates (vector<TemplateInfo>& template_names)
        for (vector<string>::iterator i = templates.begin(); i != templates.end(); ++i) {
                string file = session_template_dir_to_file (*i);
 
-               XMLTree tree;
-
-               if (!tree.read (file.c_str())) {
-                       continue;
-               }
-
                TemplateInfo rti;
-
-               rti.name = basename_nosuffix (*i);
+               rti.name = Glib::path_get_basename (*i);
                rti.path = *i;
 
+               if (read_xml) {
+
+                       XMLTree tree;
+                       if (!tree.read (file.c_str())) {
+                               cerr << "Failed to parse Route-template XML file: " << file;
+                               continue;
+                       }
+
+                       XMLNode* root = tree.root();
+                       
+                       rti.modified_with = _("(unknown)");
+                       try {
+                               XMLNode *pv = root->child("ProgramVersion");
+                               string modified_with;
+                               if (pv != 0) {
+                                       pv->get_property (X_("modified-with"), modified_with);
+                               }
+                               rti.modified_with = modified_with;
+                       } catch (XMLException &e) {}
+
+                       rti.description = _("No Description");
+                       try {
+                               XMLNode *desc = root->child("description");
+                               if (desc != 0) {
+                                       rti.description = desc->attribute_value();
+                               }
+                       } catch (XMLException &e) {}
+               }
+
                template_names.push_back (rti);
        }
+       std::sort(template_names.begin(), template_names.end());
 }
 
 void
@@ -127,6 +151,7 @@ find_route_templates (vector<TemplateInfo>& template_names)
                XMLTree tree;
 
                if (!tree.read (fullpath.c_str())) {
+                       cerr << "Failed to parse Route-template XML file: " << fullpath;
                        continue;
                }
 
@@ -134,6 +159,24 @@ find_route_templates (vector<TemplateInfo>& template_names)
 
                TemplateInfo rti;
 
+               rti.modified_with = _("(unknown)");
+               try {
+                       XMLNode *pv = root->child("ProgramVersion");
+                       string modified_with;
+                       if (pv != 0) {
+                               pv->get_property (X_("modified-with"), modified_with);
+                       }
+                       rti.modified_with = modified_with;
+               } catch (XMLException &e) {}
+
+               rti.description = _("No Description");
+               try {
+                       XMLNode *desc = root->child("description");
+                       if (desc != 0) {
+                               rti.description = desc->attribute_value();
+                       }
+               } catch (XMLException &e) {}
+
                rti.name = IO::name_from_state (*root->children().front());
                rti.path = fullpath;