diff --git a/libs/ardour/ardour/mixer_snapshot_manager.h b/libs/ardour/ardour/mixer_snapshot_manager.h index cad7439657..396fb12fe3 100644 --- a/libs/ardour/ardour/mixer_snapshot_manager.h +++ b/libs/ardour/ardour/mixer_snapshot_manager.h @@ -21,11 +21,13 @@ #include #include +#include #include #include "ardour/mixer_snapshot.h" #include "ardour/session.h" +#include "ardour/template_utils.h" #include "pbd/signals.h" @@ -42,6 +44,8 @@ public: void create_snapshot(const std::string& label, const std::string& desc, RouteList& rl, bool global); void create_snapshot(const std::string& label, const std::string& desc, const std::string& from_path, bool global); + void find_templates(std::vector&, bool); + bool rename_snapshot(MixerSnapshot*, const std::string&); bool remove_snapshot(MixerSnapshot*); diff --git a/libs/ardour/mixer_snapshot_manager.cc b/libs/ardour/mixer_snapshot_manager.cc index 9dbdba2e98..ffa81d57e0 100644 --- a/libs/ardour/mixer_snapshot_manager.cc +++ b/libs/ardour/mixer_snapshot_manager.cc @@ -16,8 +16,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include - #include #include #include @@ -25,17 +23,17 @@ #include "ardour/directory_names.h" #include "ardour/filename_extensions.h" #include "ardour/filesystem_paths.h" -#include "ardour/mixer_snapshot_manager.h" #include "ardour/mixer_snapshot.h" +#include "ardour/mixer_snapshot_manager.h" #include "ardour/search_paths.h" #include "ardour/session_directory.h" -#include "ardour/template_utils.h" #include "pbd/basename.h" #include "pbd/file_utils.h" #include "pbd/gstdio_compat.h" using namespace ARDOUR; +using namespace PBD; using namespace std; MixerSnapshotManager::MixerSnapshotManager (Session* s) @@ -59,42 +57,62 @@ void MixerSnapshotManager::ensure_snapshot_dir(bool global) } } +void MixerSnapshotManager::find_templates(vector& template_info, bool global) +{ + if(!_session) { + return; + } + + if(!global) { + Searchpath searchpath (_session->session_directory().root_path()); + searchpath.add_subdirectory_to_paths(route_templates_dir_name); + + vector files; + const string pattern = "*" + string(template_suffix); + find_files_matching_pattern(files, searchpath, pattern); + + if(!files.empty()) { + for(vector::const_iterator it = files.begin(); it != files.end(); it++) { + const string path = (*it); + const string name = basename_nosuffix(path); + + MixerSnapshot* snapshot = new MixerSnapshot(_session, path); + const string description = snapshot->get_description(); + const string modified = snapshot->get_last_modified_with(); + + TemplateInfo info {name, path, description, modified}; + template_info.push_back(info); + delete snapshot; + } + } + } else if(global) { + find_route_templates(template_info); + } +} + void MixerSnapshotManager::refresh() { clear(); - vector global_templates; - find_route_templates(global_templates); + vector global_templates, local_templates; + find_templates(global_templates, true); + find_templates(local_templates, false); + + vector::const_iterator it; if(!global_templates.empty()) { - for(vector::const_iterator it = global_templates.begin(); it != global_templates.end(); it++) { + for(it = global_templates.begin(); it != global_templates.end(); it++) { TemplateInfo info = (*it); MixerSnapshot* snap = new MixerSnapshot(_session, info.path); - snap->set_label(info.name); - snap->set_path(info.path); _global_snapshots.insert(snap); } } - - /* this should be in search_paths and then integrated into template_utils - but having it be based on the session presents... complications. For now - We're just going to construct our own search path. - */ - PBD::Searchpath spath (_session->session_directory().root_path()); - spath.add_subdirectory_to_paths(route_templates_dir_name); - - vector local_templates; - string pattern = "*" + string(template_suffix); - find_files_matching_pattern(local_templates, spath, pattern); - if(!local_templates.empty()) { - for(vector::const_iterator it = local_templates.begin(); it != local_templates.end(); it++) { - const string path = (*it); - const string label = PBD::basename_nosuffix(path); + for(it = local_templates.begin(); it != local_templates.end(); it++) { + TemplateInfo info = (*it); - MixerSnapshot* snap = new MixerSnapshot(_session, path); - snap->set_label(label); + MixerSnapshot* snap = new MixerSnapshot(_session, info.path); _local_snapshots.insert(snap); } }