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 "ardour_ui.h"
29 #include "export_range_markers_dialog.h"
34 using namespace ARDOUR;
37 ExportRangeMarkersDialog::ExportRangeMarkersDialog (PublicEditor& editor)
38 : ExportDialog(editor)
40 do_not_allow_export_cd_markers();
43 current_range_marker_index = 0;
48 ExportRangeMarkersDialog::export_audio_data ()
50 getSession().locations()->apply(*this, &ExportRangeMarkersDialog::process_range_markers_export);
54 ExportRangeMarkersDialog::process_range_markers_export(Locations::LocationList& locations)
56 Locations::LocationList::iterator locationIter;
57 current_range_marker_index = 0;
58 init_progress_computing(locations);
60 for (locationIter = locations.begin(); locationIter != locations.end(); ++locationIter) {
61 Location *currentLocation = (*locationIter);
63 if(currentLocation->is_range_marker()){
65 string filepath = get_target_filepath(
66 get_selected_file_name(),
67 currentLocation->name(),
68 sndfile_file_ending_from_string(get_selected_header_format()));
72 spec.start_frame = currentLocation->start();
73 spec.end_frame = currentLocation->end();
75 getSession().request_locate(spec.start_frame, false);
77 if (getSession().start_audio_export(spec)){
82 // wait until export of this range finished
85 if(gtk_events_pending()){
92 getSession().engine().freewheel (false);
93 current_range_marker_index++;
102 ExportRangeMarkersDialog::get_target_filepath(string path, string filename, string postfix)
104 string target_path = path;
105 if ((target_path.find_last_of ('/')) != string::npos) {
109 string target_filepath = target_path + filename + postfix;
112 for(int counter=1; (stat (target_filepath.c_str(), &statbuf) == 0); counter++){
114 ostringstream scounter;
119 target_path + filename + "_" + scounter.str() + postfix;
122 return target_filepath;
127 ExportRangeMarkersDialog::is_filepath_valid(string &filepath)
129 // sanity check file name first
132 if (filepath.empty()) {
134 string txt = _("Please enter a valid target directory.");
135 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
140 if ( (stat (filepath.c_str(), &statbuf) != 0) ||
141 (!S_ISDIR (statbuf.st_mode)) ) {
142 string txt = _("Please select an existing target directory. Files\n"
144 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
149 // directory needs to exist and be writable
150 string dirpath = Glib::path_get_dirname (filepath);
151 if (::access (dirpath.c_str(), W_OK) != 0) {
152 string txt = _("Cannot write file in: ") + dirpath;
153 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
163 ExportRangeMarkersDialog::init_progress_computing(Locations::LocationList& locations)
166 range_markers_durations_aggregated.resize(0);
168 jack_nframes_t duration_before_current_location = 0;
169 Locations::LocationList::iterator locationIter;
171 for (locationIter = locations.begin(); locationIter != locations.end(); ++locationIter) {
172 Location *currentLocation = (*locationIter);
174 if(currentLocation->is_range_marker()){
175 range_markers_durations_aggregated.push_back(
176 duration_before_current_location);
178 jack_nframes_t duration =
179 currentLocation->end() - currentLocation->start();
181 range_markers_durations.push_back(duration);
182 duration_before_current_location += duration;
186 total_duration = duration_before_current_location;
191 ExportRangeMarkersDialog::progress_timeout ()
193 double progress = 0.0;
195 if(current_range_marker_index >= range_markers_durations.size()){
200 ((double) range_markers_durations_aggregated[current_range_marker_index] +
201 (spec.progress * (double) range_markers_durations[current_range_marker_index])) /
202 (double) total_duration;
205 set_progress_fraction( progress );