Fix portability of Session::source_search_path
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 15 Jul 2013 12:05:37 +0000 (08:05 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 15 Jul 2013 12:05:37 +0000 (08:05 -0400)
gtk2_ardour/ardour_ui.cc
gtk2_ardour/ardour_ui.h
gtk2_ardour/missing_file_dialog.cc
libs/ardour/ardour/file_source.h
libs/ardour/ardour/session.h
libs/ardour/file_source.cc
libs/ardour/session.cc

index e3655a0d7ab3812e79b2054025b52c4cbec60d62..91dbd999df5c75c44b9d662e4e82b43142a478e8 100644 (file)
@@ -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<std::string> hits)
+ARDOUR_UI::ambiguous_file (std::string file, std::vector<std::string> hits)
 {
        AmbiguousFileDialog dialog (file, hits);
 
index 5817293b29cca29edec5a0f0138c82ba07bd374c..7a8a0193f1c5636bc9c2b0d3e93b29de80f32857 100644 (file)
@@ -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<std::string> hits);
+        int ambiguous_file (std::string file, std::vector<std::string> hits);
 
        bool click_button_clicked (GdkEventButton *);
 
index c7cb7f5edccf8a08902bde16c6b0a7f9d54de28c..b1e2081a1dace00aa27ab43a1efed747ca381da9 100644 (file)
 #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<string> source_dirs = s->source_search_path (type);
+       vector<string>::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<i>%3</i>\n\nin any of these folders:\n\n\
-<tt>%4</tt>\n\n"), PROGRAM_NAME, typestr, Glib::Markup::escape_text(path), Glib::Markup::escape_text (dirstr)));
+<tt>%4</tt>\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);
index 5898d04f0abaff68ab1d4dbf23c1032b8e267913..52dca18feb4505741fcfe6f77038fb6d6691fb96 100644 (file)
@@ -79,7 +79,7 @@ public:
 
        virtual void set_path (const std::string&);
        
-       static PBD::Signal3<int,std::string,std::string,std::vector<std::string> > AmbiguousFileName;
+       static PBD::Signal2<int,std::string,std::vector<std::string> > AmbiguousFileName;
 
 protected:
        FileSource (Session& session, DataType type,
index a1492246077f7100d507e9b7f4ed11ca766cfc59..85866f99a5823d14fee49c4df94f6f92b2486d56 100644 (file)
@@ -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<std::string> source_search_path(DataType) const;
        void ensure_search_path_includes (const std::string& path, DataType type);
 
        std::list<std::string> unknown_processors () const;
index 06d4fb6175de447f1aa8007d35580c7c48dc13a4..c7b03cbdb756fe8f989103fe7cd12a121e68f6d2 100644 (file)
@@ -51,7 +51,7 @@ using namespace ARDOUR;
 using namespace PBD;
 using namespace Glib;
 
-PBD::Signal3<int,std::string,std::string,std::vector<std::string> > FileSource::AmbiguousFileName;
+PBD::Signal2<int,std::string,std::vector<std::string> > 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<string> dirs;
                 vector<string> hits;
                 string fullpath;
+               std::vector<std::string> 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<string>::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<string> dirs;
+               vector<string> 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<string>::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;
index 914c6a9a77de28bd42aecf336841bf55e9f08609..476682158f86d179e446619a2657628e39ccd35d 100644 (file)
@@ -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"
 
 #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<std::string>
 Session::source_search_path (DataType type) const
 {
-       vector<string> 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<string> 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<string>::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<string>::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<string> 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<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
+       for (vector<std::string>::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;
        }
 }