2 Copyright (C) 2006 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <ardour/audioengine.h>
26 #include <ardour/sndfile_helpers.h>
28 #include <pbd/dirname.h>
30 #include "ardour_ui.h"
31 #include "export_range_markers_dialog.h"
36 using namespace ARDOUR;
39 ExportRangeMarkersDialog::ExportRangeMarkersDialog (PublicEditor& editor)
40 : ExportDialog(editor)
42 do_not_allow_export_cd_markers();
45 current_range_marker_index = 0;
50 ExportRangeMarkersDialog::export_audio_data ()
52 getSession().locations()->apply(*this, &ExportRangeMarkersDialog::process_range_markers_export);
56 ExportRangeMarkersDialog::process_range_markers_export(Locations::LocationList& locations)
58 Locations::LocationList::iterator locationIter;
59 current_range_marker_index = 0;
60 init_progress_computing(locations);
62 for (locationIter = locations.begin(); locationIter != locations.end(); ++locationIter) {
63 Location *currentLocation = (*locationIter);
65 if(currentLocation->is_range_marker()){
67 string filepath = get_target_filepath(
68 get_selected_file_name(),
69 currentLocation->name(),
70 sndfile_file_ending_from_string(get_selected_header_format()));
74 spec.start_frame = currentLocation->start();
75 spec.end_frame = currentLocation->end();
77 getSession().request_locate(spec.start_frame, false);
79 if (getSession().start_audio_export(spec)){
84 // wait until export of this range finished
87 if(gtk_events_pending()){
94 getSession().engine().freewheel (false);
95 current_range_marker_index++;
104 ExportRangeMarkersDialog::get_target_filepath(string path, string filename, string postfix)
106 string target_path = path;
107 if ((target_path.find_last_of ('/')) != string::npos) {
111 string target_filepath = target_path + filename + postfix;
114 for(int counter=1; (stat (target_filepath.c_str(), &statbuf) == 0); counter++){
116 ostringstream scounter;
121 target_path + filename + "_" + scounter.str() + postfix;
124 return target_filepath;
129 ExportRangeMarkersDialog::is_filepath_valid(string &filepath)
131 // sanity check file name first
134 if (filepath.empty()) {
136 string txt = _("Please enter a valid target directory.");
137 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
142 if ( (stat (filepath.c_str(), &statbuf) != 0) ||
143 (!S_ISDIR (statbuf.st_mode)) ) {
144 string txt = _("Please select an existing target directory. Files\n"
146 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
151 // directory needs to exist and be writable
152 string dirpath = PBD::dirname (filepath);
153 if (::access (dirpath.c_str(), W_OK) != 0) {
154 string txt = _("Cannot write file in: ") + dirpath;
155 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
165 ExportRangeMarkersDialog::init_progress_computing(Locations::LocationList& locations)
168 range_markers_durations_aggregated.resize(0);
170 jack_nframes_t duration_before_current_location = 0;
171 Locations::LocationList::iterator locationIter;
173 for (locationIter = locations.begin(); locationIter != locations.end(); ++locationIter) {
174 Location *currentLocation = (*locationIter);
176 if(currentLocation->is_range_marker()){
177 range_markers_durations_aggregated.push_back(
178 duration_before_current_location);
180 jack_nframes_t duration =
181 currentLocation->end() - currentLocation->start();
183 range_markers_durations.push_back(duration);
184 duration_before_current_location += duration;
188 total_duration = duration_before_current_location;
193 ExportRangeMarkersDialog::progress_timeout ()
195 double progress = 0.0;
197 if(current_range_marker_index >= range_markers_durations.size()){
202 ((double) range_markers_durations_aggregated[current_range_marker_index] +
203 (spec.progress * (double) range_markers_durations[current_range_marker_index])) /
204 (double) total_duration;
207 set_progress_fraction( progress );