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.
19 #include "pbd/error.h"
20 #include "pbd/compose.h"
21 #include "pbd/filesystem.h"
23 #include "ardour/directory_names.h"
24 #include "ardour/session_directory.h"
25 #include "ardour/utils.h"
31 using namespace PBD::sys;
33 SessionDirectory::SessionDirectory (const path& session_path)
34 : m_root_path(session_path)
40 SessionDirectory::create ()
44 vector<path> sub_dirs = sub_directories ();
45 for (vector<path>::const_iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i)
49 if(create_directories(*i)) is_new = true;
51 catch (PBD::sys::filesystem_error& ex)
54 PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), (*i).to_string(), ex.what()) << endmsg;
65 SessionDirectory::is_valid () const
67 if (!is_directory (m_root_path)) return false;
69 vector<path> sub_dirs = sub_directories ();
71 for (vector<path>::iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i) {
72 if (!is_directory (*i)) {
73 PBD::warning << string_compose(_("Session subdirectory does not exist at path %1"), (*i).to_string()) << endmsg;
81 SessionDirectory::old_sound_path () const
83 return m_root_path / old_sound_dir_name;
87 SessionDirectory::sources_root () const
89 const string legalized_root(legalize_for_path(m_root_path.leaf()));
91 return m_root_path / interchange_dir_name / legalized_root;
95 SessionDirectory::sound_path () const
97 if(is_directory (old_sound_path ())) return old_sound_path();
99 // the new style sound directory
100 return sources_root() / sound_dir_name;
104 SessionDirectory::midi_path () const
106 return sources_root() / midi_dir_name;
110 SessionDirectory::midi_patch_path () const
112 return sources_root() / midi_patch_dir_name;
116 SessionDirectory::peak_path () const
118 return m_root_path / peak_dir_name;
122 SessionDirectory::dead_sound_path () const
124 return m_root_path / dead_sound_dir_name;
128 SessionDirectory::dead_midi_path () const
130 return m_root_path / dead_midi_dir_name;
134 SessionDirectory::export_path () const
136 return m_root_path / export_dir_name;
140 SessionDirectory::sub_directories () const
142 vector<path> tmp_paths;
144 tmp_paths.push_back ( sound_path () );
145 tmp_paths.push_back ( midi_path () );
146 tmp_paths.push_back ( peak_path () );
147 tmp_paths.push_back ( dead_sound_path () );
148 tmp_paths.push_back ( dead_midi_path () );
149 tmp_paths.push_back ( export_path () );
154 } // namespace ARDOUR