2 Copyright (C) 2008 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.
21 #include "ardour/export_timespan.h"
23 #include "ardour/export_channel_configuration.h"
24 #include "ardour/export_filename.h"
25 #include "ardour/export_file_io.h"
26 #include "ardour/export_failed.h"
31 ExportTimespan::ExportTimespan (ExportStatusPtr status, nframes_t frame_rate) :
36 frame_rate (frame_rate)
40 ExportTimespan::~ExportTimespan ()
45 ExportTimespan::register_channel (ExportChannelPtr channel)
47 TempFilePtr ptr (new ExportTempFile (1, frame_rate));
48 ChannelFilePair pair (channel, ptr);
49 filemap.insert (pair);
53 ExportTimespan::rewind ()
55 for (TempFileMap::iterator it = filemap.begin(); it != filemap.end(); ++it) {
56 it->second->reset_read ();
61 ExportTimespan::get_data (float * data, nframes_t frames, ExportChannelPtr channel)
63 TempFileMap::iterator it = filemap.find (channel);
64 if (it == filemap.end()) {
65 throw ExportFailed (X_("Trying to get data from ExportTimespan for channel that was never registered!"));
68 return it->second->read (data, frames);
72 ExportTimespan::set_range (nframes_t start, nframes_t end)
75 position = start_frame;
80 ExportTimespan::process (nframes_t frames)
82 status->stage = export_ReadTimespan;
86 nframes_t frames_to_read;
88 if (position + frames <= end_frame) {
89 frames_to_read = frames;
91 frames_to_read = end_frame - position;
95 position += frames_to_read;
96 status->progress = (float) (position - start_frame) / (end_frame - start_frame);
98 /* Read channels from ports and save to tempfiles */
100 float * data = new float[frames_to_read];
102 for (TempFileMap::iterator it = filemap.begin(); it != filemap.end(); ++it) {
103 it->first->read (data, frames_to_read);
104 it->second->write (data, frames_to_read);
113 } // namespace ARDOUR