newly created files for use in recording appear in a .stubs folder, and are moved...
[ardour.git] / libs / ardour / session_directory.cc
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 "pbd/error.h"
20 #include "pbd/compose.h"
21 #include "pbd/filesystem.h"
22
23 #include "ardour/directory_names.h"
24 #include "ardour/session_directory.h"
25 #include "ardour/utils.h"
26
27 #include "i18n.h"
28
29 namespace ARDOUR {
30
31 using namespace std;
32 using namespace PBD::sys;
33
34 SessionDirectory::SessionDirectory (const path& session_path)
35         : m_root_path(session_path)
36 {
37
38 }
39
40 bool
41 SessionDirectory::create ()
42 {
43         bool is_new = false;
44
45         vector<path> sub_dirs = sub_directories ();
46         for (vector<path>::const_iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i)
47         {
48                 try
49                 {
50                         if(create_directories(*i)) is_new = true;
51                 }
52                 catch (PBD::sys::filesystem_error& ex)
53                 {
54                         // log the error
55                         PBD::error << string_compose(_("Cannot create Session directory at path %1 Error: %2"), (*i).to_string(), ex.what()) << endmsg;
56
57                         // and rethrow
58                         throw ex;
59                 }
60         }
61
62         return is_new;
63 }
64
65 bool
66 SessionDirectory::is_valid () const
67 {
68         if (!is_directory (m_root_path)) return false;
69
70         vector<path> sub_dirs = sub_directories ();
71
72         for (vector<path>::iterator i = sub_dirs.begin(); i != sub_dirs.end(); ++i) {
73                 if (!is_directory (*i)) {
74                         PBD::warning << string_compose(_("Session subdirectory does not exist at path %1"), (*i).to_string()) << endmsg;
75                         return false;
76                 }
77         }
78         return true;
79 }
80
81 const path
82 SessionDirectory::old_sound_path () const
83 {
84         return m_root_path / old_sound_dir_name;
85 }
86
87 const path
88 SessionDirectory::sources_root () const
89 {
90         const string legalized_root(legalize_for_path(m_root_path.leaf()));
91
92         return m_root_path / interchange_dir_name / legalized_root;
93 }
94
95 const path
96 SessionDirectory::sound_path () const
97 {
98         if(is_directory (old_sound_path ())) return old_sound_path();
99
100         // the new style sound directory
101         return sources_root() / sound_dir_name;
102 }
103
104 const path
105 SessionDirectory::sound_stub_path () const
106 {
107         if(is_directory (old_sound_path ())) return old_sound_path();
108
109         // the new style sound directory
110         return sources_root() / sound_dir_name / stub_dir_name;
111 }
112
113 const path
114 SessionDirectory::midi_path () const
115 {
116         return sources_root() / midi_dir_name;
117 }
118
119 const path
120 SessionDirectory::midi_stub_path () const
121 {
122         return sources_root() / midi_dir_name / stub_dir_name;
123 }
124
125 const path
126 SessionDirectory::midi_patch_path () const
127 {
128         return sources_root() / midi_patch_dir_name;
129 }
130
131 const path
132 SessionDirectory::peak_path () const
133 {
134         return m_root_path / peak_dir_name;
135 }
136
137 const path
138 SessionDirectory::dead_sound_path () const
139 {
140         return m_root_path / dead_sound_dir_name;
141 }
142
143 const path
144 SessionDirectory::dead_midi_path () const
145 {
146         return m_root_path / dead_midi_dir_name;
147 }
148
149 const path
150 SessionDirectory::export_path () const
151 {
152         return m_root_path / export_dir_name;
153 }
154
155 const vector<path>
156 SessionDirectory::sub_directories () const
157 {
158         vector<path> tmp_paths;
159
160         tmp_paths.push_back ( sound_path () );
161         tmp_paths.push_back ( midi_path () );
162         tmp_paths.push_back ( peak_path () );
163         tmp_paths.push_back ( dead_sound_path () );
164         tmp_paths.push_back ( dead_midi_path () );
165         tmp_paths.push_back ( export_path () );
166
167         return tmp_paths;
168 }
169
170 } // namespace ARDOUR