diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index c368bed5f3..0f72884c9b 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -1010,7 +1011,7 @@ ARDOUR_UI::open_session () bool isnew; if (session_path.length() > 0) { - if (Session::find_session (session_path, path, name, isnew) == 0) { + if (ARDOUR::find_session (session_path, path, name, isnew) == 0) { _session_is_new = isnew; load_session (path, name); } diff --git a/gtk2_ardour/imageframe_socket_handler.cc b/gtk2_ardour/imageframe_socket_handler.cc index 96b61cafdd..dac36c6e2e 100644 --- a/gtk2_ardour/imageframe_socket_handler.cc +++ b/gtk2_ardour/imageframe_socket_handler.cc @@ -44,6 +44,7 @@ #include "i18n.h" #include +#include #include @@ -2062,7 +2063,7 @@ ImageFrameSocketHandler::handle_open_session(const char* msg) std::string path, name ; bool isnew; - if (ARDOUR::Session::find_session(session_name, path, name, isnew) == 0) { + if (ARDOUR::find_session(session_name, path, name, isnew) == 0) { if (ARDOUR_UI::instance()->load_session (path, name) == 0) { send_return_success() ; } else { diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index 3d9fd057f8..80da30a0e2 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -140,7 +141,7 @@ maybe_load_session () bool isnew; - if (Session::find_session (session_name, path, name, isnew)) { + if (find_session (session_name, path, name, isnew)) { error << string_compose(_("could not load command line session \"%1\""), session_name) << endmsg; return false; } diff --git a/libs/ardour/SConscript b/libs/ardour/SConscript index ba22de18ca..9ae82096b5 100644 --- a/libs/ardour/SConscript +++ b/libs/ardour/SConscript @@ -30,6 +30,7 @@ ardour_files=Split(""" chan_count.cc diskstream.cc filename_extensions.cc +find_session.cc track.cc audio_diskstream.cc audio_library.cc diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 59da5dc2c0..35f4d32372 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -240,9 +240,6 @@ class Session : public PBD::StatefulDestructible virtual ~Session (); - - static int find_session (string str, string& path, string& snapshot, bool& isnew); - string path() const { return _path; } string name() const { return _name; } string snap_name() const { return _current_snapshot_name; } diff --git a/libs/ardour/ardour/session_utils.h b/libs/ardour/ardour/session_utils.h new file mode 100644 index 0000000000..8aa4505fe5 --- /dev/null +++ b/libs/ardour/ardour/session_utils.h @@ -0,0 +1,15 @@ + +#ifndef __ardour_session_utils_h__ +#define __ardour_session_utils_h__ + +#include + +namespace ARDOUR { + +using std::string; + +int find_session (string str, string& path, string& snapshot, bool& isnew); + +}; + +#endif diff --git a/libs/ardour/find_session.cc b/libs/ardour/find_session.cc new file mode 100644 index 0000000000..f8ed3d5a46 --- /dev/null +++ b/libs/ardour/find_session.cc @@ -0,0 +1,166 @@ +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include "i18n.h" + +using namespace PBD; + +int +ARDOUR::find_session (string str, string& path, string& snapshot, bool& isnew) +{ + struct stat statbuf; + char buf[PATH_MAX+1]; + + isnew = false; + + if (!realpath (str.c_str(), buf) && (errno != ENOENT && errno != ENOTDIR)) { + error << string_compose (_("Could not resolve path: %1 (%2)"), buf, strerror(errno)) << endmsg; + return -1; + } + + str = buf; + + /* check to see if it exists, and what it is */ + + if (stat (str.c_str(), &statbuf)) { + if (errno == ENOENT) { + isnew = true; + } else { + error << string_compose (_("cannot check session path %1 (%2)"), str, strerror (errno)) + << endmsg; + return -1; + } + } + + if (!isnew) { + + /* it exists, so it must either be the name + of the directory, or the name of the statefile + within it. + */ + + if (S_ISDIR (statbuf.st_mode)) { + + string::size_type slash = str.find_last_of ('/'); + + if (slash == string::npos) { + + /* a subdirectory of cwd, so statefile should be ... */ + + string tmp; + tmp = str; + tmp += '/'; + tmp += str; + tmp += statefile_suffix; + + /* is it there ? */ + + if (stat (tmp.c_str(), &statbuf)) { + error << string_compose (_("cannot check statefile %1 (%2)"), tmp, strerror (errno)) + << endmsg; + return -1; + } + + path = str; + snapshot = str; + + } else { + + /* some directory someplace in the filesystem. + the snapshot name is the directory name + itself. + */ + + path = str; + snapshot = str.substr (slash+1); + + } + + } else if (S_ISREG (statbuf.st_mode)) { + + string::size_type slash = str.find_last_of ('/'); + string::size_type suffix; + + /* remove the suffix */ + + if (slash != string::npos) { + snapshot = str.substr (slash+1); + } else { + snapshot = str; + } + + suffix = snapshot.find (statefile_suffix); + + if (suffix == string::npos) { + error << string_compose (_("%1 is not an Ardour snapshot file"), str) << endmsg; + return -1; + } + + /* remove suffix */ + + snapshot = snapshot.substr (0, suffix); + + if (slash == string::npos) { + + /* we must be in the directory where the + statefile lives. get it using cwd(). + */ + + char cwd[PATH_MAX+1]; + + if (getcwd (cwd, sizeof (cwd)) == 0) { + error << string_compose (_("cannot determine current working directory (%1)"), strerror (errno)) + << endmsg; + return -1; + } + + path = cwd; + + } else { + + /* full path to the statefile */ + + path = str.substr (0, slash); + } + + } else { + + /* what type of file is it? */ + error << string_compose (_("unknown file type for session %1"), str) << endmsg; + return -1; + } + + } else { + + /* its the name of a new directory. get the name + as "dirname" does. + */ + + string::size_type slash = str.find_last_of ('/'); + + if (slash == string::npos) { + + /* no slash, just use the name, but clean it up */ + + path = legalize_for_path (str); + snapshot = path; + + } else { + + path = str; + snapshot = str.substr (slash+1); + } + } + + return 0; +} diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 0542298c58..59c326264f 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -105,156 +105,6 @@ sigc::signal Session::SMPTEOffsetChanged; sigc::signal Session::StartTimeChanged; sigc::signal Session::EndTimeChanged; -int -Session::find_session (string str, string& path, string& snapshot, bool& isnew) -{ - struct stat statbuf; - char buf[PATH_MAX+1]; - - isnew = false; - - if (!realpath (str.c_str(), buf) && (errno != ENOENT && errno != ENOTDIR)) { - error << string_compose (_("Could not resolve path: %1 (%2)"), buf, strerror(errno)) << endmsg; - return -1; - } - - str = buf; - - /* check to see if it exists, and what it is */ - - if (stat (str.c_str(), &statbuf)) { - if (errno == ENOENT) { - isnew = true; - } else { - error << string_compose (_("cannot check session path %1 (%2)"), str, strerror (errno)) - << endmsg; - return -1; - } - } - - if (!isnew) { - - /* it exists, so it must either be the name - of the directory, or the name of the statefile - within it. - */ - - if (S_ISDIR (statbuf.st_mode)) { - - string::size_type slash = str.find_last_of ('/'); - - if (slash == string::npos) { - - /* a subdirectory of cwd, so statefile should be ... */ - - string tmp; - tmp = str; - tmp += '/'; - tmp += str; - tmp += statefile_suffix; - - /* is it there ? */ - - if (stat (tmp.c_str(), &statbuf)) { - error << string_compose (_("cannot check statefile %1 (%2)"), tmp, strerror (errno)) - << endmsg; - return -1; - } - - path = str; - snapshot = str; - - } else { - - /* some directory someplace in the filesystem. - the snapshot name is the directory name - itself. - */ - - path = str; - snapshot = str.substr (slash+1); - - } - - } else if (S_ISREG (statbuf.st_mode)) { - - string::size_type slash = str.find_last_of ('/'); - string::size_type suffix; - - /* remove the suffix */ - - if (slash != string::npos) { - snapshot = str.substr (slash+1); - } else { - snapshot = str; - } - - suffix = snapshot.find (statefile_suffix); - - if (suffix == string::npos) { - error << string_compose (_("%1 is not an Ardour snapshot file"), str) << endmsg; - return -1; - } - - /* remove suffix */ - - snapshot = snapshot.substr (0, suffix); - - if (slash == string::npos) { - - /* we must be in the directory where the - statefile lives. get it using cwd(). - */ - - char cwd[PATH_MAX+1]; - - if (getcwd (cwd, sizeof (cwd)) == 0) { - error << string_compose (_("cannot determine current working directory (%1)"), strerror (errno)) - << endmsg; - return -1; - } - - path = cwd; - - } else { - - /* full path to the statefile */ - - path = str.substr (0, slash); - } - - } else { - - /* what type of file is it? */ - error << string_compose (_("unknown file type for session %1"), str) << endmsg; - return -1; - } - - } else { - - /* its the name of a new directory. get the name - as "dirname" does. - */ - - string::size_type slash = str.find_last_of ('/'); - - if (slash == string::npos) { - - /* no slash, just use the name, but clean it up */ - - path = legalize_for_path (str); - snapshot = path; - - } else { - - path = str; - snapshot = str.substr (slash+1); - } - } - - return 0; -} - Session::Session (AudioEngine &eng, string fullpath, string snapshot_name,