From 35c6b52c36ca047ada5b1b127128c03049ebfc89 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 23 Oct 2012 14:52:26 +0000 Subject: probable fix for not being able to find audio files in a 2.X session that had "illegal" characters in the session name - adds the 2.X version of the search path to the audio file search path, if it exists git-svn-id: svn://localhost/ardour2/branches/3.0@13321 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/session_directory.h | 18 ++++++++++++++ libs/ardour/ardour/utils.h | 1 + libs/ardour/session.cc | 7 ++++++ libs/ardour/session_directory.cc | 22 +++++++++++++++++ libs/ardour/utils.cc | 43 +++++++++++++++++++++++++++++++++- 5 files changed, 90 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/session_directory.h b/libs/ardour/ardour/session_directory.h index 6f8f24386f..9f4410ce69 100644 --- a/libs/ardour/ardour/session_directory.h +++ b/libs/ardour/ardour/session_directory.h @@ -54,6 +54,17 @@ public: */ const std::string sound_path () const; + /** + * @return the absolute path to the directory in which + * the session stores audio files for Ardour 2.X. + * + * If the session is an older session with an existing + * "sounds" directory then it will return a path to that + * directory otherwise it will return the new location + * of root_path()/interchange/session_name/audiofiles + */ + const std::string sound_path_2X () const; + /** * @return the absolute path to the directory in which * the session stores MIDI files, ie @@ -110,6 +121,13 @@ public: */ const std::string sources_root() const; + /** + * @return The path to the directory under which source directories + * are created for different source types in Ardour 2.X + * i.e root_path()/interchange/session_name + */ + const std::string sources_root_2X() const; + private: /** diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h index 5052f03bab..7a09f5e209 100644 --- a/libs/ardour/ardour/utils.h +++ b/libs/ardour/ardour/utils.h @@ -39,6 +39,7 @@ class XMLNode; std::string legalize_for_path (const std::string& str); +std::string legalize_for_path_2X (const std::string& str); XMLNode* find_named_node (const XMLNode& node, std::string name); std::string bool_as_string (bool); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index e742dd372f..8c36f95726 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4352,6 +4352,13 @@ Session::source_search_path (DataType type) const } } + if (type == DataType::AUDIO) { + const string sound_path_2X = _session_dir->sound_path_2X(); + if (Glib::file_test (sound_path_2X, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_DIR)) { + s.push_back (sound_path_2X); + } + } + /* now check the explicit (possibly user-specified) search path */ diff --git a/libs/ardour/session_directory.cc b/libs/ardour/session_directory.cc index ec4fded685..7ff9c6f5a7 100644 --- a/libs/ardour/session_directory.cc +++ b/libs/ardour/session_directory.cc @@ -102,6 +102,22 @@ SessionDirectory::sources_root () const return Glib::build_filename (sources_root_path, legalized_root); } +const std::string +SessionDirectory::sources_root_2X () const +{ + std::string p = m_root_path; + std::string filename = Glib::path_get_basename(p); + + if (filename == ".") { + p = PBD::get_absolute_path (m_root_path); + } + + const string legalized_root (legalize_for_path_2X (Glib::path_get_basename(p))); + + std::string sources_root_path = Glib::build_filename (m_root_path, interchange_dir_name); + return Glib::build_filename (sources_root_path, legalized_root); +} + const std::string SessionDirectory::sound_path () const { @@ -111,6 +127,12 @@ SessionDirectory::sound_path () const return Glib::build_filename (sources_root(), sound_dir_name); } +const std::string +SessionDirectory::sound_path_2X () const +{ + return Glib::build_filename (sources_root_2X(), sound_dir_name); +} + const std::string SessionDirectory::midi_path () const { diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index 8c990a5e88..d9310c958a 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -60,12 +60,23 @@ using namespace ARDOUR; using namespace std; using namespace PBD; +/** take an arbitrary string as an argument, and return a version of it + * suitable for use as a path (directory/folder name). This is the Ardour 3.X + * and later version of this code. It defines a very small number + * of characters that are not allowed in a path on any of our target + * filesystems, and replaces any instances of them with an underscore. + */ + string legalize_for_path (const string& str) { string::size_type pos; string illegal_chars = "/\\"; /* DOS, POSIX. Yes, we're going to ignore HFS */ - string legal; + Glib::ustring legal; + + /* this is the one place in Ardour where we need to iterate across + * potential multibyte characters, and thus we need Glib::ustring + */ legal = str; pos = 0; @@ -78,6 +89,36 @@ legalize_for_path (const string& str) return string (legal); } +/** take an arbitrary string as an argument, and return a version of it + * suitable for use as a path (directory/folder name). This is the Ardour 2.X + * version of this code, which used an approach that came to be seen as + * problematic: defining the characters that were allowed and replacing all + * others with underscores. See legalize_for_path() for the 3.X and later + * version. + */ + +string +legalize_for_path_2X (const string& str) +{ + string::size_type pos; + string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=: "; + Glib::ustring legal; + + /* this is the one place in Ardour where we need to iterate across + * potential multibyte characters, and thus we need Glib::ustring + */ + + legal = str; + pos = 0; + + while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) { + legal.replace (pos, 1, "_"); + pos += 1; + } + + return string (legal); +} + string bump_name_once (const std::string& name, char delimiter) { -- cgit v1.2.3