From ae63588c0291f59ef3c14b331c5ec4d3c2f84f8e Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 7 Dec 2011 18:52:14 +0000 Subject: improved WORKING fix for search path issues git-svn-id: svn://localhost/ardour2/branches/3.0@10940 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/session_configuration_vars.h | 4 +- libs/ardour/ardour/utils.h | 3 +- libs/ardour/session.cc | 83 +++++++++++++++---------- libs/ardour/utils.cc | 28 +++++++++ 4 files changed, 82 insertions(+), 36 deletions(-) diff --git a/libs/ardour/ardour/session_configuration_vars.h b/libs/ardour/ardour/session_configuration_vars.h index 9d854ab2f8..45300d3e0f 100644 --- a/libs/ardour/ardour/session_configuration_vars.h +++ b/libs/ardour/ardour/session_configuration_vars.h @@ -43,8 +43,8 @@ CONFIG_VARIABLE (bool, punch_out, "punch-out", false) CONFIG_VARIABLE (uint32_t, subframes_per_frame, "subframes-per-frame", 100) CONFIG_VARIABLE (TimecodeFormat, timecode_format, "timecode-format", timecode_30) CONFIG_VARIABLE_SPECIAL(std::string, raid_path, "raid-path", "", path_expand) -CONFIG_VARIABLE_SPECIAL(std::string, audio_search_path, "audio-search-path", "", path_expand) -CONFIG_VARIABLE_SPECIAL(std::string, midi_search_path, "midi-search-path", "", path_expand) +CONFIG_VARIABLE_SPECIAL(std::string, audio_search_path, "audio-search-path", "", search_path_expand) +CONFIG_VARIABLE_SPECIAL(std::string, midi_search_path, "midi-search-path", "", search_path_expand) CONFIG_VARIABLE (std::string, bwf_country_code, "bwf-country-code", "US") CONFIG_VARIABLE (std::string, bwf_organization_code, "bwf-organization-code", "US") CONFIG_VARIABLE (LayerModel, layer_model, "layer-model", MoveAddHigher) diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h index 17fa9070ff..03a2ff13b7 100644 --- a/libs/ardour/ardour/utils.h +++ b/libs/ardour/ardour/utils.h @@ -59,7 +59,8 @@ int cmp_nocase (const std::string& s, const std::string& s2); int touch_file(std::string path); -std::string path_expand (std::string); +std::string path_expand (std::string); /* single file path */ +std::string search_path_expand (std::string); /* colon-separated search path */ std::string region_name_from_path (std::string path, bool strip_channels, bool add_channel_suffix = false, uint32_t total = 0, uint32_t this_one = 0); bool path_is_paired (std::string path, std::string& pair_base); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 2ad97e7d9d..d0ca765754 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4216,9 +4216,32 @@ Session::end_time_changed (framepos_t old) string Session::source_search_path (DataType type) const { - string search_path; + vector s; + + if (session_dirs.size() == 1) { + switch (type) { + case DataType::AUDIO: + s.push_back ( _session_dir->sound_path().to_string()); + break; + case DataType::MIDI: + s.push_back (_session_dir->midi_path().to_string()); + break; + } + } else { + for (vector::const_iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) { + SessionDirectory sdir (i->path); + switch (type) { + case DataType::AUDIO: + s.push_back (sdir.sound_path().to_string()); + break; + case DataType::MIDI: + s.push_back (sdir.midi_path().to_string()); + break; + } + } + } - /* first check the explicit (possibly user-specified) search path + /* now check the explicit (possibly user-specified) search path */ vector dirs; @@ -4233,41 +4256,27 @@ Session::source_search_path (DataType type) const } for (vector::iterator i = dirs.begin(); i != dirs.end(); ++i) { - search_path += ':'; - search_path += *i; - } - - if (!search_path.empty()) { - return search_path; - } + vector::iterator si; - /* if there was nothing there, check the session dirs */ - - if (session_dirs.size() == 1) { - switch (type) { - case DataType::AUDIO: - search_path = _session_dir->sound_path().to_string(); - break; - case DataType::MIDI: - search_path = _session_dir->midi_path().to_string(); - break; - } - } else { - for (vector::const_iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) { - SessionDirectory sdir (i->path); - if (!search_path.empty()) { - search_path += ':'; - } - switch (type) { - case DataType::AUDIO: - search_path += sdir.sound_path().to_string(); - break; - case DataType::MIDI: - search_path += sdir.midi_path().to_string(); + for (si = s.begin(); si != s.end(); ++si) { + if ((*si) == *i) { break; } } + + if (si == s.end()) { + s.push_back (*i); + } + } + + string search_path; + + for (vector::iterator si = s.begin(); si != s.end(); ++si) { + if (!search_path.empty()) { + search_path += ':'; + } + search_path += *si; } return search_path; @@ -4283,7 +4292,15 @@ Session::ensure_search_path_includes (const string& path, DataType type) return; } - search_path = source_search_path (type); + switch (type) { + case DataType::AUDIO: + search_path = config.get_audio_search_path (); + break; + case DataType::MIDI: + search_path = config.get_midi_search_path (); + break; + } + split (search_path, dirs, ':'); for (vector::iterator i = dirs.begin(); i != dirs.end(); ++i) { diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index afd83b62b5..8588d9ccd6 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -349,6 +349,34 @@ path_expand (string path) } } +string +search_path_expand (string path) +{ + if (path.empty()) { + return path; + } + + vector s; + vector n; + + split (path, s, ':'); + + for (vector::iterator i = s.begin(); i != s.end(); ++i) { + n.push_back (path_expand (*i)); + } + + string r; + + for (vector::iterator i = n.begin(); i != n.end(); ++i) { + if (!r.empty()) { + r += ':'; + } + r += *i; + } + + return r; +} + #if __APPLE__ string CFStringRefToStdString(CFStringRef stringRef) -- cgit v1.2.3