Fix angle bracket project-local include paths.
[ardour2.git] / libs / ardour / export_timespan.cc
blobd638c84b16b1bd096104bcbcd50c01d2354b874f
1 /*
2 Copyright (C) 2008 Paul Davis
3 Author: Sakari Bergen
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"
28 namespace ARDOUR
31 ExportTimespan::ExportTimespan (ExportStatusPtr status, nframes_t frame_rate) :
32 status (status),
33 start_frame (0),
34 end_frame (0),
35 position (0),
36 frame_rate (frame_rate)
40 ExportTimespan::~ExportTimespan ()
44 void
45 ExportTimespan::register_channel (ExportChannelPtr channel)
47 TempFilePtr ptr (new ExportTempFile (1, frame_rate));
48 ChannelFilePair pair (channel, ptr);
49 filemap.insert (pair);
52 void
53 ExportTimespan::rewind ()
55 for (TempFileMap::iterator it = filemap.begin(); it != filemap.end(); ++it) {
56 it->second->reset_read ();
60 nframes_t
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);
71 void
72 ExportTimespan::set_range (nframes_t start, nframes_t end)
74 start_frame = start;
75 position = start_frame;
76 end_frame = end;
79 int
80 ExportTimespan::process (nframes_t frames)
82 status->stage = export_ReadTimespan;
84 /* update position */
86 nframes_t frames_to_read;
88 if (position + frames <= end_frame) {
89 frames_to_read = frames;
90 } else {
91 frames_to_read = end_frame - position;
92 status->stop = true;
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);
107 delete [] data;
109 return 0;
113 } // namespace ARDOUR