From 9f4c7a9e9edd260a72f040b036982d4c5da89292 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 2 Mar 2009 16:52:40 +0000 Subject: track templates, backported from 2.X git-svn-id: svn://localhost/ardour2/branches/3.0@4713 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/template_utils.cc | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'libs/ardour/template_utils.cc') diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index 7c25b59db8..93bfd46972 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -1,10 +1,15 @@ #include +#include #include "pbd/filesystem.h" +#include "pbd/pathscanner.h" +#include "pbd/xml++.h" #include "ardour/template_utils.h" #include "ardour/directory_names.h" #include "ardour/filesystem_paths.h" +#include "ardour/filename_extensions.h" +#include "ardour/io.h" namespace ARDOUR { @@ -22,6 +27,20 @@ system_template_directory () return *i; } +sys::path +system_route_template_directory () +{ + SearchPath spath(system_data_search_path()); + spath.add_subdirectory_to_paths(route_templates_dir_name); + + // 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 user_template_directory () { @@ -31,4 +50,58 @@ user_template_directory () return p; } +sys::path +user_route_template_directory () +{ + sys::path p(user_config_directory()); + p /= route_templates_dir_name; + + return p; +} + +static bool +template_filter (const string &str, void *arg) +{ + return (str.length() > strlen(temp_suffix) && + str.find (temp_suffix) == (str.length() - strlen (temp_suffix))); +} + +void +find_route_templates (vector& template_names) +{ + vector *templates; + PathScanner scanner; + SearchPath spath (system_data_search_path()); + + 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) { + return; + } + + for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { + string fullpath = *(*i); + + XMLTree tree; + + if (!tree.read (fullpath.c_str())) { + continue; + } + + XMLNode* root = tree.root(); + + RouteTemplateInfo rti; + + rti.name = IO::name_from_state (*root->children().front()); + rti.path = fullpath; + + template_names.push_back (rti); + } + + free (templates); +} + } // namespace ARDOUR -- cgit v1.2.3