ardour
session_directory.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 Tim Mayberry
3 
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.
8 
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.
13 
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.
17 */
18 
19 #include <cerrno>
20 
21 #include <glibmm/fileutils.h>
22 #include <glibmm/miscutils.h>
23 
24 #include "pbd/error.h"
25 #include "pbd/compose.h"
26 #include "pbd/file_utils.h"
27 
28 #include "ardour/directory_names.h"
30 #include "ardour/utils.h"
31 
32 #include "i18n.h"
33 
34 namespace ARDOUR {
35 
36 using namespace std;
37 using namespace PBD::sys;
38 
39 SessionDirectory::SessionDirectory (const std::string& session_path)
40  : m_root_path(session_path)
41 {
42 
43 }
44 
46 SessionDirectory::operator= (const std::string& newpath)
47 {
48  m_root_path = newpath;
49  return *this;
50 }
51 
52 bool
54 {
55  vector<std::string> sub_dirs = sub_directories ();
56  for (vector<std::string>::const_iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i)
57  {
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;
60  return false;
61  }
62  }
63 
64  return true;
65 }
66 
67 bool
69 {
70  if (!Glib::file_test (m_root_path, Glib::FILE_TEST_IS_DIR)) return false;
71 
72  vector<std::string> sub_dirs = sub_directories ();
73 
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;
77  return false;
78  }
79  }
80  return true;
81 }
82 
83 const std::string
85 {
86  return Glib::build_filename (m_root_path, old_sound_dir_name);
87 }
88 
89 const std::string
91 {
92  std::string p = m_root_path;
93  std::string filename = Glib::path_get_basename(p);
94 
95  if (filename == ".") {
97  }
98 
99  const string legalized_root (legalize_for_path (Glib::path_get_basename(p)));
100 
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);
103 }
104 
105 const std::string
107 {
108  std::string p = m_root_path;
109  std::string filename = Glib::path_get_basename(p);
110 
111  if (filename == ".") {
113  }
114 
115  const string legalized_root (legalize_for_path_2X (Glib::path_get_basename(p)));
116 
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);
119 }
120 
121 const std::string
123 {
124  if (Glib::file_test (old_sound_path (), Glib::FILE_TEST_IS_DIR)) return old_sound_path();
125 
126  // the new style sound directory
127  return Glib::build_filename (sources_root(), sound_dir_name);
128 }
129 
130 const std::string
132 {
133  return Glib::build_filename (sources_root_2X(), sound_dir_name);
134 }
135 
136 const std::string
138 {
139  return Glib::build_filename (sources_root(), midi_dir_name);
140 }
141 
142 const std::string
144 {
145  return Glib::build_filename (sources_root(), midi_patch_dir_name);
146 }
147 
148 const std::string
150 {
151  return Glib::build_filename (sources_root(), video_dir_name);
152 }
153 
154 const std::string
156 {
157  return Glib::build_filename (m_root_path, peak_dir_name);
158 }
159 
160 const std::string
162 {
163  return Glib::build_filename (m_root_path, dead_dir_name);
164 }
165 
166 const std::string
168 {
169  return Glib::build_filename (m_root_path, export_dir_name);
170 }
171 
172 const vector<std::string>
174 {
175  vector<std::string> tmp_paths;
176 
177  tmp_paths.push_back (sound_path ());
178  tmp_paths.push_back (midi_path ());
179  tmp_paths.push_back (video_path ());
180  tmp_paths.push_back (peak_path ());
181  tmp_paths.push_back (dead_path ());
182  tmp_paths.push_back (export_path ());
183 
184  return tmp_paths;
185 }
186 
187 } // namespace ARDOUR
LIBARDOUR_API const char *const midi_dir_name
const std::string sound_path_2X() const
const std::string sources_root_2X() const
SessionDirectory & operator=(const std::string &path)
LIBARDOUR_API const char *const old_sound_dir_name
LIBARDOUR_API const char *const midi_patch_dir_name
LIBARDOUR_API std::string legalize_for_path(const std::string &str)
const std::string video_path() const
LIBARDOUR_API const char *const export_dir_name
LIBARDOUR_API const char *const video_dir_name
Definition: Beats.hpp:239
LIBPBD_API Transmitter error
LIBPBD_API Transmitter warning
std::string m_root_path
The path to the root of the session directory.
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
const std::string dead_path() const
#define _(Text)
Definition: i18n.h:11
LIBARDOUR_API std::string legalize_for_path_2X(const std::string &str)
Definition: amp.h:29
SessionDirectory(const std::string &session_path)
const std::string old_sound_path() const
const std::vector< std::string > sub_directories() const
std::string get_absolute_path(const std::string &p)
Definition: file_utils.cc:347
const std::string sound_path() const
const std::string midi_patch_path() const
const std::string peak_path() const
const std::string export_path() const
LIBARDOUR_API const char *const sound_dir_name
LIBARDOUR_API const char *const interchange_dir_name
const std::string midi_path() const
const std::string sources_root() const
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
LIBARDOUR_API const char *const peak_dir_name
LIBARDOUR_API const char *const dead_dir_name