From 43f7813b248686bfa89600f91dccd83017dfe669 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 15 Jul 2013 08:05:37 -0400 Subject: Fix portability of Session::source_search_path --- gtk2_ardour/ardour_ui.cc | 4 +-- gtk2_ardour/ardour_ui.h | 2 +- gtk2_ardour/missing_file_dialog.cc | 17 +++++++--- libs/ardour/ardour/file_source.h | 2 +- libs/ardour/ardour/session.h | 2 +- libs/ardour/file_source.cc | 31 ++++++----------- libs/ardour/session.cc | 69 +++++++++++++------------------------- 7 files changed, 53 insertions(+), 74 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index e3655a0d7a..91dbd999df 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -288,7 +288,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir) /* and ambiguous files */ - ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2, _3)); + ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2)); /* lets get this party started */ @@ -4050,7 +4050,7 @@ ARDOUR_UI::missing_file (Session*s, std::string str, DataType type) } int -ARDOUR_UI::ambiguous_file (std::string file, std::string /*path*/, std::vector hits) +ARDOUR_UI::ambiguous_file (std::string file, std::vector hits) { AmbiguousFileDialog dialog (file, hits); diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 5817293b29..7a8a0193f1 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -713,7 +713,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr void fontconfig_dialog (); int missing_file (ARDOUR::Session*s, std::string str, ARDOUR::DataType type); - int ambiguous_file (std::string file, std::string path, std::vector hits); + int ambiguous_file (std::string file, std::vector hits); bool click_button_clicked (GdkEventButton *); diff --git a/gtk2_ardour/missing_file_dialog.cc b/gtk2_ardour/missing_file_dialog.cc index c7cb7f5edc..b1e2081a1d 100644 --- a/gtk2_ardour/missing_file_dialog.cc +++ b/gtk2_ardour/missing_file_dialog.cc @@ -19,12 +19,17 @@ #include "pbd/compose.h" #include "pbd/replace_all.h" #include "pbd/strsplit.h" +#include "pbd/search_path.h" #include "ardour/session.h" #include "missing_file_dialog.h" #include "i18n.h" +#ifdef SearchPath +#undef SearchPath +#endif + using namespace Gtk; using namespace std; using namespace ARDOUR; @@ -56,14 +61,18 @@ MissingFileDialog::MissingFileDialog (Session* s, const std::string& path, DataT break; } - string dirstr; + vector source_dirs = s->source_search_path (type); + vector::iterator i = source_dirs.begin(); + ostringstream oss; + oss << *i << endl; - dirstr = s->source_search_path (type); - replace_all (dirstr, ":", "\n"); + while (++i != source_dirs.end()) { + oss << *i << endl; + } msg.set_justify (JUSTIFY_CENTER); msg.set_markup (string_compose (_("%1 cannot find the %2 file\n\n%3\n\nin any of these folders:\n\n\ -%4\n\n"), PROGRAM_NAME, typestr, Glib::Markup::escape_text(path), Glib::Markup::escape_text (dirstr))); +%4\n\n"), PROGRAM_NAME, typestr, Glib::Markup::escape_text(path), Glib::Markup::escape_text (oss.str()))); HBox* hbox = manage (new HBox); hbox->pack_start (msg, false, true); diff --git a/libs/ardour/ardour/file_source.h b/libs/ardour/ardour/file_source.h index 5898d04f0a..52dca18feb 100644 --- a/libs/ardour/ardour/file_source.h +++ b/libs/ardour/ardour/file_source.h @@ -79,7 +79,7 @@ public: virtual void set_path (const std::string&); - static PBD::Signal3 > AmbiguousFileName; + static PBD::Signal2 > AmbiguousFileName; protected: FileSource (Session& session, DataType type, diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index a149224607..85866f99a5 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -820,7 +820,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi void request_resume_timecode_transmission (); bool timecode_transmission_suspended () const; - std::string source_search_path(DataType) const; + std::vector source_search_path(DataType) const; void ensure_search_path_includes (const std::string& path, DataType type); std::list unknown_processors () const; diff --git a/libs/ardour/file_source.cc b/libs/ardour/file_source.cc index 06d4fb6175..c7b03cbdb7 100644 --- a/libs/ardour/file_source.cc +++ b/libs/ardour/file_source.cc @@ -51,7 +51,7 @@ using namespace ARDOUR; using namespace PBD; using namespace Glib; -PBD::Signal3 > FileSource::AmbiguousFileName; +PBD::Signal2 > FileSource::AmbiguousFileName; FileSource::FileSource (Session& session, DataType type, const string& path, const string& origin, Source::Flag flag) : Source(session, type, path, flag) @@ -240,19 +240,15 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist isnew = false; if (!Glib::path_is_absolute (path)) { - vector dirs; vector hits; string fullpath; + std::vector dirs = s.source_search_path (type); - string search_path = s.source_search_path (type); - - if (search_path.length() == 0) { + if (dirs.size() == 0) { error << _("FileSource: search path not set") << endmsg; goto out; } - split (search_path, dirs, ':'); - hits.clear (); for (vector::iterator i = dirs.begin(); i != dirs.end(); ++i) { @@ -296,7 +292,7 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist /* more than one match: ask the user */ - int which = FileSource::AmbiguousFileName (path, search_path, de_duped_hits).get_value_or (-1); + int which = FileSource::AmbiguousFileName (path, de_duped_hits).get_value_or (-1); if (which < 0) { goto out; @@ -310,8 +306,7 @@ FileSource::find (Session& s, DataType type, const string& path, bool must_exist if (must_exist) { error << string_compose( - _("Filesource: cannot find required file (%1): while searching %2"), - path, search_path) << endmsg; + _("Filesource: cannot find required file (%1)"), path) << endmsg; goto out; } else { isnew = true; @@ -357,8 +352,6 @@ bool FileSource::find_2X (Session& s, DataType type, const string& path, bool must_exist, bool& isnew, uint16_t& chan, string& found_path) { - string search_path = s.source_search_path (type); - string pathstr = path; string::size_type pos; bool ret = false; @@ -369,18 +362,17 @@ FileSource::find_2X (Session& s, DataType type, const string& path, bool must_ex /* non-absolute pathname: find pathstr in search path */ - vector dirs; + vector dirs = s.source_search_path (type); + int cnt; string fullpath; string keeppath; - if (search_path.length() == 0) { + if (dirs.size() == 0) { error << _("FileSource: search path not set") << endmsg; goto out; } - split (search_path, dirs, ':'); - cnt = 0; for (vector::iterator i = dirs.begin(); i != dirs.end(); ++i) { @@ -437,16 +429,15 @@ FileSource::find_2X (Session& s, DataType type, const string& path, bool must_ex if (cnt > 1) { error << string_compose ( - _("FileSource: \"%1\" is ambigous when searching %2\n\t"), - pathstr, search_path) << endmsg; + _("FileSource: \"%1\" is ambigous when searching\n\t"), pathstr) << endmsg; goto out; } else if (cnt == 0) { if (must_exist) { error << string_compose( - _("Filesource: cannot find required file (%1): while searching %2"), - pathstr, search_path) << endmsg; + _("Filesource: cannot find required file (%1): while searching") + , pathstr) << endmsg; goto out; } else { isnew = true; diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 914c6a9a77..476682158f 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -44,8 +44,8 @@ #include "pbd/stacktrace.h" #include "pbd/file_utils.h" #include "pbd/convert.h" -#include "pbd/strsplit.h" #include "pbd/unwind.h" +#include "pbd/search_path.h" #include "ardour/amp.h" #include "ardour/analyser.h" @@ -94,6 +94,10 @@ #include "i18n.h" +#ifdef SearchPath +#undef SearchPath +#endif + namespace ARDOUR { class MidiSource; class Processor; @@ -4420,18 +4424,18 @@ Session::end_time_changed (framepos_t old) } } -string +std::vector Session::source_search_path (DataType type) const { - vector s; + SearchPath sp; if (session_dirs.size() == 1) { switch (type) { case DataType::AUDIO: - s.push_back (_session_dir->sound_path()); + sp.push_back (_session_dir->sound_path()); break; case DataType::MIDI: - s.push_back (_session_dir->midi_path()); + sp.push_back (_session_dir->midi_path()); break; } } else { @@ -4439,10 +4443,10 @@ Session::source_search_path (DataType type) const SessionDirectory sdir (i->path); switch (type) { case DataType::AUDIO: - s.push_back (sdir.sound_path()); + sp.push_back (sdir.sound_path()); break; case DataType::MIDI: - s.push_back (sdir.midi_path()); + sp.push_back (sdir.midi_path()); break; } } @@ -4451,49 +4455,30 @@ 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)) { - if (find (s.begin(), s.end(), sound_path_2X) == s.end()) { - s.push_back (sound_path_2X); + if (find (sp.begin(), sp.end(), sound_path_2X) == sp.end()) { + sp.push_back (sound_path_2X); } } } - /* now check the explicit (possibly user-specified) search path - */ - - vector dirs; + // now check the explicit (possibly user-specified) search path switch (type) { case DataType::AUDIO: - split (config.get_audio_search_path (), dirs, ':'); + sp += SearchPath(config.get_audio_search_path ()); break; case DataType::MIDI: - split (config.get_midi_search_path (), dirs, ':'); + sp += SearchPath(config.get_midi_search_path ()); break; } - for (vector::iterator i = dirs.begin(); i != dirs.end(); ++i) { - if (find (s.begin(), s.end(), *i) == 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; + return sp; } void Session::ensure_search_path_includes (const string& path, DataType type) { - string search_path; - vector dirs; + SearchPath sp; if (path == ".") { return; @@ -4501,16 +4486,14 @@ Session::ensure_search_path_includes (const string& path, DataType type) switch (type) { case DataType::AUDIO: - search_path = config.get_audio_search_path (); + sp += SearchPath(config.get_audio_search_path ()); break; case DataType::MIDI: - search_path = config.get_midi_search_path (); + sp += SearchPath (config.get_midi_search_path ()); break; } - split (search_path, dirs, ':'); - - for (vector::iterator i = dirs.begin(); i != dirs.end(); ++i) { + for (vector::iterator i = sp.begin(); i != sp.end(); ++i) { /* No need to add this new directory if it has the same inode as an existing one; checking inode rather than name prevents duplicated directories when we are using symlinks. @@ -4522,18 +4505,14 @@ Session::ensure_search_path_includes (const string& path, DataType type) } } - if (!search_path.empty()) { - search_path += ':'; - } - - search_path += path; + sp += path; switch (type) { case DataType::AUDIO: - config.set_audio_search_path (search_path); + config.set_audio_search_path (sp.to_string()); break; case DataType::MIDI: - config.set_midi_search_path (search_path); + config.set_midi_search_path (sp.to_string()); break; } } -- cgit v1.2.3