2
Copyright (C) 2007 Tim Mayberry
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#include <glibmm/fileutils.h>
22
#include <glibmm/miscutils.h>
24
#include "pbd/error.h"
25
#include "pbd/compose.h"
26
#include "pbd/file_utils.h"
28
#include "ardour/directory_names.h"
29
#include "ardour/session_directory.h"
30
#include "ardour/utils.h"
37
using namespace PBD::sys;
39
SessionDirectory::SessionDirectory (const std::string& session_path)
40
: m_root_path(session_path)
46
SessionDirectory::operator= (const std::string& newpath)
48
m_root_path = newpath;
53
SessionDirectory::create ()
55
vector<std::string> sub_dirs = sub_directories ();
56
for (vector<std::string>::const_iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i)
58
if (g_mkdir_with_parents (i->c_str(), 0755) != 0) {
59
PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), *i, g_strerror(errno)) << endmsg;
68
SessionDirectory::is_valid () const
70
if (!Glib::file_test (m_root_path, Glib::FILE_TEST_IS_DIR)) return false;
72
vector<std::string> sub_dirs = sub_directories ();
74
for (vector<std::string>::iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i) {
75
if (!Glib::file_test (*i, Glib::FILE_TEST_IS_DIR)) {
76
PBD::warning << string_compose(_("Session subdirectory does not exist at path %1"), *i) << endmsg;
84
SessionDirectory::old_sound_path () const
86
return Glib::build_filename (m_root_path, old_sound_dir_name);
90
SessionDirectory::sources_root () const
92
std::string p = m_root_path;
93
std::string filename = Glib::path_get_basename(p);
95
if (filename == ".") {
96
p = PBD::get_absolute_path (m_root_path);
99
const string legalized_root (legalize_for_path (Glib::path_get_basename(p)));
101
std::string sources_root_path = Glib::build_filename (m_root_path, interchange_dir_name);
102
return Glib::build_filename (sources_root_path, legalized_root);
106
SessionDirectory::sources_root_2X () const
108
std::string p = m_root_path;
109
std::string filename = Glib::path_get_basename(p);
111
if (filename == ".") {
112
p = PBD::get_absolute_path (m_root_path);
115
const string legalized_root (legalize_for_path_2X (Glib::path_get_basename(p)));
117
std::string sources_root_path = Glib::build_filename (m_root_path, interchange_dir_name);
118
return Glib::build_filename (sources_root_path, legalized_root);
122
SessionDirectory::sound_path () const
124
if (Glib::file_test (old_sound_path (), Glib::FILE_TEST_IS_DIR)) return old_sound_path();
126
// the new style sound directory
127
return Glib::build_filename (sources_root(), sound_dir_name);
131
SessionDirectory::sound_path_2X () const
133
return Glib::build_filename (sources_root_2X(), sound_dir_name);
137
SessionDirectory::midi_path () const
139
return Glib::build_filename (sources_root(), midi_dir_name);
143
SessionDirectory::midi_patch_path () const
145
return Glib::build_filename (sources_root(), midi_patch_dir_name);
149
SessionDirectory::video_path () const
151
return Glib::build_filename (sources_root(), video_dir_name);
155
SessionDirectory::peak_path () const
157
return Glib::build_filename (m_root_path, peak_dir_name);
161
SessionDirectory::dead_path () const
163
return Glib::build_filename (m_root_path, dead_dir_name);
167
SessionDirectory::export_path () const
169
return Glib::build_filename (m_root_path, export_dir_name);
172
const vector<std::string>
173
SessionDirectory::sub_directories () const
175
vector<std::string> tmp_paths;
177
tmp_paths.push_back (sound_path ());
178
tmp_paths.push_back (midi_path ());
179
tmp_paths.push_back (peak_path ());
180
tmp_paths.push_back (dead_path ());
181
tmp_paths.push_back (export_path ());
186
} // namespace ARDOUR