* Improved export error handling, streamlined ExportFailed
[ardour.git] / libs / ardour / ardour / export_timespan.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
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.
9
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.
14
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.
18
19 */
20
21 #ifndef __ardour_export_timespan_h__
22 #define __ardour_export_timespan_h__
23
24 #include <map>
25 #include <list>
26
27 #include <glibmm/ustring.h>
28
29 #include <ardour/export_status.h>
30 #include <ardour/ardour.h>
31
32 using Glib::ustring;
33
34 namespace ARDOUR
35 {
36
37 class ExportChannel;
38 class ExportTempFile;
39
40 class ExportTimespan : public sigc::trackable
41 {
42   private:
43         typedef boost::shared_ptr<ExportTempFile> TempFilePtr;
44         typedef std::pair<ExportChannel const, TempFilePtr> ChannelFilePair;
45         typedef std::map<ExportChannel const, TempFilePtr> TempFileMap;
46         typedef boost::shared_ptr<ExportStatus> ExportStatusPtr;
47
48   private:
49         friend class ExportElementFactory;
50         ExportTimespan (ExportStatusPtr status, nframes_t frame_rate);
51         
52   public:
53         ~ExportTimespan ();
54         
55         ustring name () const { return _name; }
56         void set_name (ustring name) { _name = name; }
57         
58         ustring range_id () const { return _range_id; }
59         void set_range_id (ustring range_id) { _range_id = range_id; }
60         
61         /// Registers a channel to be read when export starts rolling
62         void register_channel (ExportChannel const & channel);
63         
64         /// "Rewinds" the tempfiles to start reading the beginnings again
65         void rewind ();
66         
67         /// Reads data from the tempfile belonging to channel into data
68         nframes_t get_data (float * data, nframes_t frames, ExportChannel const & channel);
69         
70         /// Reads data from each channel and writes to tempfile
71         int process (nframes_t frames);
72         
73         sigc::connection  process_connection;
74         
75         void set_range (nframes_t start, nframes_t end);
76         nframes_t get_length () const { return end_frame - start_frame; }
77         nframes_t get_start () const { return start_frame; }
78         nframes_t get_end () const { return end_frame; }
79
80   private:
81
82         ExportStatusPtr status;
83
84         nframes_t      start_frame;
85         nframes_t      end_frame;
86         nframes_t      position;
87         nframes_t      frame_rate;
88
89         TempFileMap    filemap;
90         
91         ustring       _name;
92         ustring       _range_id;
93
94 };
95
96 } // namespace ARDOUR
97
98 #endif /* __ardour_export_timespan_h__ */